-
Notifications
You must be signed in to change notification settings - Fork 30
62 lines (54 loc) · 2.29 KB
/
chromatic-label-helper.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
# The DCR repo has a required status check on the Chromatic UI Tests
# To save £££, we only run the Chromatic tests once the `run_chromatic`
# label is applied. This workflow reminds people to add the label
# because it isn't always obvious.
name: Chromatic Label Helper
on:
pull_request:
types: [opened, ready_for_review]
jobs:
write_comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
# We only comment on pull requests that have been marked as ready for review
if: ${{ github.event.pull_request.draft == false}}
steps:
- uses: actions/github-script@v7
with:
script: |
const labels = await github.rest.issues
.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
.then(({ data }) => data);
const hasChromaticLabel = labels.some(
(label) => label.name === 'run_chromatic',
);
if (!hasChromaticLabel) {
const commentLines = [
"Hello :wave:! When you're ready to run Chromatic, please apply the `run_chromatic` label to this PR.",
"You will need to reapply the label each time you want to run Chromatic.",
'[Click here to see the Chromatic project.](https://www.chromatic.com/builds?appId=63e251470cfbe61776b0ef19)',
];
/** Checks if this label helper has already commented on the pull request */
const hasChromaticCommentAlready = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
}).then(({ data }) => {
return data.some((comment) => {
return comment.body.includes(commentLines[0]);
});
});
if (!hasChromaticCommentAlready) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentLines.join('\n\n'),
});
}
}