This GitHub action automates the process of creating a pull request from local changes. It utilizes the GitHub REST API to create commits. If the GitHub token used in this action is a bot token, the commits will be created as signed and shown as verified.
The GitHub token required to perform actions such as pushing commits and creating pull requests.
The base branch to create the pull request against. Defaults to the current
github.ref
context if not set. The git reference for the base must exists
locally (i.e. "fetched").
The name of the new branch to be created by this action. If an existing branch
with the same name exists in the repository, the action will fail, unless the
upsert
option is enabled. In that case, the branch will be force-updated.
The commit message for the new commit created by this action.
The title of the pull request that will be created.
Optional
The body content of the pull request. This can provide additional information or context for the changes being made.
Optional
The repository to create the branch and pull request on, for example
canonical/create-pull-request
. Defaults to the current repository if not set.
Options: true | false
Default: false
By default, the action fails if there's an existing branch with the same name in
the repository. Enabling upsert
allows this action to update the existing
branch and its related pull request instead of doing nothing and failing.
WARNING: In upsert mode, commits in the existing branch will be irreversibly removed.
Options: true | false
Default: false
By default, the action fails if no local changes are detected. Enabling this option allows the action to do nothing and exit successfully when there are no changes.
Options: true | false
Default: false
When set to true, the action will enable auto-merge using the squash merge method for the pull request and delete the branch after merge.
Create a new-branch
branch with the changes to the current repository.
create-pull-request:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Change local files
run: |
echo hello > hello
echo new-test > test
- name: Create pull request
uses: canonical/create-pull-request@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Test commit message
branch-name: new-branch
title: Test pull request
body: Test pull request body
Create a new-branch
branch with the changes to a different repository (i.e.
test-owner/test-repo
in this example). Note, that the github-token
will need
to be a repo
scoped Personal Access Token (PAT) or it can be a github
app token with access to that repository.
create-pull-request:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: test-owner/test-repo
- name: Change local files
run: |
echo hello > hello
echo new-test > test
- name: Create pull request
uses: canonical/create-pull-request@main
with:
github-token: ${{ secrets.TOKEN_FOR_TEST_REPO }}
commit-message: Test commit message
branch-name: new-branch
title: Test pull request
body: Test pull request body
repository: test-owner/test-repo