Skip to main content

A CLI tool to automate PR creation and listing.

Project description

AutoPR: Your AI-Powered GitHub Assistant

AutoPR is a command-line tool that uses AI to help you with common GitHub tasks like managing issues, writing commit messages, creating pull requests, and even reviewing code. It's like having a smart assistant right in your terminal!

What Can AutoPR Do For You?

Here's a look at how AutoPR can make your GitHub workflow smoother and faster.

(Make sure you're in the main directory of your Git project when running these commands!)

1. See What Needs Doing: autopr ls

Want to quickly see what issues are open in your project?

  • See all open issues:
    autopr ls
    
  • See absolutely all issues (open and closed):
    autopr ls -a
    # or
    autopr ls --all
    
    If there's nothing matching your filters, AutoPR will let you know.

2. Grab an Issue and Get to Work: autopr workon <issue_number>

Ready to tackle an issue? autopr workon gets you set up in a flash.

Command:

autopr workon <issue_number> 
# Example: autopr workon 101

Replace <issue_number> with the actual number of the GitHub issue.

What it does for you:

  1. Finds the Issue: Looks up the issue on GitHub to get its title.
  2. Creates a Smart Branch Name: Makes a new branch like feature/101-fix-that-tricky-bug from the issue number and title. (It cleans up the title to make it a good branch name – all lowercase, hyphens for spaces, etc.)
  3. Switches to Your New Branch: Runs git checkout -b ... so you're ready to code.
  4. Remembers What You're Working On: Saves the issue number in .git/.autopr_current_issue. This helps other AutoPR commands know the context of your work.

Example: If issue #42 is "Fix login button display error":

autopr workon 42

AutoPR will create and switch to a branch like feature/42-fix-login-button-display-error and remember that you're working on issue 42.

3. Commit Your Awesome Changes (with AI Help!): autopr commit

You've staged your changes (git add .), and now it's time to commit. Let AutoPR help you write a great commit message!

Prerequisites:

  • You have changes staged for commit.
  • You need an OPENAI_API_KEY set in your environment.
    export OPENAI_API_KEY='your_api_key_here' 
    
    (Tip: Add this to your .zshrc or .bashrc so you don't have to set it every time.)

Command:

autopr commit

What it does for you:

  1. Checks Your Staged Work: Looks at what you've staged with git diff --staged.
  2. Asks AI for a Commit Message: Sends this "diff" to an AI (currently GPT-3.5 Turbo) to suggest a commit message.
  3. Shows You the Suggestion: Prints the AI's idea to your console.
  4. You Decide: Asks if you want to use it (y/n).
    • y (yes): AutoPR runs git commit -m "AI's clever message" for you.
    • n (no): No problem! AutoPR will tell you to commit manually with git commit.

Example: After git add my_amazing_feature.py:

autopr commit

AutoPR will show you a suggested message. If you like it, hit y, and you're committed!

4. Create a Pull Request (AI-Assisted Title & Body): autopr pr

Ready to share your work? autopr pr helps you draft a Pull Request with an AI-generated title and description based on your commits and the original issue.

Prerequisites:

  • You've committed your changes to your local branch.
  • You have that OPENAI_API_KEY environment variable set.
  • It helps if you started with autopr workon <issue_number> so AutoPR can link the PR back to the issue.

Command:

autopr pr [--base <target_branch>]
# Example: autopr pr
# Example: autopr pr --base develop
  • --base <target_branch>: Tell AutoPR where your PR should merge into. If you don't say, it defaults to main.

What it does for you:

  1. Gathers Your Commits: Looks at all the commits you've made on your current branch since you branched off from main (or your specified --base branch).
  2. Remembers the Issue (if you used workon): If you used autopr workon, it will try to fetch the original issue's title and description from GitHub.
  3. Asks AI for a PR Title & Body: Sends your commit messages (and issue details, if found) to an AI (GPT-3.5 Turbo) to draft a title and body for your PR.
  4. Shows You the Draft: Prints the AI's suggested title and body.
  5. You Decide: Asks if you want to create the PR on GitHub with this draft (y/n).
    • y (yes): AutoPR uses gh pr create ... to open the PR on GitHub, linking it to the issue if possible.
    • n (no): No worries! AutoPR will suggest you create the PR manually.

Example: You've made some commits on your feature/42-new-login-flow branch.

autopr pr 

AutoPR will gather your work, ask the AI for a good PR title and body, show them to you, and then create the PR if you say yes!

5. Get an AI Code Review: autopr review <PR_NUMBER>

Want a second pair of (AI) eyes on a Pull Request? autopr review uses AI to analyze the changes and post suggestions directly as comments on GitHub.

Prerequisites:

  • You have the gh CLI installed and logged in (gh auth login).
  • Yep, you need that OPENAI_API_KEY again.

Command:

autopr review <PR_NUMBER>
# Example: autopr review 7

Replace <PR_NUMBER> with the number of the PR you want to review.

What it does for you:

  1. Fetches the PR's Changes: Uses gh pr diff <PR_NUMBER> to get all the code changes.
  2. AI Analyzes the Code: Sends the diff to a powerful AI (GPT-4 Turbo Preview) to look for potential improvements or issues.
  3. Posts Suggestions on GitHub: If the AI has suggestions, AutoPR posts them as comments directly on the relevant lines of code in the PR on GitHub.
  4. Tells You What Happened: Gives you a summary of how many comments it posted.

Example: To get AI feedback on Pull Request #7:

autopr review 7

AutoPR will fetch the PR, let the AI review it, and post comments on GitHub.

Getting Started: Installation

Ready to try AutoPR?

For Most Users (Install from PyPI)

The easiest way is with pip:

pip install autopr_cli

Then you can run commands like autopr ls.

For Developers (If you want to contribute or tinker)

  1. Get the Code:
    git clone https://github.com/leaopedro/autopr.git
    cd autopr
    
  2. Set up a Virtual Environment (Good Practice!):
    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install Everything Needed:
    pip install -r requirements.txt 
    
    Now you can run commands like python -m autopr.cli ls.

For Developers: Contributing to AutoPR

If you're working on AutoPR itself:

Running Tests

Make sure everything still works:

make test

Keeping Code Tidy (Formatting)

We use Black to format our Python code:

make format

Publishing a New Version (For Maintainers)

We have a Makefile to help with releases. You'll need twine and your PyPI credentials.

  1. Update Version: Change __version__ in autopr/__init__.py.
  2. Build: make build (creates distributable files in dist/)
  3. Test on TestPyPI (Important!): make publish-test
  4. Publish for Real on PyPI: make publish
  5. Full Release (Publish & Tag): make release (does publish then tags the version in Git).
    • Crucial: After make release, push the tag: git push origin vX.Y.Z (or git push --tags).

Note: For developer commands like python -m autopr.cli ..., you can create an alias in your shell (e.g., in .zshrc or .bashrc) to make them shorter, like alias dev-autopr="python -m autopr.cli".

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autopr_cli-0.2.28.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autopr_cli-0.2.28-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file autopr_cli-0.2.28.tar.gz.

File metadata

  • Download URL: autopr_cli-0.2.28.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for autopr_cli-0.2.28.tar.gz
Algorithm Hash digest
SHA256 24098046a370b787d874dca7961e236d3679d8591d75784849f69f7925d51879
MD5 485713d5d8d1d7372342aa063f46b2e4
BLAKE2b-256 1ed6ffd0928f170eb1ba48a4b97c66fb566ff841ee761da7150cae2c43c7e2c6

See more details on using hashes here.

File details

Details for the file autopr_cli-0.2.28-py3-none-any.whl.

File metadata

  • Download URL: autopr_cli-0.2.28-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for autopr_cli-0.2.28-py3-none-any.whl
Algorithm Hash digest
SHA256 e377657d78af3324ee4feb5ab1530d2f568c6a8add8204036f738676a7939ba5
MD5 ed5d1672817874f8a23850db916a48bf
BLAKE2b-256 52ba117e7ee277817be1e4f06b1d9bfa12bf3b5ff54b89087be63f38d294786a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page