Skip to content

Commit 67c1b81

Browse files
authored
Merge pull request #902 from Stremio/feat/add-auto-label-assignments-on-prs
chore(Github): auto assignments on PRs
2 parents 83a7f6f + 107564b commit 67c1b81

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

.github/workflows/auto_assign.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: PR and Issue Workflow
2+
on:
3+
pull_request:
4+
types: [opened, reopened]
5+
issues:
6+
types: [opened]
7+
jobs:
8+
auto-assign-and-label:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
issues: write
12+
pull-requests: write
13+
steps:
14+
# Auto assign PR to author
15+
- name: Auto Assign PR to Author
16+
if: github.event_name == 'pull_request'
17+
uses: actions/github-script@v6
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
script: |
21+
const pr = context.payload.pull_request;
22+
if (pr) {
23+
await github.rest.issues.addAssignees({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
issue_number: pr.number,
27+
assignees: [pr.user.login]
28+
});
29+
console.log(`Assigned PR #${pr.number} to author @${pr.user.login}`);
30+
}
31+
32+
# Dynamic labeling based on PR/Issue title
33+
- name: Label PRs and Issues
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
uses: actions/github-script@v6
37+
with:
38+
github-token: ${{ secrets.GITHUB_TOKEN }}
39+
script: |
40+
const prTitle = context.payload.pull_request ? context.payload.pull_request.title : context.payload.issue.title;
41+
const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : context.payload.issue.number;
42+
const isIssue = context.payload.issue !== undefined;
43+
const labelMappings = [
44+
{ pattern: /^feat(ure)?/i, label: 'feature' },
45+
{ pattern: /^fix/i, label: 'bug' },
46+
{ pattern: /^refactor/i, label: 'refactor' },
47+
{ pattern: /^chore/i, label: 'chore' },
48+
{ pattern: /^docs?/i, label: 'documentation' },
49+
{ pattern: /^perf(ormance)?/i, label: 'performance' },
50+
{ pattern: /^test/i, label: 'testing' }
51+
];
52+
let labelsToAdd = [];
53+
for (const mapping of labelMappings) {
54+
if (mapping.pattern.test(prTitle)) {
55+
labelsToAdd.push(mapping.label);
56+
}
57+
}
58+
if (labelsToAdd.length > 0) {
59+
github.rest.issues.addLabels({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
issue_number: issueNumber,
63+
labels: labelsToAdd
64+
});
65+
}

0 commit comments

Comments
 (0)