forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (64 loc) · 2.37 KB
/
auto-assign.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Auto assign pull requests
on:
pull_request:
types:
- opened
jobs:
update_pr:
runs-on: ubuntu-latest
steps:
- uses: tibdex/[email protected]
id: generate-token
with:
app_id: ${{ secrets.METABASE_BOT_APP_ID }}
private_key: ${{ secrets.METABASE_BOT_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
- name: Assign author and their team. Returns true if team exists.
id: auto-assign
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const fs = require('fs');
const teamConfig = JSON.parse(fs.readFileSync('.github/team.json', 'utf-8'));
const prAuthor = context.payload.pull_request.user.login;
const prNumber = context.payload.pull_request.number;
if (prAuthor.endsWith('[bot]')) {
return null;
}
// Assign PR author
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
assignees: [prAuthor]
});
const team = teamConfig.teams.find(t => t.members.includes(prAuthor));
if (!team) {
console.log('You are not assigned to any team. If you need one, update .github/team.json');
return null;
}
try {
const label = await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: team.label
});
} catch (e) {
console.log(`The label ${team.label} does not exist, create it first`);
return null;
}
// Add team label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: [team.label]
});
return team.projectUrl || null;
- uses: actions/[email protected]
if: ${{ steps.auto-assign.outputs.result != 'null' }}
with:
project-url: ${{ steps.auto-assign.outputs.result }}
github-token: ${{ steps.generate-token.outputs.token }}