Skip to content

Commit ec3a7ce

Browse files
authored
set insteadOf url for org-id (#621)
1 parent fd47087 commit ec3a7ce

9 files changed

+293
-131
lines changed

__test__/git-auth-helper.test.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,17 @@ describe('git-auth-helper tests', () => {
518518
await authHelper.configureSubmoduleAuth()
519519

520520
// Assert
521-
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(3)
521+
expect(mockSubmoduleForeach).toHaveBeenCalledTimes(4)
522522
expect(mockSubmoduleForeach.mock.calls[0][0]).toMatch(
523523
/unset-all.*insteadOf/
524524
)
525525
expect(mockSubmoduleForeach.mock.calls[1][0]).toMatch(/http.*extraheader/)
526-
expect(mockSubmoduleForeach.mock.calls[2][0]).toMatch(/url.*insteadOf/)
526+
expect(mockSubmoduleForeach.mock.calls[2][0]).toMatch(
527+
/url.*insteadOf.*git@github.com:/
528+
)
529+
expect(mockSubmoduleForeach.mock.calls[3][0]).toMatch(
530+
/url.*insteadOf.*org-123456@github.com:/
531+
)
527532
}
528533
)
529534

@@ -770,7 +775,8 @@ async function setup(testName: string): Promise<void> {
770775
repositoryPath: '',
771776
sshKey: sshPath ? 'some ssh private key' : '',
772777
sshKnownHosts: '',
773-
sshStrict: true
778+
sshStrict: true,
779+
workflowOrganizationId: 123456
774780
}
775781
}
776782

__test__/input-helper.test.ts

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as assert from 'assert'
21
import * as core from '@actions/core'
32
import * as fsHelper from '../lib/fs-helper'
43
import * as github from '@actions/github'
54
import * as inputHelper from '../lib/input-helper'
65
import * as path from 'path'
6+
import * as workflowContextHelper from '../lib/workflow-context-helper'
77
import {IGitSourceSettings} from '../lib/git-source-settings'
88

99
const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
@@ -43,6 +43,11 @@ describe('input-helper tests', () => {
4343
.spyOn(fsHelper, 'directoryExistsSync')
4444
.mockImplementation((path: string) => path == gitHubWorkspace)
4545

46+
// Mock ./workflowContextHelper getOrganizationId()
47+
jest
48+
.spyOn(workflowContextHelper, 'getOrganizationId')
49+
.mockImplementation(() => Promise.resolve(123456))
50+
4651
// GitHub workspace
4752
process.env['GITHUB_WORKSPACE'] = gitHubWorkspace
4853
})
@@ -67,8 +72,8 @@ describe('input-helper tests', () => {
6772
jest.restoreAllMocks()
6873
})
6974

70-
it('sets defaults', () => {
71-
const settings: IGitSourceSettings = inputHelper.getInputs()
75+
it('sets defaults', async () => {
76+
const settings: IGitSourceSettings = await inputHelper.getInputs()
7277
expect(settings).toBeTruthy()
7378
expect(settings.authToken).toBeFalsy()
7479
expect(settings.clean).toBe(true)
@@ -82,11 +87,11 @@ describe('input-helper tests', () => {
8287
expect(settings.repositoryPath).toBe(gitHubWorkspace)
8388
})
8489

85-
it('qualifies ref', () => {
90+
it('qualifies ref', async () => {
8691
let originalRef = github.context.ref
8792
try {
8893
github.context.ref = 'some-unqualified-ref'
89-
const settings: IGitSourceSettings = inputHelper.getInputs()
94+
const settings: IGitSourceSettings = await inputHelper.getInputs()
9095
expect(settings).toBeTruthy()
9196
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
9297
expect(settings.ref).toBe('refs/heads/some-unqualified-ref')
@@ -95,32 +100,42 @@ describe('input-helper tests', () => {
95100
}
96101
})
97102

98-
it('requires qualified repo', () => {
103+
it('requires qualified repo', async () => {
99104
inputs.repository = 'some-unqualified-repo'
100-
assert.throws(() => {
101-
inputHelper.getInputs()
102-
}, /Invalid repository 'some-unqualified-repo'/)
105+
try {
106+
await inputHelper.getInputs()
107+
throw 'should not reach here'
108+
} catch (err) {
109+
expect(`(${(err as any).message}`).toMatch(
110+
"Invalid repository 'some-unqualified-repo'"
111+
)
112+
}
103113
})
104114

105-
it('roots path', () => {
115+
it('roots path', async () => {
106116
inputs.path = 'some-directory/some-subdirectory'
107-
const settings: IGitSourceSettings = inputHelper.getInputs()
117+
const settings: IGitSourceSettings = await inputHelper.getInputs()
108118
expect(settings.repositoryPath).toBe(
109119
path.join(gitHubWorkspace, 'some-directory', 'some-subdirectory')
110120
)
111121
})
112122

113-
it('sets ref to empty when explicit sha', () => {
123+
it('sets ref to empty when explicit sha', async () => {
114124
inputs.ref = '1111111111222222222233333333334444444444'
115-
const settings: IGitSourceSettings = inputHelper.getInputs()
125+
const settings: IGitSourceSettings = await inputHelper.getInputs()
116126
expect(settings.ref).toBeFalsy()
117127
expect(settings.commit).toBe('1111111111222222222233333333334444444444')
118128
})
119129

120-
it('sets sha to empty when explicit ref', () => {
130+
it('sets sha to empty when explicit ref', async () => {
121131
inputs.ref = 'refs/heads/some-other-ref'
122-
const settings: IGitSourceSettings = inputHelper.getInputs()
132+
const settings: IGitSourceSettings = await inputHelper.getInputs()
123133
expect(settings.ref).toBe('refs/heads/some-other-ref')
124134
expect(settings.commit).toBeFalsy()
125135
})
136+
137+
it('sets workflow organization ID', async () => {
138+
const settings: IGitSourceSettings = await inputHelper.getInputs()
139+
expect(settings.workflowOrganizationId).toBe(123456)
140+
})
126141
})

0 commit comments

Comments
 (0)