Skip to content

Commit 78a4820

Browse files
Merge pull request #57 from tharapalanivel/pr_label_workflow
ci: Add workflow for PR labels
2 parents 9301123 + fa69992 commit 78a4820

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

.github/workflows/labelpr.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Label PRs
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, edited, synchronize, reopened]
6+
7+
jobs:
8+
label_pr:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/github-script@v7
12+
with:
13+
github-token: ${{ secrets.GITHUB_TOKEN }}
14+
script: |
15+
const pr_welcome_msg = `Thanks for making a pull request! 😃\nOne of the maintainers will review and advise on the next steps.`;
16+
// https://github.com/commitizen/conventional-commit-types
17+
const valid_pr_types = ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert'];
18+
19+
if(context.payload.pull_request.comments === 0) {
20+
await github.issues.createComment({ ...context.repo, issue_number: context.payload.number, body: pr_welcome_msg});
21+
}
22+
23+
const title = context.payload.pull_request.title;
24+
const results = /^(\w+)(\(\w+\))?!?:/.exec(title);
25+
if (results === null) return core.setFailed(`The title does not follow conventional commits spec: https://www.conventionalcommits.org/en/v1.0.0/#summary Title: ${title}`);
26+
27+
const pr_type = results[1];
28+
core.info(`pr_type: ${pr_type}`);
29+
30+
if (!valid_pr_types.includes(pr_type)) return core.setFailed(`Unknown pull request type: ${pr_type}`);
31+
32+
const labels = context.payload.pull_request.labels;
33+
const new_labels = labels.filter(label => !valid_pr_types.includes(label.name)); // keep all labels that are not in valid_pr_types
34+
new_labels.push({name: pr_type});
35+
await github.issues.update({ ...context.repo, issue_number: context.payload.number, labels: new_labels });

0 commit comments

Comments
 (0)