Ai Coding Tools

How to Build a Simple GitHub Bot with Cursor in 1 Hour

By BTW Team3 min read

How to Build a Simple GitHub Bot with Cursor in 1 Hour

If you’re like me, you’ve probably found yourself wishing for a way to automate those repetitive tasks on GitHub. Maybe you want to label issues automatically, respond to pull requests, or even send reminders for code reviews. Building a GitHub bot can sound daunting, but with the right tools, it can be done in just one hour. In this guide, I’ll walk you through how to create a simple GitHub bot using Cursor—an AI coding tool that has been making waves for its ease of use and efficiency.

Why Use Cursor for Your GitHub Bot?

Cursor is an AI coding assistant that helps you write and debug code faster. It’s particularly good for automating tasks and can integrate directly with your development environment. Here’s why I recommend it:

  • Time Efficiency: Cursor can generate code snippets, which saves you time writing boilerplate code.
  • Error Reduction: It helps catch bugs early, especially useful when working with GitHub APIs.
  • User-Friendly: Even if you’re not a coding expert, Cursor makes it easier to implement complex logic.

Prerequisites

Before diving in, make sure you have the following:

  1. GitHub Account: You’ll need access to create a repository.
  2. Node.js Installed: Download from nodejs.org if you don’t have it.
  3. Cursor Account: Sign up at cursor.so.
  4. Basic JavaScript Knowledge: Familiarity with JavaScript will help, but I’ll guide you through the tricky parts.

Step-by-Step Guide to Building Your GitHub Bot

Step 1: Set Up Your GitHub Repository

  1. Go to GitHub and create a new repository.
  2. Name it something like github-bot-example.
  3. Initialize it with a README file.

Step 2: Create Your Bot Script

  1. Open your terminal and navigate to your repository folder.
  2. Run npm init -y to create a package.json file.
  3. Install the required packages:
    npm install axios dotenv
    
  4. Create a new file named bot.js.

Step 3: Write Your Bot Logic

Here’s a simple bot that labels issues based on keywords in the title:

require('dotenv').config();
const axios = require('axios');

const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
const REPO_OWNER = 'your-github-username';
const REPO_NAME = 'github-bot-example';

async function labelIssues() {
    const response = await axios.get(`https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/issues`, {
        headers: {
            Authorization: `token ${GITHUB_TOKEN}`
        }
    });

    const issues = response.data;

    for (let issue of issues) {
        if (issue.title.includes('bug')) {
            await axios.post(`https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/issues/${issue.number}/labels`, {
                labels: ['bug']
            }, {
                headers: {
                    Authorization: `token ${GITHUB_TOKEN}`
                }
            });
        }
    }
}

labelIssues();

Step 4: Configure Your Environment Variables

  1. Create a .env file in your project directory.
  2. Add your GitHub token:
    GITHUB_TOKEN=your_github_token
    

Step 5: Run Your Bot

  1. In your terminal, run:
    node bot.js
    
  2. Check your GitHub issues to see if the labels were applied correctly.

Troubleshooting Common Issues

  • Invalid Token Error: Make sure your GitHub token has the correct permissions (repo access).
  • Network Issues: Ensure that your internet connection is stable.
  • API Rate Limiting: GitHub APIs have rate limits. If you hit a limit, you’ll need to wait before making more requests.

What's Next?

Now that you have a basic GitHub bot, consider expanding its functionality. You could add features like:

  • Responding to pull requests with comments.
  • Automatically closing issues after a certain period.
  • Integrating with Slack for notifications.

Conclusion: Start Here

Building a GitHub bot using Cursor is a practical way to automate your workflows. This guide should take you about an hour to complete. Remember, while this bot is simple, the potential for automation is vast.

If you’re looking to dive deeper into AI coding tools, check out our podcast, Built This Week, where we discuss more tools and techniques for builders like you!

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

5 Common Misconceptions About AI Coding Tools That Beginners Believe

5 Common Misconceptions About AI Coding Tools That Beginners Believe As a solo founder or indie hacker, diving into the world of AI coding tools can feel overwhelming, especially i

Oct 5, 20263 min read
Ai Coding Tools

5 Mistakes Every Beginner Makes When Using AI Coding Tools

5 Mistakes Every Beginner Makes When Using AI Coding Tools As a solo founder or indie hacker diving into the world of AI coding tools, it’s easy to get swept up in the excitement o

Oct 4, 20264 min read
Ai Coding Tools

10 Common Misconceptions About AI Coding Tools in 2026

10 Common Misconceptions About AI Coding Tools in 2026 As we dive into 2026, AI coding tools have become a staple in the developer toolkit. However, misconceptions still run rampan

Oct 4, 20264 min read
Ai Coding Tools

5 Mistakes to Avoid When Using AI Coding Tools for Real Projects

5 Mistakes to Avoid When Using AI Coding Tools for Real Projects As we dive deeper into 2026, AI coding tools have become an essential part of the developer's toolkit. However, usi

Oct 4, 20264 min read
Ai Coding Tools

5 Common Misconceptions About AI Coding Tools and Why They Matter

5 Common Misconceptions About AI Coding Tools and Why They Matter As a solo founder or indie hacker, you’re likely eyeing AI coding tools to boost your productivity and streamline

Oct 4, 20264 min read
Ai Coding Tools

5 Common Mistakes Developers Make with AI Coding Tools in 2026

5 Common Mistakes Developers Make with AI Coding Tools in 2026 As we dive deeper into 2026, AI coding tools have become essential for developers looking to enhance productivity and

Oct 4, 20263 min read