Skip to content

About

Autonomous GitHub pull-requests manager 🌟 Star if you like it! 🌟

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

39 Commits

Folders and files

Repository files navigation

πŸš€ GitHub Pull Request Fetcher & Cleanup Tool

Manage GitHub Pull Requests Banner

AwesomeDiscord Python Version License: MIT GitHub API Maintenance GitHub followers

An advanced, performance-optimized CLI utility designed for GitHub maintainers. It fetches, analyzes, and manages pull requests across hundreds of repositories with ease.


✨ Key Features

  • πŸ” Deep PR Analysis: Automatically detects merge conflicts in open pull requests by inspecting repository internals.
  • πŸ› οΈ Interactive Cleanup & Management: Close conflicted PRs or approve and merge target PRs directly from the terminal. Supports individual confirmation or "Yes to All" ([y/N/a]).
  • πŸ”€ Automated Approval & Conflict-Safe Merge: Automatically review, approve, and merge pull requests matching a submitting user and title phraseβ€”strictly ensuring merge conflicts are detected and skipped.
  • ⚑ Intelligent Caching:
    • 24-hour TTL: Local JSON caching of repos, PR lists, and deep details.
    • Auto-Sync: Automatically invalidates local cache when you close or merge a PR through the tool.
    • Zero-PR Optimization: Correctly caches repositories with no PRs to maximize speed.
  • ⏱️ Progress & ETA Monitoring: Real-time tracking of processing progress, elapsed time, and dynamic ETA calculation.
  • πŸ“„ Full Pagination: Seamlessly handles accounts with massive repository counts and deep PR histories.
  • πŸ“‚ Fork Filtering: Automatically ignores forked repositories by default to focus on original content.

πŸ› οΈ Installation

1. Clone & Setup

git clone https://github.com/ishandutta2007/manage-github-pull-requests.git
cd manage-github-pull-requests
pip install -r requirements.txt

2. Configure Environment

Create a .env file in the root directory:

ADMIN_TOKEN=your_github_fine_grained_pat

πŸ”‘ Required Token Permissions

To enable the Interactive Cleanup & Management features, your PAT needs Read and Write access for:

  1. Go to Settings: GitHub Fine-grained Tokens
  2. Pull requests: Read and Write (Required for reviews, merges, and closures)
  3. Issues: Read and Write (Required for posting closure comments)
  4. Contents: Read and Write (Required for merging pull requests into repositories)

πŸš€ Usage

The tool suite includes four specialized scripts for repository maintenance.

1. Merge Conflict Cleanup (fetch_prs_and_close_conflicting.py)

Scans all repositories and identifies open PRs that cannot be merged due to conflicts.

Goal Command
Default Run python fetch_prs_and_close_conflicting.py
Target Owner python fetch_prs_and_close_conflicting.py <username>
Include Forks python fetch_prs_and_close_conflicting.py --include-forks

2. User-Specific Cleanup (fetch_prs_and_close_from_user.py)

Scans repositories and identifies open PRs submitted by a specific user (e.g., to clean up bot spam or specific contributors).

Goal Command
Standard Run python fetch_prs_and_close_from_user.py --target-user <username>
Custom Owner python fetch_prs_and_close_from_user.py --owner <org> --target-user <bot>

3. Title Prefix Cleanup (fetch_prs_and_close_by_title_prefix.py)

Scans repositories and identifies open PRs whose title starts with a specific string prefix.

Goal Command
Standard Run python fetch_prs_and_close_by_title_prefix.py --title-prefix "<prefix>"
Custom Owner python fetch_prs_and_close_by_title_prefix.py --owner <org> --title-prefix "[WIP]"

4. User & Title Phrase Approve and Merge (fetch_prs_and_approve_and_merge_from_user_with_a_certain_title.py)

Scans repositories and filters PRs matching both the submitting user ID and a title phrase/subtext. It submits an approving review and safely merges the PR provided there is no merge conflict.

Goal Command
Standard Run python fetch_prs_and_approve_and_merge_from_user_with_a_certain_title.py --target-user <username> --title-phrase "<phrase>"
Using Aliases python fetch_prs_and_approve_and_merge_from_user_with_a_certain_title.py --user-id <username> --phrase "<phrase>"
Custom Owner & Squash Merge python fetch_prs_and_approve_and_merge_from_user_with_a_certain_title.py --owner <org> --target-user <bot> --title-phrase "version bump" --merge-method squash
Include Forks & Auto-Confirm python fetch_prs_and_approve_and_merge_from_user_with_a_certain_title.py --target-user <username> --title-phrase "<phrase>" --include-forks -y

Interactive Actions

All scripts support an interactive confirmation loop when candidate PRs are identified:

  • y: Execute the action (close, or approve & merge if no conflict).
  • N: Skip this PR (Default).
  • a: Yes to All. Automatically process all remaining identified PRs in the session.

πŸ’Ύ Cache Management

The tool maintains a structured cache in the .cache/ directory:

  • repos/: List of user repositories.
  • prs/: List of PRs per repository.
  • pr_details/: Deep metadata for specific PRs (used for conflict detection).

Note: Closing or merging a PR via the tool triggers an immediate clear_cache() for that repository and PR, ensuring your next run reflects the updated state.


πŸ“‚ Project Structure

.
β”œβ”€β”€ .cache/                                                                # Multi-layer JSON cache
β”œβ”€β”€ .env                                                                   # Private GitHub token
β”œβ”€β”€ github_tool/                                                           # Core library modules
β”‚   β”œβ”€β”€ api.py                                                             # REST API calls (reviews, merges, PRs)
β”‚   β”œβ”€β”€ cache.py                                                           # Cache storage and expiration
β”‚   β”œβ”€β”€ config.py                                                          # Environment and configuration
β”‚   └── core.py                                                            # Repository retrieval logic
β”œβ”€β”€ fetch_prs_and_approve_and_merge_from_user_with_a_certain_title.py      # Filter, approve & merge clean PRs by author and title phrase
β”œβ”€β”€ fetch_prs_and_close_by_title_prefix.py                                 # Filter & close PRs by title prefix
β”œβ”€β”€ fetch_prs_and_close_conflicting.py                                     # Detect & close conflicting PRs
β”œβ”€β”€ fetch_prs_and_close_from_user.py                                       # Filter & close PRs by author
β”œβ”€β”€ tests/                                                                 # Test suite
β”œβ”€β”€ requirements.txt                                                       # Dependencies
└── README.md                                                              # Documentation

βš–οΈ License

Distributed under the MIT License. See LICENSE for more information.

GitHub followers


πŸ“ˆ Star History


Made with ❀️ for efficient GitHub maintenance.GitHub followers

About

Autonomous GitHub pull-requests manager 🌟 Star if you like it! 🌟

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages