Skip to content

Commit 49e3000

Browse files
authored
Merge pull request #17 from tzkhan/debug-warnings
[updated-by-action] V2 updates
2 parents 7d08127 + 5905939 commit 49e3000

File tree

9 files changed

+10565
-10475
lines changed

9 files changed

+10565
-10475
lines changed

.github/workflows/update-pr.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@ name: "Update Pull Request"
33
on: pull_request
44

55
jobs:
6-
pr_update_text:
6+
update_pr:
77
runs-on: ubuntu-latest
8+
outputs:
9+
baseMatch: ${{ steps.update_pr.outputs.baseMatch }}
10+
headMatch: ${{ steps.update_pr.outputs.headMatch }}
11+
titleUpdated: ${{ steps.update_pr.outputs.titleUpdated }}
12+
bodyUpdated: ${{ steps.update_pr.outputs.bodyUpdated }}
813
steps:
9-
- uses: tzkhan/[email protected]
14+
- id: update_pr
15+
uses: tzkhan/pr-update-action@debug-warnings
1016
with:
1117
repo-token: "${{ secrets.GITHUB_TOKEN }}"
12-
branch-regex: '[a-z\d-_.\/]+'
13-
lowercase-branch: true
18+
head-branch-regex: '[a-z\d-_.\/]+'
1419
title-template: "[updated-by-action]"
15-
replace-title: false
16-
title-prefix-space: true
17-
uppercase-title: false
1820
body-template: "[Updated by Pull Request Updater action]"
19-
replace-body: false
20-
body-prefix-newline-count: 2
21-
uppercase-body: false
21+
update_pr_outputs:
22+
runs-on: ubuntu-latest
23+
needs: update_pr
24+
steps:
25+
- run: |
26+
echo 'baseMatch:' ${{needs.update_pr.outputs.baseMatch}}
27+
echo 'headMatch:' ${{needs.update_pr.outputs.headMatch}}
28+
echo 'titleUpdated:' ${{needs.update_pr.outputs.titleUpdated}}
29+
echo 'bodyUpdated:' ${{needs.update_pr.outputs.bodyUpdated}}

README.md

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,50 @@
33
![Update Pull Request](https://github.com/tzkhan/pr-update-action/workflows/Update%20Pull%20Request/badge.svg)
44
[![Release](https://img.shields.io/github/release/tzkhan/pr-update-action.svg)](https://github.com/tzkhan/pr-update-action/releases/latest)
55

6-
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.
77

88
## Usage
99

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)):
13-
14-
```
15-
name: "Update Pull Request"
16-
17-
on: pull_request
18-
19-
jobs:
20-
update_pr:
21-
runs-on: ubuntu-latest
22-
steps:
23-
- uses: tzkhan/[email protected]
24-
with:
25-
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
4250

4351
## Example
4452

@@ -49,22 +57,20 @@ name: "Update Pull Request"
4957
on: pull_request
5058
5159
jobs:
52-
pr_update_text:
60+
update_pr:
5361
runs-on: ubuntu-latest
5462
steps:
55-
- uses: tzkhan/pr-update-action@v1.1.1
63+
- uses: tzkhan/pr-update-action@v2
5664
with:
5765
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%)
72+
body-update-action: 'suffix'
73+
body-uppercase-base-match: false
6874
```
6975

7076
produces this effect... :point_down:

action.yml

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,74 @@
1-
name: 'Pull Request Updater GitHub Action'
2-
description: 'GitHub Action that updates a pull request with information extracted from branch name'
3-
author: 'Tamim Khan'
1+
name: "Pull Request Updater GitHub Action"
2+
description: "GitHub Action that updates a pull request with information extracted from branch name"
3+
author: "Tamim Khan"
44
runs:
5-
using: 'node12'
6-
main: 'dist/index.js'
5+
using: "node12"
6+
main: "dist/index.js"
77
inputs:
88
repo-token:
9-
description: 'The GITHUB_TOKEN secret'
9+
description: "The GITHUB_TOKEN secret"
1010
required: true
11-
use-base-branch:
12-
description: 'Whether to use target branch or pr branch for branch name'
11+
base-branch-regex:
12+
description: "Regex to match text in the base branch name"
1313
required: false
14-
default: false
15-
branch-regex:
16-
description: 'Regex to match branch name'
17-
required: true
18-
default: 'foo-\d+'
14+
default: ""
15+
head-branch-regex:
16+
description: "Regex to match text in the head branch name"
17+
required: false
18+
default: ""
1919
lowercase-branch:
20-
description: 'Should lowercase branch name before matching text'
20+
description: "Should lowercase branch name before matching text"
2121
required: false
22-
default: false
22+
default: "true"
2323
title-template:
24-
description: 'Title template where branch info gets substituted in'
25-
required: true
26-
default: '[%branch%]'
27-
replace-title:
28-
description: 'Should replace title instead of prefixing'
24+
description: "Title template where matched text from branch gets substituted in. Allowed tokens: %basebranch% | %headbranch%"
25+
required: false
26+
default: ""
27+
title-update-action:
28+
description: "Update action to perform on the title. Allowed values: prefix | suffix | replace"
2929
required: false
30-
default: false
31-
title-prefix-space:
32-
description: 'Should add space after title prefix'
30+
default: "prefix"
31+
title-insert-space:
32+
description: "Should insert a space between title and its prefix or suffix"
3333
required: false
34-
default: true
35-
uppercase-title:
36-
description: 'Should uppercase matched branch info in title'
34+
default: "true"
35+
title-uppercase-base-match:
36+
description: "Should uppercase matched text from base branch in title"
3737
required: false
38-
default: true
38+
default: "true"
39+
title-uppercase-head-match:
40+
description: "Should uppercase matched text from head branch in title"
41+
required: false
42+
default: "true"
3943
body-template:
40-
description: 'Body template where branch info gets substituted in'
41-
required: true
42-
default: '[%branch%](https://url/to/browse/ticket/%branch%)'
43-
replace-body:
44-
description: 'Should replace body instead of prefixing'
44+
description: "Body template where matched text from branch gets substituted in. Allowed tokens: %basebranch% | %headbranch%"
45+
required: false
46+
default: ""
47+
body-update-action:
48+
description: "Update action to perform on the body. Allowed values: prefix | suffix | replace"
49+
required: false
50+
default: "prefix"
51+
body-newline-count:
52+
description: "Number of newlines to separate body and its prefix or suffix"
4553
required: false
46-
default: false
47-
body-prefix-newline-count:
48-
description: 'Number of newlines to separate body and its prefix'
54+
default: "2"
55+
body-uppercase-base-match:
56+
description: "Should uppercase matched text from base branch in body"
4957
required: false
50-
default: 2
51-
uppercase-body:
52-
description: 'Should uppercase matched branch info in body'
58+
default: "true"
59+
body-uppercase-head-match:
60+
description: "Should uppercase matched text from head branch in body"
5361
required: false
54-
default: true
62+
default: "true"
63+
outputs:
64+
baseMatch:
65+
description: "Matched text from base branch if any"
66+
headMatch:
67+
description: "Matched text from head branch if any"
68+
titleUpdated:
69+
description: "Whether the PR title was updated"
70+
bodyUpdated:
71+
description: "Whether the PR body was updated"
5572
branding:
56-
icon: 'edit-3'
57-
color: 'green'
58-
73+
icon: "edit-3"
74+
color: "green"

0 commit comments

Comments
 (0)