forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 2
79 lines (62 loc) · 2.71 KB
/
check-milestone.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
75
76
77
name: Milestone Reminder
on:
pull_request:
jobs:
milestone-reminder:
name: Remind to set milestone
runs-on: ubuntu-22.04
timeout-minutes: 5
permissions:
pull-requests: write
issues: read
steps:
- uses: actions/github-script@v7
with:
script: | # js
const { getLinkedIssues } = require('${{ github.workspace }}/release/utils/index.cjs');
const owner = context.repo.owner;
const repo = context.repo.repo;
const pullNumber = '${{ github.event.pull_request.number }}';
function getMilestone(pullOrIssue) {
// pull has pull.data.milestone, issue has issue.milestone
return pullOrIssue?.data?.milestone || pullOrIssue?.milestone;
}
const pull = await github.rest.pulls.get({
owner,
repo,
pull_number: pullNumber,
});
if (getMilestone(pull)) {
console.log("Pull request has milestone", pull.data.milestone?.title);
process.exit(0);
}
// the github API doesn't expose linked issues, so we have to parse the body ourselves
const linkedIssues = getLinkedIssues(pull);
if (Array.isArray(linkedIssues) && linkedIssues.length > 0) {
console.log('linked issue(s) found');
linkedIssues.forEach((issueId, index) => {
const issue = await github.rest.issues.get({
owner,
repo,
issue_number: issueId,
});
const milestone = getMilestone(issue);
if (milestone) {
console.log(`Linked issue #${issueId} has milestone`, milestone.title);
index === linkedIssues.length -1 && process.exit(0);
} else {
console.log("No milestone found");
const author = pull.data.user.login;
const guideLink = "https://www.notion.so/metabase/Metabase-Branching-Strategy-6eb577d5f61142aa960a626d6bbdfeb3?pvs=4#3dea255ffa3b4f74942a227844e889fa";
const message = `@${author} Did you forget to add a milestone to the issue for this PR? _[When and where should I add a milestone?](${guideLink})_`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: pullNumber,
body: message,
});
// Exit as soon as we found an issue without a milestone and alerted the author.
process.exit(0);
}
});
}