@@ -22,44 +22,14 @@ jobs:
22
22
steps :
23
23
- name : " Label PR based on title"
24
24
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 }}
25
28
with :
26
29
github-token : ${{ secrets.GITHUB_TOKEN }}
27
30
# This safely runs in our base repo, not on fork
28
31
# thus allowing us to provide a write access token to label based on PR title
29
32
# and label PR based on semantic title accordingly
30
33
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