Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to customize working directory #1493

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
change: remove path.sep, add unit tests, dist
Remove path.sep during comparison with repositoryPath
(did not take in account root folders)
Updated and added more unit tests
Updated dist/index.js
  • Loading branch information
accodev committed Apr 25, 2024
commit 8461fff5ebbd8df1ff4b43ab5de858024dd5acd7
1 change: 0 additions & 1 deletion __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
@@ -825,7 +825,6 @@ async function setup(testName: string): Promise<void> {
workflowOrganizationId: 123456,
setSafeDirectory: true,
githubServerUrl: githubServerUrl,
workingDirectory: undefined
}
}

21 changes: 21 additions & 0 deletions __test__/input-helper.test.ts
Original file line number Diff line number Diff line change
@@ -144,4 +144,25 @@ describe('input-helper tests', () => {
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.workflowOrganizationId).toBe(123456)
})

it('sets a different working directory', async() => {
inputs['working-directory'] = '/home/user/test'
inputs['path'] = 'path/to/repo'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.repositoryPath).toBe(path.resolve('/home/user/test/path/to/repo'))
})

it('sets a working directory on root', async() => {
inputs['working-directory'] = '/'
inputs['path'] = 'path/to/repo'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.repositoryPath).toBe(path.resolve('/path/to/repo'))
})

it('sets a working directory on root and repository path is set to empty', async() => {
inputs['working-directory'] = '/'
inputs['path'] = ''
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.repositoryPath).toBe(path.resolve('/'))
})
})
4 changes: 2 additions & 2 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
@@ -43,11 +43,11 @@ export async function getInputs(): Promise<IGitSourceSettings> {
)
if (
!(result.repositoryPath + path.sep).startsWith(
workingDirectory + path.sep
workingDirectory
)
) {
throw new Error(
`Repository path '${result.repositoryPath}' is not under '${workingDirectory}'`
`Repository path '${result.repositoryPath + path.sep}' is not under '${workingDirectory}'`
)
}