Skip to main content

A CLI tool to automate PR creation and listing.

Project description

AutoPR

A CLI tool designed to streamline your GitHub workflow by automating Pull Request (PR) creation and issue management. Future versions will incorporate AI to assist in generating PR descriptions.

Features (Current)

  • List open GitHub issues for the current repository.
  • List all (open and closed) GitHub issues using the -a flag.
  • Create a new PR with a specified title.
  • Automatically detects the GitHub repository from your local .git configuration.

Installation & Setup

For Users (when published on PyPI):

You can install AutoPR using pip:

pip install autopr_cli

For Developers (Local Setup):

  1. Clone the repository:
    git clone https://github.com/leaopedro/autopr.git
    cd autopr
    
  2. Create and activate a virtual environment (recommended):
    python3 -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
    
  3. Install dependencies (including development tools):
    pip install -r requirements.txt
    

Usage

Make sure you are in the root directory of your Git repository.

  • List open issues:
    autopr ls
    # For developers: python -m autopr.cli ls
    
  • List all issues (open and closed):
    autopr ls -a
    # For developers: python -m autopr.cli ls -a
    
  • Start working on an issue:
    autopr workon <issue_number>
    # For developers: python -m autopr.cli workon <issue_number>
    
    (See full guide below)
  • Generate AI-assisted commit message and commit:
    autopr commit
    # For developers: python -m autopr.cli commit
    
    Requires OPENAI_API_KEY environment variable. (See full guide below)
  • Create a new PR:
    autopr create --title "Your Amazing PR Title"
    # For developers: python -m autopr.cli create --title "Your Amazing PR Title"
    

Starting Work on an Issue (autopr workon)

The workon command helps you kickstart development on a specific GitHub issue.

Command:

autopr workon <issue_number>
# For developers: python -m autopr.cli workon <issue_number>

Replace <issue_number> with the actual number of the GitHub issue you want to work on.

What it does:

  1. Fetches Issue Details: It uses the gh CLI to retrieve the title of the specified issue.
  2. Generates a Branch Name: Based on the issue number and its title, it creates a sanitized, descriptive branch name in the format feature/<issue_number>-<sanitized-title>.
    • Sanitization includes: lowercasing, replacing spaces and special characters with hyphens, and limiting length.
  3. Creates and Switches Branch: It executes git checkout -b <generated_branch_name> to create the new local branch and immediately switch to it.
  4. Stores Context: The issue number is saved to a file named .autopr_current_issue inside your local .git directory. This allows future autopr commands (like autopr commit and autopr pr create in upcoming features) to know which issue you're currently working on.

Example:

If you want to start working on issue #42 which has the title "Fix login button display error":

autopr workon 42
# For developers: python -m autopr.cli workon 42

This might:

  • Fetch details for issue #42.
  • Generate a branch name like feature/42-fix-login-button-display-error.
  • Create and switch to this new branch.
  • Save 42 into .git/.autopr_current_issue.

You are then ready to start coding on the new branch with the issue context set up for future autopr commands.

Generating an AI-assisted Commit Message (autopr commit)

The commit command helps you generate a commit message using AI based on your staged changes, and then optionally commit those changes.

Prerequisites:

  • You must have changes staged for commit (git add ...).
  • You need to set the OPENAI_API_KEY environment variable with your valid OpenAI API key.
    export OPENAI_API_KEY='your_api_key_here' 
    
    (Add this to your shell configuration file like .zshrc or .bashrc for persistence).

Command:

autopr commit
# For developers: python -m autopr.cli commit

What it does:

  1. Checks for Staged Changes: It first runs git diff --staged to get your staged modifications. If there are no staged changes, it will inform you.
  2. Sends Diff to AI: The staged diff is sent to the OpenAI API (currently using gpt-3.5-turbo).
  3. Displays AI Suggestion: The AI-generated commit message suggestion is printed to your console.
  4. User Confirmation: You will be asked if you want to commit with the suggested message (y/n).
  5. Commits Changes (if confirmed):
    • If you enter y (yes), autopr will execute git commit -m "suggested_message" to commit your staged changes with the AI's suggestion.
    • If you enter n (no) or any other input, the commit will be aborted, and you will be advised to commit manually using git.
  6. Handles Errors: If there's an issue getting the AI suggestion (e.g., API key problem, network error) or if the git commit command fails, appropriate error messages will be displayed.

Example:

After staging some changes to my_feature.py:

git add my_feature.py
autopr commit
# For developers: python -m autopr.cli commit

If the AI service returns an error, or if you choose not to use the suggestion, you will be prompted to commit manually.

Development

Running Tests

To run the automated tests, use Make:

make test

Formatting Code

To format the code using Black:

make format

Publishing a New Version (for Maintainers)

This project uses Makefile targets to streamline the release process. Ensure you have twine configured with your PyPI credentials (API tokens are recommended) and have installed development dependencies via pip install -r requirements.txt.

  1. Update Version: Increment the __version__ string in autopr/__init__.py.

  2. Build the Package:

    make build
    

    This cleans old builds and creates new source distribution and wheel files in the dist/ directory.

  3. Test Publishing (Highly Recommended): Publish to TestPyPI to ensure everything works correctly before a real release.

    make publish-test
    

    You will be prompted for confirmation. Check the package on test.pypi.org.

  4. Publish to PyPI (Real):

    make publish
    

    This will upload the package to the official PyPI. You will be prompted for confirmation.

  5. Full Release (Publish to PyPI & Tag): For a complete release including Git tagging:

    make release
    

    This performs make publish and then creates a Git tag for the new version (e.g., v0.2.5). After running this, you must push the tag to the remote repository:

    git push origin vX.Y.Z  # Replace X.Y.Z with the version number
    # OR push all tags if you have multiple new tags
    git push --tags
    

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.21.tar.gz (24.7 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.21-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autopr_cli-0.2.21.tar.gz
  • Upload date:
  • Size: 24.7 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.21.tar.gz
Algorithm Hash digest
SHA256 de4994984d8bb5ddbf9d2b0ca09771b2aec85ee060fa3102f3da37ab4e507920
MD5 e358c8b2da6d41042681cf56fba8f1b0
BLAKE2b-256 b055abb35b7b3fb90728b29c020cf74511e726e7eba4bf9bc50cc2186ff7b013

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autopr_cli-0.2.21-py3-none-any.whl
  • Upload date:
  • Size: 25.3 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.21-py3-none-any.whl
Algorithm Hash digest
SHA256 5b1275c0cf3cb040ccef5cc63ce566429b59622c2dc66aa4b6025657967c8a62
MD5 6368b98023dc6f2014a032f9659e6287
BLAKE2b-256 55eed8ffa6e2dc34576192bae310dbe2e187a888b9ae6b059fc1604e227ac65a

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