Skip to content

Commit 472a050

Browse files
committed
chore(ci): convert inline gh-script to file to ease debugging
1 parent a5b70b6 commit 472a050

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = async ({github, context, core}) => {
2+
core.info(process.env);
3+
4+
const pr_number = process.env.PR_NUMBER
5+
const pr_title = process.env.PR_TITLE
6+
7+
const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
8+
const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/
9+
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/
10+
const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/
11+
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/
12+
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/
13+
14+
const labels = {
15+
"feature": FEAT_REGEX,
16+
"bug": BUG_REGEX,
17+
"documentation": DOCS_REGEX,
18+
"internal": CHORE_REGEX,
19+
"enhancement": REFACTOR_REGEX,
20+
"deprecated": DEPRECATED_REGEX,
21+
}
22+
23+
for (const label in labels) {
24+
const matcher = new RegExp(labels[label])
25+
const isMatch = matcher.exec(pr_title)
26+
if (isMatch != null) {
27+
console.info(`Auto-labeling PR ${pr_number} with ${label}`)
28+
29+
await github.rest.issues.addLabels({
30+
issue_number: pr_number,
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
labels: [label]
34+
})
35+
36+
break
37+
}
38+
}
39+
}

.github/workflows/label_pr_on_title.yml

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,14 @@ jobs:
2222
steps:
2323
- name: "Label PR based on title"
2424
uses: actions/github-script@v6
25+
env:
26+
PR_NUMBER: ${{ needs.get_pr_details.outputs.prNumber }}
27+
PR_TITLE: ${{ needs.get_pr_details.outputs.prTitle }}
2528
with:
2629
github-token: ${{ secrets.GITHUB_TOKEN }}
2730
# This safely runs in our base repo, not on fork
2831
# thus allowing us to provide a write access token to label based on PR title
2932
# and label PR based on semantic title accordingly
3033
script: |
31-
const pr_number = ${{ needs.get_pr_details.outputs.prNumber }};
32-
const pr_title = "${{ needs.get_pr_details.outputs.prTitle }}";
33-
34-
const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
35-
const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/
36-
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/
37-
const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/
38-
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/
39-
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/
40-
41-
const labels = {
42-
"feature": FEAT_REGEX,
43-
"bug": BUG_REGEX,
44-
"documentation": DOCS_REGEX,
45-
"internal": CHORE_REGEX,
46-
"enhancement": REFACTOR_REGEX,
47-
"deprecated": DEPRECATED_REGEX,
48-
}
49-
50-
for (const label in labels) {
51-
const matcher = new RegExp(labels[label])
52-
const isMatch = matcher.exec(pr_title)
53-
if (isMatch != null) {
54-
console.info(`Auto-labeling PR ${pr_number} with ${label}`)
55-
56-
await github.rest.issues.addLabels({
57-
issue_number: pr_number,
58-
owner: context.repo.owner,
59-
repo: context.repo.repo,
60-
labels: [label]
61-
})
62-
63-
break
64-
}
65-
}
34+
const script = require('.github/scripts/label_pr_based_on_title.js')
35+
await script({github, context, core})

0 commit comments

Comments
 (0)