Chain pull requests from your devbranch's commits.
Project description
ghchain
ghchain automates the creation of chained pull requests for each commit in your development branch, facilitating a clear and organized review process. This tool is heavily inspired by ghstack and further details on the concept of stacked pull requests can be found in this blog post.
Features
- Automated Branch Creation: Creates a new branch for each commit on your development branch.
- Pull Request Management: Automatically creates a GitHub pull request for each branch, stacking them sequentially for streamlined review.
- Configurable Workflows: Supports custom GitHub Actions workflows via
.ghchain.tomlfor automated testing and checks. - Dynamic Branch Naming: Configurable branch naming schemes to match your project's conventions.
- Issue Link Detection: Customizable regex patterns to detect linked issues in commit messages.
- Logging: Detailed logging to track the process of ghchain.
- git notes: ghchain adds a git note to each commit with
- the PR number, to easily track the PRs.
- workflow status, to see if the workflows have passed.
- status checks, to see if the status checks have passed.
[!CAUTION] Running
ghchainwith multiple branches containing the same commit may lead to conflicts or errors.
Configuration
Configure ghchain using a .ghchain.toml file in the root of your repository. Current configuration options include:
workflows = [] # List of GitHub Actions workflows to run with the tests flags
base_branch = "origin/main" # Base branch for the PRs
branch_name_template = "{git_config_author}-{pr_id}" # Template for naming branches, customizable to include author name and a PR identifier.
delete_branch_after_merge = true # Whether to delete the branch after the PR is merged
log_file = "path/to/ghchain.log" # Path to the log file
log_level = "INFO" # Logging level
# Regex pattern to detect linked issues in commit messages.
# This one is for the default pattern of "(#<issue_number>)"
issue_pattern = "\\\\(#(\\\\d+)\\\\)"
Usage
$ ghchain --help
Usage: ghchain [OPTIONS] COMMAND [ARGS]...
Create a branch for each commit in the stack that doesn't already have one.
Optionally, create a PR for each branch and run the github workflows that
are specified in the .ghchain.toml config of the repository.
Usage:
ghchain: will create a branch for each commit in the stack that doesn't
already have one and push it to the remote.
ghchain --create-pr: will create a branch for each commit in the stack that
doesn't already have one, push it to the remote and create a PR for each
branch.
ghchain --draft: will create a branch for each commit in the stack that
doesn't already have one, push it to the remote and create a draft PR for
each branch.
ghchain --with-tests: will create a branch for each commit in the stack that
doesn't already have one, push it to the remote and run the github
workflows that are specified in the .ghchain.toml config of the
repository.
Options:
-p, --create-pr If set to True, a pull request will be opened for every
commit.
--draft Create the pull request as a draft. This flag sets
--create-pr to True.
--with-tests Run the github workflows that are specified in the
.ghchain.toml config of the repository.
--help Show this message and exit.
Commands:
fix-refs If you messed up your stack with a rebase and lost the...
land Merge the specified branch into the configured base branch.
publish Publish all updated branches in the stack to the remote.
rebase Rebase the current branch onto branch, using...
refresh Update the commit notes with the PR/ workflow statuses...
run-workflows Run the github workflows that are specified in the...
Usage Example
Let's say that you're working on your dev branch mydev and you've cleaned up your changes into 4 commits:
git log main..mydev
>> commit 64bd042e9d7be39a180bcb7d0a788c23b75682fd (HEAD -> mydev)
>> Author: Hendrik Klug
>> Date: Sat Apr 13 14:27:25 2042 +0200
>>
>> commit 3
>>
>> commit 80edccef17a7086b7a90b03bf18a5c763adf741f
>> Author: Hendrik Klug
>> Date: Sat Apr 13 14:27:25 2042 +0200
>>
>> [feat] commit 2 (#2558)
>>
>> commit b64c30667ad23847e981e4c9bafe8eee3ffb0881
>> Author: Hendrik Klug
>> Date: Sat Apr 13 14:27:25 2042 +0200
>>
>> commit 1
>>
>> commit 51d6204578eacb3ee78fd1488e367e37bb20b492
>> Author: Hendrik Klug
>> Date: Sat Apr 13 14:27:25 2042 +0200
>>
>> commit 0
[!NOTE] "commit 2" references issue #2558 in the commit message. Ghchain will use this information to link the branch or PR to the issue.
You would like to make the life of the reviewer easier by creating a pull request for each commit.
Running ghchain -p will create a new branch for each commit and create a pull request for each of those branches:
git log main..mydev
commit 64bd042e9d7be39a180bcb7d0a788c23b75682fd (HEAD -> mydev, origin/hk-136, hk-136)
Author: Hendrik Klug
Date: Sat Apr 13 14:27:25 2042 +0200
commit 3
commit 80edccef17a7086b7a90b03bf18a5c763adf741f (origin/hk-135, hk-135)
Author: Hendrik Klug
Date: Sat Apr 13 14:27:25 2042 +0200
[feat] commit 2 (#2558)
Notes:
[ghchain]
issue = https://github.com/HendrikKlug-synthara/mytest/issues/2558
commit b64c30667ad23847e981e4c9bafe8eee3ffb0881 (origin/hk-134, hk-134)
Author: Hendrik Klug
Date: Sat Apr 13 14:27:25 2042 +0200
commit 1
commit 51d6204578eacb3ee78fd1488e367e37bb20b492 (origin/hk-133, hk-133)
Author: Hendrik Klug
Date: Sat Apr 13 14:27:25 2042 +0200
commit 0
[!NOTE] The pull request that was created for
commit 2will automatically have a reference to issue #2558. The commit also has a git note with the issue link. You can configure the issue pattern with which linked issues are detected in the.ghchain.tomlfile.
[!NOTE] The
with-testsflag can also be passed toghchain process-commits. If it is passed all workflows defined in the.ghchain.tomlfile will be run for each commit.
The pull requests then look like the following (see my test repo for reference):
A single pull request, with the with-tests flag passed, will look like this:
Fixing commits
Your reviewer is verry happy with your small pull request, but would like you to fix a small issue in commit 1.
You stash your new changes from mydev and checkout the branch hk-134.
You fix the issue with either git commit --amend or git commit --fixup b64c30667ad23847e981e4c9bafe8eee3ffb0881 and push the changes.
To rebase your whole stack on top of the new commit, you can checkout your mydev branch and run ghchain rebase hk-134.
This will run a git rebase --update-refs hk-134 and push the changes to the remote, hence updating your pull requests.
[!NOTE] You can also pass the --interactive flag to the rebase command to run an interactive rebase.
Checking the status of the PRs/Commits
You can run ghchain refresh to update the git notes of your commits.
This will update the workflow status and the status checks of each commit.
git log will then show the following:
commit 51d6204578eacb3ee78fd1488e367e37bb20b492 (origin/hk-133, hk-133)
Author: Hendrik Klug
Date: Sat Apr 13 14:27:25 2042 +0200
commit 0
Notes:
[ghchain]
pr url = https://github.com/HendrikKlug-synthara/mytest/pull/1961
Review Decision =
Mergable = MERGEABLE
is_draft = False
title = commit 0
[[workflow_statuses]]
| name | status | conclusion |
|:-----------|:---------|:-------------|
| workflow_1 | ✅ | ✅ |
| workflow_2 | ✅ | ✅ |
Installation
[!CAUTION] ghchain uses the github cli gh to interact with the github api.
It needs to be installed and configured beforeghchaincan be used.
pip release version
pip install ghchain
pip live version
pip install git+https://github.com/Jimmy2027/ghchain.git
portage
ghchain is available via Jimmy's overlay.
Either enable the repo or copy the ebuild to your local overlay.
Then run:
emerge -av ghchain
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ghchain-0.1.6.tar.gz.
File metadata
- Download URL: ghchain-0.1.6.tar.gz
- Upload date:
- Size: 178.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6af713fbae9489ca62e86b4b2489bc1d8f54899d4363f834e0af1c2ffe3f3c64
|
|
| MD5 |
2b9b82186f6da0dad448f601a5cdbb73
|
|
| BLAKE2b-256 |
289d6d7dda7bbde4cb23ffef4861da14cbb45ed7577ee12a933657c227064e52
|
Provenance
The following attestation bundles were made for ghchain-0.1.6.tar.gz:
Publisher:
release.yaml on Jimmy2027/ghchain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghchain-0.1.6.tar.gz -
Subject digest:
6af713fbae9489ca62e86b4b2489bc1d8f54899d4363f834e0af1c2ffe3f3c64 - Sigstore transparency entry: 157254842
- Sigstore integration time:
-
Permalink:
Jimmy2027/ghchain@7d51dd856b33668d367db0893deefe55f6f44b48 -
Branch / Tag:
refs/tags/0.1.6 - Owner: https://github.com/Jimmy2027
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@7d51dd856b33668d367db0893deefe55f6f44b48 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ghchain-0.1.6-py3-none-any.whl.
File metadata
- Download URL: ghchain-0.1.6-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee882238e15405d35934a6368231e344b261532d2ac1e9df3c7472a253e8d8d5
|
|
| MD5 |
e2d69b2df5ba7d932627c8ba07f22857
|
|
| BLAKE2b-256 |
a3efe8388abb78af9635dae3438ec9574fb76e0c20a5bf55abe0c5b0809cc3f4
|
Provenance
The following attestation bundles were made for ghchain-0.1.6-py3-none-any.whl:
Publisher:
release.yaml on Jimmy2027/ghchain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghchain-0.1.6-py3-none-any.whl -
Subject digest:
ee882238e15405d35934a6368231e344b261532d2ac1e9df3c7472a253e8d8d5 - Sigstore transparency entry: 157254843
- Sigstore integration time:
-
Permalink:
Jimmy2027/ghchain@7d51dd856b33668d367db0893deefe55f6f44b48 -
Branch / Tag:
refs/tags/0.1.6 - Owner: https://github.com/Jimmy2027
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@7d51dd856b33668d367db0893deefe55f6f44b48 -
Trigger Event:
push
-
Statement type: