Skip to content

Commit d60b448

Browse files
authored
Merge pull request #5 from github/improvements
Improvements
2 parents 8c2d30c + b1549c3 commit d60b448

File tree

16 files changed

+488
-203
lines changed

16 files changed

+488
-203
lines changed

README.md

Lines changed: 285 additions & 2 deletions
Large diffs are not rendered by default.

__tests__/functions/post.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ test('skips the process of completing the run', async () => {
8383
return skipped[name]
8484
})
8585
expect(await post()).toBeUndefined()
86-
expect(infoMock).toHaveBeenCalledWith('skip_completing set, exiting')
86+
expect(infoMock).toHaveBeenCalledWith('skip_completing set, exiting')
8787
})
8888

8989
test('throws an error', async () => {

__tests__/functions/prechecks.test.js

Lines changed: 38 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {prechecks} from '../../src/functions/prechecks'
2+
import {COLORS} from '../../src/functions/colors'
23
import * as isAllowed from '../../src/functions/allowlist'
34
import * as validPermissions from '../../src/functions/valid-permissions'
45
import * as core from '@actions/core'
56

67
// Globals for testing
78
const infoMock = jest.spyOn(core, 'info')
9+
const debugMock = jest.spyOn(core, 'debug')
810
const defaultContextType = 'pull_request'
911

1012
var context
@@ -97,7 +99,7 @@ test('runs prechecks and finds that the IssueOps command is valid', async () =>
9799
octokit // octokit
98100
)
99101
).toStrictEqual({
100-
message: '✔️ PR is approved and all CI checks passed - OK',
102+
message: ' PR is approved and all CI checks passed',
101103
ref: 'test-ref',
102104
status: true,
103105
sha: 'abc123'
@@ -117,7 +119,7 @@ test('runs prechecks and finds that the IssueOps command is valid and exits earl
117119
octokit // octokit
118120
)
119121
).toStrictEqual({
120-
message: '✔️ operation requested on an issue - OK',
122+
message: `✅ operation requested on an ${COLORS.highlight}issue`,
121123
ref: null,
122124
status: true,
123125
sha: null
@@ -144,17 +146,19 @@ test('runs prechecks and finds that the IssueOps command is valid without define
144146
octokit
145147
)
146148
).toStrictEqual({
147-
message:
148-
'✔️ CI checks have not been defined but the PR has been approved - OK',
149+
message: '✅ CI checks have not been defined but the PR has been approved',
149150
status: true,
150151
ref: 'test-ref',
151152
sha: 'abc123'
152153
})
153-
expect(infoMock).toHaveBeenCalledWith(
154-
"Could not retrieve PR commit status: TypeError: Cannot read properties of undefined (reading 'nodes') - Handled: OK"
154+
expect(debugMock).toHaveBeenCalledWith(
155+
"could not retrieve PR commit status: TypeError: Cannot read properties of undefined (reading 'nodes') - Handled: OK"
155156
)
156-
expect(infoMock).toHaveBeenCalledWith(
157-
'Skipping commit status check and proceeding...'
157+
expect(debugMock).toHaveBeenCalledWith(
158+
'this repo may not have any CI checks defined'
159+
)
160+
expect(debugMock).toHaveBeenCalledWith(
161+
'skipping commit status check and proceeding...'
158162
)
159163
})
160164

@@ -198,20 +202,23 @@ test('runs prechecks and finds that reviews and CI checks have not been defined'
198202
)
199203
).toStrictEqual({
200204
message:
201-
'️ CI checks have not been defined and required reviewers have not been defined... proceeding - OK',
205+
'🎛️ CI checks have not been defined and required reviewers have not been defined',
202206
status: true,
203207

204208
ref: 'test-ref',
205209
sha: 'abc123'
206210
})
207-
expect(infoMock).toHaveBeenCalledWith(
208-
"Could not retrieve PR commit status: TypeError: Cannot read properties of undefined (reading 'nodes') - Handled: OK"
211+
expect(debugMock).toHaveBeenCalledWith(
212+
"could not retrieve PR commit status: TypeError: Cannot read properties of undefined (reading 'nodes') - Handled: OK"
209213
)
210-
expect(infoMock).toHaveBeenCalledWith(
211-
'Skipping commit status check and proceeding...'
214+
expect(debugMock).toHaveBeenCalledWith(
215+
'this repo may not have any CI checks defined'
216+
)
217+
expect(debugMock).toHaveBeenCalledWith(
218+
'skipping commit status check and proceeding...'
212219
)
213220
expect(infoMock).toHaveBeenCalledWith(
214-
'️ CI checks have not been defined and required reviewers have not been defined... proceeding - OK'
221+
'🎛️ CI checks have not been defined and required reviewers have not been defined'
215222
)
216223
})
217224

@@ -249,57 +256,16 @@ test('runs prechecks and finds CI checks pass but reviews are not defined', asyn
249256
octokit
250257
)
251258
).toStrictEqual({
252-
message:
253-
'⚠️ CI checks have been defined but required reviewers have not been defined... proceeding - OK',
259+
message: '✅ CI checks are passing and reviews are not defined',
254260
status: true,
255261
ref: 'test-ref',
256262
sha: 'abc123'
257263
})
258264
expect(infoMock).toHaveBeenLastCalledWith(
259-
'⚠️ CI checks have been defined but required reviewers have not been defined... proceeding - OK'
265+
' CI checks are passing and reviews are not defined'
260266
)
261267
})
262268

263-
test('runs prechecks and finds CI is passing and the PR has not been reviewed', async () => {
264-
octokit.graphql = jest.fn().mockReturnValue({
265-
repository: {
266-
pullRequest: {
267-
reviewDecision: 'REVIEW_REQUIRED',
268-
commits: {
269-
nodes: [
270-
{
271-
commit: {
272-
checkSuites: {
273-
totalCount: 1
274-
},
275-
statusCheckRollup: {
276-
state: 'SUCCESS'
277-
}
278-
}
279-
}
280-
]
281-
}
282-
}
283-
}
284-
})
285-
286-
expect(
287-
await prechecks(
288-
'123',
289-
true, // allow forks
290-
false, // skip_ci
291-
false, // skip_reviews
292-
false, // allow_drafts
293-
defaultContextType, // contextType
294-
context,
295-
octokit
296-
)
297-
).toStrictEqual({
298-
message: '⚠️ CI checks are passing but the PR has not been reviewed',
299-
status: false
300-
})
301-
})
302-
303269
test('runs prechecks and finds that the IssueOps command is valid for a branch operation and is from a forked repository', async () => {
304270
octokit.graphql = jest.fn().mockReturnValue({
305271
repository: {
@@ -347,7 +313,7 @@ test('runs prechecks and finds that the IssueOps command is valid for a branch o
347313
octokit
348314
)
349315
).toStrictEqual({
350-
message: '✔️ PR is approved and all CI checks passed - OK',
316+
message: ' PR is approved and all CI checks passed',
351317
status: true,
352318

353319
ref: 'abcde12345',
@@ -669,7 +635,8 @@ test('runs prechecks and finds CI is passing but the PR is missing an approval',
669635
octokit
670636
)
671637
).toStrictEqual({
672-
message: '⚠️ CI checks are passing but the PR has not been reviewed',
638+
message:
639+
'### ⚠️ Cannot proceed with operation\n\n> CI checks are passing but the PR has not been reviewed',
673640
status: false
674641
})
675642
})
@@ -789,7 +756,7 @@ test('runs prechecks and finds the skip_ci is set and reviews are not required',
789756
)
790757
).toStrictEqual({
791758
message:
792-
'⚠️ CI requirements have been disabled for this operation and required reviewers have not been defined... proceeding - OK',
759+
' CI requirements have been disabled for this operation and reviews are not required',
793760
status: true,
794761
ref: 'test-ref',
795762
sha: 'abc123'
@@ -900,7 +867,7 @@ test('runs prechecks and finds the PR is a DRAFT PR and drafts are allowed', asy
900867
octokit
901868
)
902869
).toStrictEqual({
903-
message: '✔️ PR is approved and all CI checks passed - OK',
870+
message: ' PR is approved and all CI checks passed',
904871
ref: 'test-ref',
905872
status: true,
906873
sha: 'abc123'
@@ -919,49 +886,6 @@ test('runs prechecks and fails with a non 200 permissionRes.status', async () =>
919886
})
920887
})
921888

922-
test('runs prechecks and finds that no CI checks exist and reviews are not defined', async () => {
923-
octokit.graphql = jest.fn().mockReturnValue({
924-
repository: {
925-
pullRequest: {
926-
reviewDecision: null,
927-
commits: {
928-
nodes: [
929-
{
930-
commit: {
931-
checkSuites: {
932-
totalCount: 0
933-
},
934-
statusCheckRollup: null
935-
}
936-
}
937-
]
938-
}
939-
}
940-
}
941-
})
942-
expect(
943-
await prechecks(
944-
'123',
945-
true,
946-
false,
947-
false,
948-
false,
949-
defaultContextType, // contextType
950-
context,
951-
octokit
952-
)
953-
).toStrictEqual({
954-
message:
955-
'⚠️ CI checks have not been defined and required reviewers have not been defined... proceeding - OK',
956-
status: true,
957-
ref: 'test-ref',
958-
sha: 'abc123'
959-
})
960-
expect(infoMock).toHaveBeenLastCalledWith(
961-
'⚠️ CI checks have not been defined and required reviewers have not been defined... proceeding - OK'
962-
)
963-
})
964-
965889
test('runs prechecks and finds that no CI checks exist but reviews are defined', async () => {
966890
octokit.graphql = jest.fn().mockReturnValue({
967891
repository: {
@@ -994,8 +918,7 @@ test('runs prechecks and finds that no CI checks exist but reviews are defined',
994918
octokit
995919
)
996920
).toStrictEqual({
997-
message:
998-
'✔️ CI checks have not been defined but the PR has been approved - OK',
921+
message: '✅ CI checks have not been defined but the PR has been approved',
999922
status: true,
1000923
ref: 'test-ref',
1001924
sha: 'abc123'
@@ -1036,7 +959,7 @@ test('runs prechecks and finds that skip_ci is set and the PR has been approved'
1036959
)
1037960
).toStrictEqual({
1038961
message:
1039-
'✔️ CI requirements have been disabled for this operation and the PR has been approved - OK',
962+
' CI requirements have been disabled for this operation and the PR has been approved',
1040963
status: true,
1041964
ref: 'test-ref',
1042965
sha: 'abc123'
@@ -1100,14 +1023,14 @@ test('runs prechecks and finds that skip_ci is set and no reviews are defined',
11001023
octokit
11011024
)
11021025
).toStrictEqual({
1103-
message: '✔️ CI and PR reviewers are not required for this operation - OK',
1026+
message: ' CI and PR reviewers are not required for this operation',
11041027
ref: 'test-ref',
11051028
status: true,
11061029
sha: 'abc123'
11071030
})
11081031

11091032
expect(infoMock).toHaveBeenCalledWith(
1110-
'✔️ CI and PR reviewers are not required for this operation - OK'
1033+
' CI and PR reviewers are not required for this operation'
11111034
)
11121035
})
11131036

@@ -1146,14 +1069,14 @@ test('runs prechecks and finds that skip_ci is set and skip_reviews is set', asy
11461069
octokit
11471070
)
11481071
).toStrictEqual({
1149-
message: '✔️ CI and PR reviewers are not required for this operation - OK',
1072+
message: ' CI and PR reviewers are not required for this operation',
11501073
ref: 'test-ref',
11511074
status: true,
11521075
sha: 'abc123'
11531076
})
11541077

11551078
expect(infoMock).toHaveBeenCalledWith(
1156-
'✔️ CI and PR reviewers are not required for this operation - OK'
1079+
' CI and PR reviewers are not required for this operation'
11571080
)
11581081
})
11591082

@@ -1192,8 +1115,7 @@ test('runs prechecks and finds that skip_ci is set', async () => {
11921115
octokit
11931116
)
11941117
).toStrictEqual({
1195-
message:
1196-
'⚠️ CI checks are not required for this operation but the PR has not been reviewed',
1118+
message: `### ⚠️ Cannot proceed with operation\n\n> CI checks are not required for this operation but the PR has not been reviewed`,
11971119
status: false
11981120
})
11991121
})
@@ -1273,7 +1195,7 @@ test('runs prechecks and finds that the PR is NOT reviewed and CI checks have be
12731195
octokit
12741196
)
12751197
).toStrictEqual({
1276-
message: `✔️ CI and PR reviewers are not required for this operation - OK`,
1198+
message: ` CI and PR reviewers are not required for this operation`,
12771199
status: true,
12781200
ref: 'test-ref',
12791201
sha: 'abc123'
@@ -1315,7 +1237,7 @@ test('runs prechecks and finds the PR is approved and ci is passing', async () =
13151237
octokit // octokit instance
13161238
)
13171239
).toStrictEqual({
1318-
message: '✔️ PR is approved and all CI checks passed - OK',
1240+
message: ' PR is approved and all CI checks passed',
13191241
status: true,
13201242
ref: 'test-ref',
13211243
sha: 'abc123'
@@ -1358,7 +1280,7 @@ test('runs prechecks and finds the PR is approved and ci is passing', async () =
13581280
)
13591281
).toStrictEqual({
13601282
message:
1361-
'✔️ CI checked passsed and required reviewers have been disabled for this operation - OK',
1283+
' CI checks are passing and reviews have been disabled for this operation',
13621284
status: true,
13631285
ref: 'test-ref',
13641286
sha: 'abc123'

__tests__/functions/trigger-check.test.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {triggerCheck} from '../../src/functions/trigger-check'
2+
import {COLORS} from '../../src/functions/colors'
23
import * as core from '@actions/core'
34

45
const setOutputMock = jest.spyOn(core, 'setOutput')
5-
const infoMock = jest.spyOn(core, 'info')
6+
const debugMock = jest.spyOn(core, 'debug')
67

78
beforeEach(() => {
89
jest.clearAllMocks()
910
jest.spyOn(core, 'setOutput').mockImplementation(() => {})
1011
jest.spyOn(core, 'saveState').mockImplementation(() => {})
11-
jest.spyOn(core, 'info').mockImplementation(() => {})
12+
jest.spyOn(core, 'debug').mockImplementation(() => {})
1213
})
1314

1415
test('checks a message and finds a standard trigger', async () => {
@@ -23,17 +24,11 @@ test('checks a message and does not find trigger', async () => {
2324
const trigger = '.test'
2425
expect(await triggerCheck(body, trigger)).toBe(false)
2526
expect(setOutputMock).toHaveBeenCalledWith('comment_body', '.bad')
26-
expect(infoMock).toHaveBeenCalledWith(
27-
'Trigger ".test" not found in the comment body'
27+
expect(debugMock).toHaveBeenCalledWith(
28+
`trigger ${COLORS.highlight}${trigger}${COLORS.reset} not found in the comment body`
2829
)
2930
})
3031

31-
test('checks a message and finds a global trigger', async () => {
32-
const body = 'I want to .test'
33-
const trigger = '.test'
34-
expect(await triggerCheck(body, trigger)).toBe(false)
35-
})
36-
3732
test('checks a message and finds a trigger with extra text', async () => {
3833
const trigger = '.test'
3934
expect(await triggerCheck('.test dev something', trigger)).toBe(true)
@@ -61,15 +56,15 @@ test('checks a message and finds a trigger with extra text', async () => {
6156
)
6257
})
6358

64-
test('checks a message and does not find global trigger', async () => {
59+
test('checks a message and does not find a trigger', async () => {
6560
const body = 'I want to .ping a website'
6661
const trigger = '.test'
6762
expect(await triggerCheck(body, trigger)).toBe(false)
6863
expect(setOutputMock).toHaveBeenCalledWith(
6964
'comment_body',
7065
'I want to .ping a website'
7166
)
72-
expect(infoMock).toHaveBeenCalledWith(
73-
'Trigger ".test" not found in the comment body'
67+
expect(debugMock).toHaveBeenCalledWith(
68+
`trigger ${COLORS.highlight}${trigger}${COLORS.reset} not found in the comment body`
7469
)
7570
})

0 commit comments

Comments
 (0)