@@ -8,14 +8,15 @@ import * as sinon from "sinon";
8
8
import * as actionsUtil from "./actions-util" ;
9
9
import { computeAutomationID } from "./api-client" ;
10
10
import { EnvVar } from "./environment" ;
11
+ import * as gitUtils from "./git-utils" ;
11
12
import { setupActionsVars , setupTests } from "./testing-utils" ;
12
13
import { initializeEnvironment , withTmpDir } from "./util" ;
13
14
14
15
setupTests ( test ) ;
15
16
16
17
test ( "getRef() throws on the empty string" , async ( t ) => {
17
18
process . env [ "GITHUB_REF" ] = "" ;
18
- await t . throwsAsync ( actionsUtil . getRef ) ;
19
+ await t . throwsAsync ( gitUtils . getRef ) ;
19
20
} ) ;
20
21
21
22
test ( "getRef() returns merge PR ref if GITHUB_SHA still checked out" , async ( t ) => {
@@ -26,10 +27,10 @@ test("getRef() returns merge PR ref if GITHUB_SHA still checked out", async (t)
26
27
process . env [ "GITHUB_REF" ] = expectedRef ;
27
28
process . env [ "GITHUB_SHA" ] = currentSha ;
28
29
29
- const callback = sinon . stub ( actionsUtil , "getCommitOid" ) ;
30
+ const callback = sinon . stub ( gitUtils , "getCommitOid" ) ;
30
31
callback . withArgs ( "HEAD" ) . resolves ( currentSha ) ;
31
32
32
- const actualRef = await actionsUtil . getRef ( ) ;
33
+ const actualRef = await gitUtils . getRef ( ) ;
33
34
t . deepEqual ( actualRef , expectedRef ) ;
34
35
callback . restore ( ) ;
35
36
} ) ;
@@ -43,11 +44,11 @@ test("getRef() returns merge PR ref if GITHUB_REF still checked out but sha has
43
44
process . env [ "GITHUB_SHA" ] = "b" . repeat ( 40 ) ;
44
45
const sha = "a" . repeat ( 40 ) ;
45
46
46
- const callback = sinon . stub ( actionsUtil , "getCommitOid" ) ;
47
+ const callback = sinon . stub ( gitUtils , "getCommitOid" ) ;
47
48
callback . withArgs ( "refs/remotes/pull/1/merge" ) . resolves ( sha ) ;
48
49
callback . withArgs ( "HEAD" ) . resolves ( sha ) ;
49
50
50
- const actualRef = await actionsUtil . getRef ( ) ;
51
+ const actualRef = await gitUtils . getRef ( ) ;
51
52
t . deepEqual ( actualRef , expectedRef ) ;
52
53
callback . restore ( ) ;
53
54
} ) ;
@@ -59,11 +60,11 @@ test("getRef() returns head PR ref if GITHUB_REF no longer checked out", async (
59
60
process . env [ "GITHUB_REF" ] = "refs/pull/1/merge" ;
60
61
process . env [ "GITHUB_SHA" ] = "a" . repeat ( 40 ) ;
61
62
62
- const callback = sinon . stub ( actionsUtil , "getCommitOid" ) ;
63
+ const callback = sinon . stub ( gitUtils , "getCommitOid" ) ;
63
64
callback . withArgs ( tmpDir , "refs/pull/1/merge" ) . resolves ( "a" . repeat ( 40 ) ) ;
64
65
callback . withArgs ( tmpDir , "HEAD" ) . resolves ( "b" . repeat ( 40 ) ) ;
65
66
66
- const actualRef = await actionsUtil . getRef ( ) ;
67
+ const actualRef = await gitUtils . getRef ( ) ;
67
68
t . deepEqual ( actualRef , "refs/pull/1/head" ) ;
68
69
callback . restore ( ) ;
69
70
} ) ;
@@ -80,11 +81,11 @@ test("getRef() returns ref provided as an input and ignores current HEAD", async
80
81
process . env [ "GITHUB_REF" ] = "refs/pull/1/merge" ;
81
82
process . env [ "GITHUB_SHA" ] = "a" . repeat ( 40 ) ;
82
83
83
- const callback = sinon . stub ( actionsUtil , "getCommitOid" ) ;
84
+ const callback = sinon . stub ( gitUtils , "getCommitOid" ) ;
84
85
callback . withArgs ( "refs/pull/1/merge" ) . resolves ( "b" . repeat ( 40 ) ) ;
85
86
callback . withArgs ( "HEAD" ) . resolves ( "b" . repeat ( 40 ) ) ;
86
87
87
- const actualRef = await actionsUtil . getRef ( ) ;
88
+ const actualRef = await gitUtils . getRef ( ) ;
88
89
t . deepEqual ( actualRef , "refs/pull/2/merge" ) ;
89
90
callback . restore ( ) ;
90
91
getAdditionalInputStub . restore ( ) ;
@@ -100,7 +101,7 @@ test("getRef() returns CODE_SCANNING_REF as a fallback for GITHUB_REF", async (t
100
101
process . env [ "GITHUB_REF" ] = "" ;
101
102
process . env [ "GITHUB_SHA" ] = currentSha ;
102
103
103
- const actualRef = await actionsUtil . getRef ( ) ;
104
+ const actualRef = await gitUtils . getRef ( ) ;
104
105
t . deepEqual ( actualRef , expectedRef ) ;
105
106
} ) ;
106
107
} ) ;
@@ -114,7 +115,7 @@ test("getRef() returns GITHUB_REF over CODE_SCANNING_REF if both are provided",
114
115
process . env [ "GITHUB_REF" ] = expectedRef ;
115
116
process . env [ "GITHUB_SHA" ] = currentSha ;
116
117
117
- const actualRef = await actionsUtil . getRef ( ) ;
118
+ const actualRef = await gitUtils . getRef ( ) ;
118
119
t . deepEqual ( actualRef , expectedRef ) ;
119
120
} ) ;
120
121
} ) ;
@@ -127,7 +128,7 @@ test("getRef() throws an error if only `ref` is provided as an input", async (t)
127
128
128
129
await t . throwsAsync (
129
130
async ( ) => {
130
- await actionsUtil . getRef ( ) ;
131
+ await gitUtils . getRef ( ) ;
131
132
} ,
132
133
{
133
134
instanceOf : Error ,
@@ -148,7 +149,7 @@ test("getRef() throws an error if only `sha` is provided as an input", async (t)
148
149
149
150
await t . throwsAsync (
150
151
async ( ) => {
151
- await actionsUtil . getRef ( ) ;
152
+ await gitUtils . getRef ( ) ;
152
153
} ,
153
154
{
154
155
instanceOf : Error ,
@@ -219,7 +220,7 @@ test("initializeEnvironment", (t) => {
219
220
test ( "isAnalyzingDefaultBranch()" , async ( t ) => {
220
221
process . env [ "GITHUB_EVENT_NAME" ] = "push" ;
221
222
process . env [ "CODE_SCANNING_IS_ANALYZING_DEFAULT_BRANCH" ] = "true" ;
222
- t . deepEqual ( await actionsUtil . isAnalyzingDefaultBranch ( ) , true ) ;
223
+ t . deepEqual ( await gitUtils . isAnalyzingDefaultBranch ( ) , true ) ;
223
224
process . env [ "CODE_SCANNING_IS_ANALYZING_DEFAULT_BRANCH" ] = "false" ;
224
225
225
226
await withTmpDir ( async ( tmpDir ) => {
@@ -237,13 +238,13 @@ test("isAnalyzingDefaultBranch()", async (t) => {
237
238
238
239
process . env [ "GITHUB_REF" ] = "main" ;
239
240
process . env [ "GITHUB_SHA" ] = "1234" ;
240
- t . deepEqual ( await actionsUtil . isAnalyzingDefaultBranch ( ) , true ) ;
241
+ t . deepEqual ( await gitUtils . isAnalyzingDefaultBranch ( ) , true ) ;
241
242
242
243
process . env [ "GITHUB_REF" ] = "refs/heads/main" ;
243
- t . deepEqual ( await actionsUtil . isAnalyzingDefaultBranch ( ) , true ) ;
244
+ t . deepEqual ( await gitUtils . isAnalyzingDefaultBranch ( ) , true ) ;
244
245
245
246
process . env [ "GITHUB_REF" ] = "feature" ;
246
- t . deepEqual ( await actionsUtil . isAnalyzingDefaultBranch ( ) , false ) ;
247
+ t . deepEqual ( await gitUtils . isAnalyzingDefaultBranch ( ) , false ) ;
247
248
248
249
fs . writeFileSync (
249
250
envFile ,
@@ -253,7 +254,7 @@ test("isAnalyzingDefaultBranch()", async (t) => {
253
254
) ;
254
255
process . env [ "GITHUB_EVENT_NAME" ] = "schedule" ;
255
256
process . env [ "GITHUB_REF" ] = "refs/heads/main" ;
256
- t . deepEqual ( await actionsUtil . isAnalyzingDefaultBranch ( ) , true ) ;
257
+ t . deepEqual ( await gitUtils . isAnalyzingDefaultBranch ( ) , true ) ;
257
258
258
259
const getAdditionalInputStub = sinon . stub ( actionsUtil , "getOptionalInput" ) ;
259
260
getAdditionalInputStub
@@ -264,7 +265,7 @@ test("isAnalyzingDefaultBranch()", async (t) => {
264
265
. resolves ( "0000000000000000000000000000000000000000" ) ;
265
266
process . env [ "GITHUB_EVENT_NAME" ] = "schedule" ;
266
267
process . env [ "GITHUB_REF" ] = "refs/heads/main" ;
267
- t . deepEqual ( await actionsUtil . isAnalyzingDefaultBranch ( ) , false ) ;
268
+ t . deepEqual ( await gitUtils . isAnalyzingDefaultBranch ( ) , false ) ;
268
269
getAdditionalInputStub . restore ( ) ;
269
270
} ) ;
270
271
} ) ;
@@ -274,7 +275,7 @@ test("determineBaseBranchHeadCommitOid non-pullrequest", async (t) => {
274
275
275
276
process . env [ "GITHUB_EVENT_NAME" ] = "hucairz" ;
276
277
process . env [ "GITHUB_SHA" ] = "100912429fab4cb230e66ffb11e738ac5194e73a" ;
277
- const result = await actionsUtil . determineBaseBranchHeadCommitOid ( __dirname ) ;
278
+ const result = await gitUtils . determineBaseBranchHeadCommitOid ( __dirname ) ;
278
279
t . deepEqual ( result , undefined ) ;
279
280
t . deepEqual ( 0 , infoStub . callCount ) ;
280
281
@@ -288,7 +289,7 @@ test("determineBaseBranchHeadCommitOid not git repository", async (t) => {
288
289
process . env [ "GITHUB_SHA" ] = "100912429fab4cb230e66ffb11e738ac5194e73a" ;
289
290
290
291
await withTmpDir ( async ( tmpDir ) => {
291
- await actionsUtil . determineBaseBranchHeadCommitOid ( tmpDir ) ;
292
+ await gitUtils . determineBaseBranchHeadCommitOid ( tmpDir ) ;
292
293
} ) ;
293
294
294
295
t . deepEqual ( 1 , infoStub . callCount ) ;
@@ -306,7 +307,7 @@ test("determineBaseBranchHeadCommitOid other error", async (t) => {
306
307
307
308
process . env [ "GITHUB_EVENT_NAME" ] = "pull_request" ;
308
309
process . env [ "GITHUB_SHA" ] = "100912429fab4cb230e66ffb11e738ac5194e73a" ;
309
- const result = await actionsUtil . determineBaseBranchHeadCommitOid (
310
+ const result = await gitUtils . determineBaseBranchHeadCommitOid (
310
311
path . join ( __dirname , "../../i-dont-exist" ) ,
311
312
) ;
312
313
t . deepEqual ( result , undefined ) ;
@@ -326,39 +327,39 @@ test("determineBaseBranchHeadCommitOid other error", async (t) => {
326
327
} ) ;
327
328
328
329
test ( "decodeGitFilePath unquoted strings" , async ( t ) => {
329
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo" ) , "foo" ) ;
330
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo bar" ) , "foo bar" ) ;
331
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\\\bar" ) , "foo\\\\bar" ) ;
332
- t . deepEqual ( actionsUtil . decodeGitFilePath ( 'foo\\"bar' ) , 'foo\\"bar' ) ;
333
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\001bar" ) , "foo\\001bar" ) ;
334
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\abar" ) , "foo\\abar" ) ;
335
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\bbar" ) , "foo\\bbar" ) ;
336
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\fbar" ) , "foo\\fbar" ) ;
337
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\nbar" ) , "foo\\nbar" ) ;
338
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\rbar" ) , "foo\\rbar" ) ;
339
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\tbar" ) , "foo\\tbar" ) ;
340
- t . deepEqual ( actionsUtil . decodeGitFilePath ( "foo\\vbar" ) , "foo\\vbar" ) ;
330
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo" ) , "foo" ) ;
331
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo bar" ) , "foo bar" ) ;
332
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\\\bar" ) , "foo\\\\bar" ) ;
333
+ t . deepEqual ( gitUtils . decodeGitFilePath ( 'foo\\"bar' ) , 'foo\\"bar' ) ;
334
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\001bar" ) , "foo\\001bar" ) ;
335
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\abar" ) , "foo\\abar" ) ;
336
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\bbar" ) , "foo\\bbar" ) ;
337
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\fbar" ) , "foo\\fbar" ) ;
338
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\nbar" ) , "foo\\nbar" ) ;
339
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\rbar" ) , "foo\\rbar" ) ;
340
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\tbar" ) , "foo\\tbar" ) ;
341
+ t . deepEqual ( gitUtils . decodeGitFilePath ( "foo\\vbar" ) , "foo\\vbar" ) ;
341
342
t . deepEqual (
342
- actionsUtil . decodeGitFilePath ( "\\a\\b\\f\\n\\r\\t\\v" ) ,
343
+ gitUtils . decodeGitFilePath ( "\\a\\b\\f\\n\\r\\t\\v" ) ,
343
344
"\\a\\b\\f\\n\\r\\t\\v" ,
344
345
) ;
345
346
} ) ;
346
347
347
348
test ( "decodeGitFilePath quoted strings" , async ( t ) => {
348
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo"' ) , "foo" ) ;
349
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo bar"' ) , "foo bar" ) ;
350
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\\\bar"' ) , "foo\\bar" ) ;
351
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\"bar"' ) , 'foo"bar' ) ;
352
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\001bar"' ) , "foo\x01bar" ) ;
353
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\abar"' ) , "foo\x07bar" ) ;
354
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\bbar"' ) , "foo\bbar" ) ;
355
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\fbar"' ) , "foo\fbar" ) ;
356
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\nbar"' ) , "foo\nbar" ) ;
357
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\rbar"' ) , "foo\rbar" ) ;
358
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\tbar"' ) , "foo\tbar" ) ;
359
- t . deepEqual ( actionsUtil . decodeGitFilePath ( '"foo\\vbar"' ) , "foo\vbar" ) ;
349
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo"' ) , "foo" ) ;
350
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo bar"' ) , "foo bar" ) ;
351
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\\\bar"' ) , "foo\\bar" ) ;
352
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\"bar"' ) , 'foo"bar' ) ;
353
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\001bar"' ) , "foo\x01bar" ) ;
354
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\abar"' ) , "foo\x07bar" ) ;
355
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\bbar"' ) , "foo\bbar" ) ;
356
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\fbar"' ) , "foo\fbar" ) ;
357
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\nbar"' ) , "foo\nbar" ) ;
358
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\rbar"' ) , "foo\rbar" ) ;
359
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\tbar"' ) , "foo\tbar" ) ;
360
+ t . deepEqual ( gitUtils . decodeGitFilePath ( '"foo\\vbar"' ) , "foo\vbar" ) ;
360
361
t . deepEqual (
361
- actionsUtil . decodeGitFilePath ( '"\\a\\b\\f\\n\\r\\t\\v"' ) ,
362
+ gitUtils . decodeGitFilePath ( '"\\a\\b\\f\\n\\r\\t\\v"' ) ,
362
363
"\x07\b\f\n\r\t\v" ,
363
364
) ;
364
365
} ) ;
0 commit comments