11import { prechecks } from '../../src/functions/prechecks'
2+ import { COLORS } from '../../src/functions/colors'
23import * as isAllowed from '../../src/functions/allowlist'
34import * as validPermissions from '../../src/functions/valid-permissions'
45import * as core from '@actions/core'
56
67// Globals for testing
78const infoMock = jest . spyOn ( core , 'info' )
9+ const debugMock = jest . spyOn ( core , 'debug' )
810const defaultContextType = 'pull_request'
911
1012var 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-
303269test ( '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-
965889test ( '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'
0 commit comments