Skip to main content
auto-pr logo

CI Publish PyPI version PyPI downloads Code style: black

auto-pr

A command line tool to perform bulk updates across multiple GitHub repositories.

How to install

With pipx (recommended):

pipx install auto-pr

With pip:

pip install auto-pr

Usage

Usage

Init

First initialise the project directory by running the init command within an empty directory.

auto-pr init --api-key=<github_token> --ssh-key-file=<path-to-ssh-key>

Where <github_token> is a GitHub personal access token which has repo and user:user:email scope.

Next modify the generated config.yaml file with your desired configurations.

credentials:
  api_key: <github_token>
  ssh_key_file: /path/to/ssh/key/to/push/.ssh/id_rsa
pr:
  body: >
    Body of the PR that will be generated

    Can be multi-line :)
  branch: auto-pr # The branch name to use when making changes
  message: Replace default pipelines with modules # Commit message
  title: 'My awesome change' # Title of the PR
  draft: True # Whether to create the PR as a draft
repositories: # Rules that define what repos to update
  - mode: add
    match_owner: <org/user>
update_command:
  - touch
  - my-file

Using Environment Variables for Credentials

To avoid storing credentials in plain text within config.yaml, you can use environment variable expansion with the ${VAR_NAME} syntax:

credentials:
  api_key: ${GITHUB_API_KEY}
  ssh_key_file: ${HOME}/.ssh/id_rsa

Then set the environment variables before running auto-pr:

export GITHUB_API_KEY=ghp_your_token_here
export HOME=/home/username
auto-pr pull

Environment variables can be used in multiple ways:

  • Full replacement: api_key: ${GITHUB_API_KEY}
  • Embedded in paths: ssh_key_file: ${HOME}/.ssh/id_rsa
  • Multiple variables: ssh_key_file: ${USER_HOME}/${KEY_DIR}/id_rsa

If a referenced environment variable is not set, auto-pr will display a clear error message indicating which variable is missing.

Alternatively, if you wish to keep your API Key outside of config.yaml without modifying the config file, you can set the env var APR_API_KEY with your GitHub Token

Using a Custom Repositories Directory

By default, auto-pr clones repositories into a repos/ subdirectory within your working directory. If you already have repositories cloned locally (e.g., >1k repositories), you can configure auto-pr to use your existing directory instead:

Option 1: Config file

Add custom_repos_dir to your config.yaml:

credentials:
  api_key: ${GITHUB_API_KEY}
  ssh_key_file: ${HOME}/.ssh/id_rsa
pr:
  title: 'My awesome change'
  branch: auto-pr
  message: Update dependencies
  body: Automated update
  draft: false
repositories:
  - mode: add
    match_owner: myorg
update_command:
  - echo
  - "Hello"
custom_repos_dir: /path/to/existing/repos  # Point to your existing cloned repos

The custom_repos_dir field supports environment variable expansion:

custom_repos_dir: ${HOME}/all-my-repos

Option 2: CLI flag

Use the --repos-dir option when running commands:

auto-pr --repos-dir=/path/to/existing/repos pull
auto-pr --repos-dir=/path/to/existing/repos test
auto-pr --repos-dir=/path/to/existing/repos run

The CLI option takes precedence over the config file setting.

Important notes:

  • The custom repos directory must exist before running auto-pr init
  • auto-pr will use the existing cloned repositories and apply its cleanup operations as normal
  • This is useful for organizations with many repositories to avoid duplicating disk space

Repositories

You can define the list of repositories to pull and build into the database to update using a list of rules.

  • mode - either add or remove - used to either match or negate
  • public (optional) - pull only public or private, leave out for both
  • archived (optional) - archived or non-archived, leave out for both
  • match_owner (optional) - the owner or user to pull
  • match_name (optional) - a list of regular expressions to match against to pull

The flags of the filter rules are optional not specifying will run the command on all repositories that the token has access too.

Update Command

This is the list containing the command to be executed along with the arguments passed to it. It will be executed from the root of each repository that is processed.

If an error occurs during the execution it will be displayed in the output but will not halt the execution.

See example commands

Pull

After you have configured the project you can now pull the repositories down that match your rules.

auto-pr pull

This will generate a db.json file within your workdir containing a list of mapped repositories and their state.

This command can be run multiple times, if there are new matching repositories found they will be merged into the existing database.

If you would like to use your globally set config, you can pass the option --use-global-git-config when pulling the repos. If you had already pulled the repos before this and you would like to change the config for those repos, you would also need to pass --update-repos alongside the global-git-config option when pulling.

Test

Once the pull command has finished setting up the work directory you can now run test to check what the changes that will be made by the script will yield.

Run

When you're confident with the changes output from the test command you can finally execute run.

auto-pr run

This will perform the changes to a branch on the locally cloned repository and push the branch upstream with the information you provided within config.yaml.

By default, the commits will be associated with your primary email and name, which were set on the repo level for those repos when you ran auto-pr pull. If you would like to use your global git config for the repos that you already pulled, you need to run pull again with:

auto-pr pull --update-repos --use-global-git-config

See --help for more information about other commands and their usage.

Reset

You can reset the list of repos in db.json using auto-pr reset all, or auto-pr reset from FILE

When using auto-pr reset from FILE, the list of repos should be provided as a newline separated list of repos like <owner>/<name>, e.g:

getyourguide/test
getyourguide/auto-pr

Development

For information on setting up a development environment and contributing to auto-pr, see DEVELOPMENT.md.

Security

For sensitive security matters please contact security@getyourguide.com.

Legal

Copyright 2021 GetYourGuide GmbH.

auto-pr is licensed under the Apache License, Version 2.0. See LICENSE for the full text.

Metadata

Release files for auto-pr 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for auto-pr 1.2.0
File Size Uploaded Provenance Actions
auto_pr-1.2.0.tar.gz 130.0 kB Without provenance Details for auto_pr-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for auto-pr 1.2.0
File Interpreter ABI Platform Actions
auto_pr-1.2.0-py3-none-any.whl Python 3 none any Details for auto_pr-1.2.0-py3-none-any.whl

Total release size: 150.5 kB

Release files / auto_pr-1.2.0.tar.gz

Download URL auto_pr-1.2.0.tar.gz
Size 130.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5e51c3ed186fcbee7beb2de0ccefba3e1f040c41c1a5a7f232861d241597e2ea
BLAKE2b-256 checksum
How to use checksums
1fb9f16635849102dc6b2f411c46935a73d7cf0785520c2c6ac2e370dc20594e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / auto_pr-1.2.0-py3-none-any.whl

Download URL auto_pr-1.2.0-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b3124cb358e5a1688c18ad0dc583a0a0d2850636474dad9d866000383f55c05
BLAKE2b-256 checksum
How to use checksums
72b137f5e6f063005dc3371dd26771dd6fc93f4aac173204fedc4aebd1f67117
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for auto-pr 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page