Skip to content

Pratham-Prog861/github-pr-automation

Repository files navigation

πŸ€– GitHub PR Automation Suite

GitHub Automation Motia TypeScript AI Powered

A powerful, AI-enhanced GitHub automation suite built with Motia framework

Features β€’ Quick Start β€’ API Endpoints β€’ Examples β€’ Contributing


✨ Features

πŸ” Analytics & Insights (GET Endpoints)

  • πŸ“Š Repository Stats Dashboard - Comprehensive repo analytics with stars, forks, languages, and top contributors
  • πŸ“¦ Release Notes Viewer - Fetch latest or all releases with download stats
  • πŸ“ˆ Code Activity Tracker - Analyze commit patterns, active hours, and contributor stats
  • πŸ’» Personal Commits Viewer - List all your commits in any repository

πŸš€ Automation Actions (POST Endpoints)

  • πŸ€– AI-Powered PR Review - Automated code review using Google Gemini AI
  • 🏷️ Smart Auto-Labeler - Automatically label PRs based on file changes

🎯 Quick Start

Prerequisites

Installation

# Clone the repository
git clone https://github.com/Pratham-Prog861/github-pr-automation.git
cd github-pr-automation

# Install dependencies
npm install

# Create .env file
cat > .env << EOF
GITHUB_TOKEN=your_github_token_here
GEMINI_API_KEY=your_gemini_api_key_here
EOF

# Generate TypeScript types
npm run generate-types

# Start the development server
npm run dev

πŸŽ‰ Server is now running at http://localhost:3000


πŸ“‘ API Endpoints

πŸ“Š Analytics Endpoints

1. Repository Stats Dashboard

GET /repo-stats?repo=owner/repo

Example Response:

{
  "ok": true,
  "stats": {
    "name": "mini-postman",
    "stars": 42,
    "forks": 15,
    "languages": [
      { "language": "TypeScript", "percentage": "85.50" }
    ],
    "topContributors": [...]
  }
}

2. Release Notes Viewer

GET /releases?repo=owner/repo&latest=true

Query Parameters:

  • repo (required) - Repository in format owner/repo
  • latest (optional) - true for latest release, false for all releases (default: true)

3. Code Activity Tracker

GET /repo-activity?repo=owner/repo&days=30

Query Parameters:

  • repo (required) - Repository in format owner/repo
  • days (optional) - Number of days to analyze (default: 30)

4. Personal Commits Viewer

GET /repo-commits?repo=owner/repo

Returns the last 10 commits authored by you in the specified repository.


πŸ€– Automation Endpoints

5. AI-Powered PR Review

POST /review-pr
Content-Type: application/json

{
  "repo": "owner/repo",
  "prNumber": 123
}

What it does:

  • βœ… Fetches PR files and diff
  • πŸ” Runs AI-powered code review using Gemini
  • πŸ“ Posts detailed review comment on GitHub
  • ✨ Auto-approves if lint passes and AI approves

6. Smart Auto-Labeler

POST /auto-label
Content-Type: application/json

{
  "repo": "owner/repo",
  "prNumber": 123
}

Labeling Rules:

File Pattern Label
.ts, .tsx typescript
.js, .jsx javascript
.css, .scss styling
.md documentation
test, spec tests
package.json dependencies

πŸ’‘ Usage Examples

Using cURL

# Get repository statistics
curl "http://localhost:3000/repo-stats?repo=facebook/react"

# Get latest release
curl "http://localhost:3000/releases?repo=vercel/next.js&latest=true"

# Analyze last 7 days of activity
curl "http://localhost:3000/repo-activity?repo=microsoft/vscode&days=7"

# Review a pull request
curl -X POST http://localhost:3000/review-pr \
  -H "Content-Type: application/json" \
  -d '{"repo":"owner/repo","prNumber":42}'

# Auto-label a PR
curl -X POST http://localhost:3000/auto-label \
  -H "Content-Type: application/json" \
  -d '{"repo":"owner/repo","prNumber":42}'

