Skip to content

Commit d56f9f8

Browse files
authored
PR Checks: Trigger milestone check on labeled/unlabeled actions (#95)
1 parent 96d641f commit d56f9f8

File tree

4 files changed

+33
-133
lines changed

4 files changed

+33
-133
lines changed

pr-checks/checks/MilestoneCheck.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pr-checks/checks/MilestoneCheck.test.ts

Lines changed: 30 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -6,138 +6,38 @@ import { Dispatcher } from '../Dispatcher'
66
import { CheckState } from '../types'
77
import { MilestoneCheck } from './MilestoneCheck'
88

9+
const prEvents = ['pull_request', 'pull_request_target']
10+
const prActions = ['opened', 'reopened', 'ready_for_review', 'synchronize', 'labeled', 'unlabeled']
11+
12+
const prTestCases = prEvents
13+
.flatMap((event) => {
14+
return prActions.map((action) => ({
15+
eventName: event,
16+
action: action,
17+
}))
18+
})
19+
.flatMap((tc) => [
20+
{
21+
testCaseName: 'without milestone set',
22+
eventName: tc.eventName,
23+
action: tc.action,
24+
checkState: CheckState.Failure,
25+
description: 'Failed',
26+
pull_request_payload: {},
27+
},
28+
{
29+
testCaseName: 'with milestone set',
30+
eventName: tc.eventName,
31+
action: tc.action,
32+
checkState: CheckState.Success,
33+
description: 'Milestone set',
34+
pull_request_payload: { milestone: {} },
35+
},
36+
])
37+
938
describe('MilestoneCheck', () => {
1039
describe('Pull Requests', () => {
11-
test.each([
12-
{
13-
testCaseName: 'without milestone set',
14-
eventName: 'pull_request',
15-
action: 'opened',
16-
checkState: CheckState.Failure,
17-
description: 'Failed',
18-
pull_request_payload: {},
19-
},
20-
{
21-
testCaseName: 'without milestone set',
22-
eventName: 'pull_request',
23-
action: 'reopened',
24-
checkState: CheckState.Failure,
25-
description: 'Failed',
26-
pull_request_payload: {},
27-
},
28-
{
29-
testCaseName: 'without milestone set',
30-
eventName: 'pull_request',
31-
action: 'synchronize',
32-
checkState: CheckState.Failure,
33-
description: 'Failed',
34-
pull_request_payload: {},
35-
},
36-
{
37-
testCaseName: 'without milestone set',
38-
eventName: 'pull_request',
39-
action: 'ready_for_review',
40-
checkState: CheckState.Failure,
41-
description: 'Failed',
42-
pull_request_payload: {},
43-
},
44-
{
45-
testCaseName: 'without milestone set',
46-
eventName: 'pull_request_target',
47-
action: 'opened',
48-
checkState: CheckState.Failure,
49-
description: 'Failed',
50-
pull_request_payload: {},
51-
},
52-
{
53-
testCaseName: 'without milestone set',
54-
eventName: 'pull_request_target',
55-
action: 'reopened',
56-
checkState: CheckState.Failure,
57-
description: 'Failed',
58-
pull_request_payload: {},
59-
},
60-
{
61-
testCaseName: 'without milestone set',
62-
eventName: 'pull_request_target',
63-
action: 'ready_for_review',
64-
checkState: CheckState.Failure,
65-
description: 'Failed',
66-
pull_request_payload: {},
67-
},
68-
{
69-
testCaseName: 'without milestone set',
70-
eventName: 'pull_request_target',
71-
action: 'synchronize',
72-
checkState: CheckState.Failure,
73-
description: 'Failed',
74-
pull_request_payload: {},
75-
},
76-
{
77-
testCaseName: 'with milestone set',
78-
eventName: 'pull_request',
79-
action: 'opened',
80-
checkState: CheckState.Success,
81-
description: 'Milestone set',
82-
pull_request_payload: { milestone: {} },
83-
},
84-
{
85-
testCaseName: 'with milestone set',
86-
eventName: 'pull_request',
87-
action: 'reopened',
88-
checkState: CheckState.Success,
89-
description: 'Milestone set',
90-
pull_request_payload: { milestone: {} },
91-
},
92-
{
93-
testCaseName: 'with milestone set',
94-
eventName: 'pull_request',
95-
action: 'ready_for_review',
96-
checkState: CheckState.Success,
97-
description: 'Milestone set',
98-
pull_request_payload: { milestone: {} },
99-
},
100-
{
101-
testCaseName: 'with milestone set',
102-
eventName: 'pull_request',
103-
action: 'synchronize',
104-
checkState: CheckState.Success,
105-
description: 'Milestone set',
106-
pull_request_payload: { milestone: {} },
107-
},
108-
{
109-
testCaseName: 'with milestone set',
110-
eventName: 'pull_request_target',
111-
action: 'opened',
112-
checkState: CheckState.Success,
113-
description: 'Milestone set',
114-
pull_request_payload: { milestone: {} },
115-
},
116-
{
117-
testCaseName: 'with milestone set',
118-
eventName: 'pull_request_target',
119-
action: 'reopened',
120-
checkState: CheckState.Success,
121-
description: 'Milestone set',
122-
pull_request_payload: { milestone: {} },
123-
},
124-
{
125-
testCaseName: 'with milestone set',
126-
eventName: 'pull_request_target',
127-
action: 'ready_for_review',
128-
checkState: CheckState.Success,
129-
description: 'Milestone set',
130-
pull_request_payload: { milestone: {} },
131-
},
132-
{
133-
testCaseName: 'with milestone set',
134-
eventName: 'pull_request_target',
135-
action: 'synchronize',
136-
checkState: CheckState.Success,
137-
description: 'Milestone set',
138-
pull_request_payload: { milestone: {} },
139-
},
140-
])(
40+
test.each(prTestCases)(
14141
'$eventName - $action - $testCaseName - Should create status $checkState',
14242
async ({ eventName, action, checkState, description, pull_request_payload }) => {
14343
const createStatusMock = jest.fn()

pr-checks/checks/MilestoneCheck.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class MilestoneCheck extends Check {
2020
subscribe(s: CheckSubscriber) {
2121
s.on(
2222
['pull_request', 'pull_request_target'],
23-
['opened', 'reopened', 'ready_for_review', 'synchronize'],
23+
['opened', 'reopened', 'ready_for_review', 'synchronize', 'labeled', 'unlabeled'],
2424
async (ctx) => {
2525
const pr = context.payload.pull_request as EventPayloads.WebhookPayloadPullRequestPullRequest
2626

repository-dispatch/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RepositoryDispatch extends Action {
1212
throw new Error('Missing repository')
1313
}
1414

15-
const api = new OctoKit(this.getToken(), context.repo)
15+
const api = new OctoKit(this.getToken(), context.repo)
1616

1717
const [owner, repo] = repository.split('/')
1818

0 commit comments

Comments
 (0)