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

Bolt.new vs Codeium: Which AI Tool Delivers Better Code Quality?

Bolt.new vs Codeium: Which AI Tool Delivers Better Code Quality? As indie hackers and solo founders, we often find ourselves juggling multiple roles, and writing quality code can b

Jul 22, 20264 min read
Ai Coding Tools

Cursor vs. Codeium: Which AI Coding Tool is Best for Intermediate Developers?

Cursor vs. Codeium: Which AI Coding Tool is Best for Intermediate Developers? As an intermediate developer, you're likely looking for tools that can help you code faster and more e

Jul 22, 20264 min read
Ai Coding Tools

How to Learn GitHub Copilot in 30 Minutes: A Beginner's Guide

How to Learn GitHub Copilot in 30 Minutes: A Beginner's Guide If you're a beginner looking to enhance your coding productivity, you've probably heard of GitHub Copilot. But let's b

Jul 22, 20264 min read
Ai Coding Tools

Bolt.new vs GitHub Copilot: A Side-by-Side Comparison of Features and Usability

Bolt.new vs GitHub Copilot: A SidebySide Comparison of Features and Usability As solo founders and indie hackers, we often find ourselves kneedeep in code, looking for tools that c

Jul 22, 20263 min read
Ai Coding Tools

How to Build a Complete SaaS Application Using AI Tools in 60 Minutes

How to Build a Complete SaaS Application Using AI Tools in 60 Minutes Building a SaaS application can feel daunting, especially if you’re a solo founder or indie hacker strapped fo

Jul 22, 20265 min read
Ai Coding Tools

Cursor vs GitHub Copilot: Which AI Tool Boosts Your Development Speed?

Cursor vs GitHub Copilot: Which AI Tool Boosts Your Development Speed? (2026) As a solo founder or indie hacker, maximizing your development speed is crucial. With so many AI codin

Jul 22, 20263 min read