Using JavaScript/TypeScript

// Fetch repository stats
const stats = await fetch(
  "http://localhost:3000/repo-stats?repo=facebook/react"
).then((res) => res.json());

console.log(`⭐ Stars: ${stats.stats.stars}`);
console.log(`🍴 Forks: ${stats.stats.forks}`);

// Auto-label a PR
const result = await fetch("http://localhost:3000/auto-label", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    repo: "owner/repo",
    prNumber: 42,
  }),
}).then((res) => res.json());

console.log(`🏷️ Labels added: ${result.labelsAdded.join(", ")}`);

πŸ—οΈ Project Structure

github-pr-automation/
β”œβ”€β”€ steps/                          # API endpoint definitions
β”‚   β”œβ”€β”€ github-pr-review.step.ts   # AI-powered PR review
β”‚   β”œβ”€β”€ github-auto-labeler.step.ts # Smart PR labeler
β”‚   β”œβ”€β”€ github-commits.step.ts     # Personal commits viewer
β”‚   β”œβ”€β”€ github-repo-stats.step.ts  # Repository statistics
β”‚   β”œβ”€β”€ github-releases.step.ts    # Release notes viewer
β”‚   └── github-activity.step.ts    # Code activity tracker
β”œβ”€β”€ motia.config.ts                # Motia configuration
β”œβ”€β”€ types.d.ts                     # Auto-generated TypeScript types
β”œβ”€β”€ .env                           # Environment variables (create this)
└── package.json                   # Dependencies

πŸ› οΈ Development

Available Commands

# Start development server with hot reload
npm run dev

# Generate TypeScript types from Step configs
npm run generate-types

# Build for production
npm run build

# Clean build artifacts
npm run clean

Adding a New Endpoint

  1. Create a new file in steps/ directory (e.g., my-feature.step.ts)
  2. Define your step configuration and handler
  3. Run npm run generate-types to register it
  4. Test your endpoint at http://localhost:3000/your-path

Example:

import { ApiRouteConfig, Handlers } from "motia";

export const config: ApiRouteConfig = {
  name: "my-feature",
  type: "api",
  path: "/my-endpoint",
  method: "GET",
  emits: [],
};

export const handler: Handlers["my-feature"] = async (req, ctx) => {
  return {
    status: 200,
    body: { message: "Hello from my feature!" },
  };
};

πŸ” Environment Variables

Create a .env file in the root directory:

# GitHub Personal Access Token (required)
# Scopes needed: repo, read:user
GITHUB_TOKEN=ghp_your_token_here

# Google Gemini API Key (required for PR review)
GEMINI_API_KEY=AIzaSy_your_key_here

Getting Your Tokens

GitHub Token:

  1. Go to GitHub Settings β†’ Developer settings β†’ Personal access tokens
  2. Click "Generate new token (classic)"
  3. Select repo scope
  4. Copy the generated token

Gemini API Key:

  1. Visit Google AI Studio
  2. Click "Get API key"
  3. Create a new API key
  4. Copy the key

πŸ“š What is Motia?

Motia is an open-source, unified backend framework that eliminates runtime fragmentation by bringing APIs, background jobs, queueing, streaming, state, workflows, AI agents, observability, scaling, and deployment into one unified system using a single core primitive, the Step.

Step Types

Type When it runs Use case
api HTTP request REST APIs, webhooks
event Event emitted Background jobs, workflows
cron Schedule Cleanup, reports, reminders

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’» Make your changes
  4. βœ… Test your changes
  5. πŸ“ Commit your changes (git commit -m 'Add amazing feature')
  6. πŸš€ Push to the branch (git push origin feature/amazing-feature)
  7. πŸŽ‰ Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ”— Links


Made with ❀️ using Motia

If you found this helpful, please ⭐ star the repository!

About

A powerful, AI-enhanced GitHub automation suite built with Motia framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors