This is a GitHub Action that updates a pull request with information extracted from branch name.
Create a workflow yaml file (eg: .github/workflows/update-pr.yml
see Creating a Workflow file):
name: "Update Pull Request"
on: pull_request
jobs:
update_pr:
runs-on: ubuntu-latest
steps:
- uses: tzkhan/pr-update-action@v1
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}" # required - allows the action to make calls to GitHub's rest API
branch-regex: 'FOO-\d+' # required - regex to match text from the head branch name
lowercase-branch: true # optional - whether to lowercase branch name before matching # optional - whether to uppercase title prefix
body-template: '[%branch%](https://browse/ticket/%branch%)' # optional - text template to prefix body
body-prefix-newline-count: 2 # optional - number of newlines to insert after body prefix
uppercase-body: true # optional - whether to uppercase body prefix
body-template
can be set to a GitHub secret if necessary to avoid leaking sensitive data in the URLs for instance. body-template: ${{ secrets.PR_BODY_PREFIX_TEMPLATE }}
NOTE: template values must contain the %branch%
token (can occur multiple times) so that it can be replaced with the matched text from the branch name.
So the following yaml
name: "Update Pull Request"
on: pull_request
jobs:
pr_update_text:
runs-on: ubuntu-latest
steps:
- uses: tzkhan/pr-update-action@v1
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
branch-regex: 'foo-\d+'
lowercase-branch: false
body-template: '[Link to %branch%](https://url/to/browse/ticket/%branch%)'
body-prefix-newline-count: 2
uppercase-body: true
produces this effect... 👇