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!
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!)
Want to quickly see what issues are open in your project?
- See all open issues:
autopr ls
- See absolutely all issues (open and closed):
If there's nothing matching your filters, AutoPR will let you know.
autopr ls -a # or autopr ls --all
Ready to tackle an issue? autopr workon gets you set up in a flash.
Command:
autopr workon <issue_number>
# Example: autopr workon 101Replace <issue_number> with the actual number of the GitHub issue.
What it does for you:
- Finds the Issue: Looks up the issue on GitHub to get its title.
- Creates a Smart Branch Name: Makes a new branch like
feature/101-fix-that-tricky-bugfrom the issue number and title. (It cleans up the title to make it a good branch name – all lowercase, hyphens for spaces, etc.) - Switches to Your New Branch: Runs
git checkout -b ...so you're ready to code. - 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 42AutoPR will create and switch to a branch like feature/42-fix-login-button-display-error and remember that you're working on issue 42.
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_KEYset in your environment.(Tip: Add this to yourexport OPENAI_API_KEY='your_api_key_here'
.zshrcor.bashrcso you don't have to set it every time.)
Command:
autopr commitWhat it does for you:
- Checks Your Staged Work: Looks at what you've staged with
git diff --staged. - Asks AI for a Commit Message: Sends this "diff" to an AI (currently GPT-3.5 Turbo) to suggest a commit message.
- Shows You the Suggestion: Prints the AI's idea to your console.
- You Decide: Asks if you want to use it (
y/n).y(yes): AutoPR runsgit commit -m "AI's clever message"for you.n(no): No problem! AutoPR will tell you to commit manually withgit commit.
Example:
After git add my_amazing_feature.py:
autopr commitAutoPR will show you a suggested message. If you like it, hit y, and you're committed!
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_KEYenvironment 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 tomain.
What it does for you:
- Gathers Your Commits: Looks at all the commits you've made on your current branch since you branched off from
main(or your specified--basebranch). - Remembers the Issue (if you used
workon): If you usedautopr workon, it will try to fetch the original issue's title and description from GitHub. - 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.
- Shows You the Draft: Prints the AI's suggested title and body.
- You Decide: Asks if you want to create the PR on GitHub with this draft (
y/n).y(yes): AutoPR usesgh 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!
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
ghCLI installed and logged in (gh auth login). - Yep, you need that
OPENAI_API_KEYagain.
Command:
autopr review <PR_NUMBER>
# Example: autopr review 7Replace <PR_NUMBER> with the number of the PR you want to review.
What it does for you:
- Fetches the PR's Changes: Uses
gh pr diff <PR_NUMBER>to get all the code changes. - AI Analyzes the Code: Sends the diff to a powerful AI (GPT-4 Turbo Preview) to look for potential improvements or issues.
- 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.
- 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 7AutoPR will fetch the PR, let the AI review it, and post comments on GitHub.
Ready to try AutoPR?
The easiest way is with pip:
pip install autopr_cliThen you can run commands like autopr ls.
- Get the Code:
git clone https://github.com/leaopedro/autopr.git cd autopr - Set up a Virtual Environment (Good Practice!):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install Everything Needed:
Now you can run commands like
pip install -r requirements.txt
python -m autopr.cli ls.
If you're working on AutoPR itself:
Make sure everything still works:
make testWe use Black to format our Python code:
make formatWe have a Makefile to help with releases. You'll need twine and your PyPI credentials.
- Update Version: Change
__version__inautopr/__init__.py. - Build:
make build(creates distributable files indist/) - Test on TestPyPI (Important!):
make publish-test - Publish for Real on PyPI:
make publish - Full Release (Publish & Tag):
make release(doespublishthen tags the version in Git).- Crucial: After
make release, push the tag:git push origin vX.Y.Z(orgit push --tags).
- Crucial: After
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".