You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a GitHub Action that updates a pull request with information extracted from branch name. The pull request title and body can either be prefixed or replaced.
6
+
This is a GitHub Action that updates a pull request with information extracted from branch name. The branch could be either base or head branch or both. The pull request title and body can either be prefixed, suffixed or replaced.
7
7
8
8
## Usage
9
9
10
-
### Create Workflow
11
-
12
-
Create a workflow yaml file (eg: `.github/workflows/update-pr.yml` see [Creating a Workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file)):
repo-token: "${{ secrets.GITHUB_TOKEN }}" # required - allows the action to make calls to GitHub's rest API
26
-
use-base-branch: false # required - whether to use target or pr for branch name
27
-
branch-regex: 'foo-\d+' # required - regex to match text from the head branch name
28
-
lowercase-branch: true # optional - whether to lowercase branch name before matching
29
-
title-template: '[%branch%]' # required - text template to update title with
30
-
replace-title: false # optional - whether to prefix or replace title with title-template
31
-
title-prefix-space: true # optional - whether to add a space after title prefix
32
-
uppercase-title: true # optional - whether to uppercase matched branch info in title
33
-
body-template: '[%branch%](https://browse/ticket/%branch%)' # required - text template to prefix body
34
-
replace-body: false # optional - whether to prefix or replace body with body-template
35
-
body-prefix-newline-count: 2 # optional - number of newlines to insert after body prefix
36
-
uppercase-body: true # optional - whether to uppercase matched branch info in body
37
-
```
38
-
39
-
`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 }}`
40
-
41
-
_**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._
10
+
Create a workflow yaml file (for e.g. `.github/workflows/update-pr.yml`). See [Creating a Workflow file](https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/introduction-to-github-actions#create-an-example-workflow).
11
+
12
+
### Inputs
13
+
14
+
#### Required
15
+
-`repo-token`: secret token to allow making calls to GitHub's rest API (for e.g. `${{ secrets.GITHUB_TOKEN }}`)
16
+
17
+
#### Optional
18
+
-`base-branch-regex`: regex to match text from the base branch name
19
+
-`head-branch-regex`: regex to match text from the head branch name
20
+
-`lowercase-branch`: whether to lowercase branch name before matching (default: `true`)
21
+
-`title-template`: text template to update title with
22
+
-`title-update-action`: whether to prefix or suffix or replace title with title-template (default: `prefix`)
23
+
-`title-insert-space`: whether to insert a space between title and its prefix or suffix (default: `true`)
24
+
-`title-uppercase-base-match`: whether to uppercase matched text from base branch in title (default: `true`)
25
+
-`title-uppercase-head-match`: whether to uppercase matched text from head branch in title (default: `true`)
26
+
-`body-template`: text template to update body with
27
+
-`body-update-action`: whether to prefix or replace body with body-template (default: `prefix`)
28
+
-`body-newline-count`: number of newlines to separate body and its prefix or suffix (default: `2`)
29
+
-`body-uppercase-base-match`: whether to uppercase matched text from base branch in body (default: `true`)
30
+
-`body-uppercase-head-match`: whether to uppercase matched text from head branch in body (default: `true`)
31
+
32
+
#### Notes:
33
+
34
+
- Value for at least one of `base-branch-regex` or `head-branch-regex` should be provided, otherwise the action will return an error. The value should be a [Javascript regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions).
35
+
-`title-template` and `body-template` can contain any of the following tokens (can be repeated if required) which will be replaced by the matched text from branch name:
36
+
-`%basebranch%`
37
+
-`%headbranch%`
38
+
-`title-update-action` and `body-update-action` can be set to one of the following values:
39
+
-`prefix`
40
+
-`suffix`
41
+
-`replace`
42
+
-`body-template` can be set to a GitHub secret if necessary to avoid leaking sensitive data. `body-template: ${{ secrets.PR_BODY_TEMPLATE }}`
43
+
44
+
### Outputs
45
+
46
+
-`baseMatch`: matched text from base branch if any
47
+
-`headMatch`: matched text from head branch if any
48
+
-`titleUpdated`: whether the PR title was updated
49
+
-`bodyUpdated`: whether the PR body was updated
42
50
43
51
## Example
44
52
@@ -49,22 +57,20 @@ name: "Update Pull Request"
49
57
on: pull_request
50
58
51
59
jobs:
52
-
pr_update_text:
60
+
update_pr:
53
61
runs-on: ubuntu-latest
54
62
steps:
55
-
- uses: tzkhan/pr-update-action@v1.1.1
63
+
- uses: tzkhan/pr-update-action@v2
56
64
with:
57
65
repo-token: "${{ secrets.GITHUB_TOKEN }}"
58
-
branch-regex: 'foo-\d+'
59
-
lowercase-branch: false
60
-
title-template: '[%branch%]'
61
-
replace-title: false
62
-
title-prefix-space: true
63
-
uppercase-title: true
64
-
body-template: '[Link to %branch%](https://url/to/browse/ticket/%branch%)'
65
-
replace-body: false
66
-
body-prefix-newline-count: 2
67
-
uppercase-body: true
66
+
base-branch-regex: '[a-z\d-_.\\/]+'
67
+
head-branch-regex: 'foo-\d+'
68
+
title-template: '[%headbranch%] '
69
+
body-template: |
70
+
Merging into '%basebranch%'
71
+
[Link to %headbranch%](https://url/to/browse/ticket/%headbranch%)
0 commit comments