Skip to content

Commit

Permalink
Dont force repo (#125)
Browse files Browse the repository at this point in the history
* don't force REPO_ID

* dist

* add test

* fix test
  • Loading branch information
lezhumain authored Jun 21, 2024
1 parent 47208f7 commit 218efbd
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
64 changes: 63 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,68 @@ describe('action', () => {
expect(errorMock).not.toHaveBeenCalled()
}, 10000)

it('works with multiple repo ids', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'WORKSPACE_ID':
return '5e3018c2d1'
case 'REPO_ID':
return '500,501'
case 'FROM_PIPELINE':
return 'My from'
case 'TO_PIPELINE':
return 'My to'
case 'FROM_DATE':
return ''
case 'TO_DATE':
return ''
default:
return ''
}
})

main.init()

expect(getInputMock).toHaveBeenNthCalledWith(4, 'WORKSPACE_ID')
expect(getInputMock).toHaveBeenNthCalledWith(3, 'REPO_ID')
expect(getInputMock).toHaveBeenNthCalledWith(2, 'FROM_DATE')
expect(getInputMock).toHaveBeenNthCalledWith(1, 'TO_DATE')

const newConf: IMainConfig = MockMain.getTestConf(
main.config0 as IMainConfig
)
Object.assign(main.config0!, newConf)

Check warning on line 140 in __tests__/main.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Forbidden non-null assertion

Check warning on line 140 in __tests__/main.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Forbidden non-null assertion
const myFile: string | undefined = main.config0!.inputJsonFilename

Check warning on line 141 in __tests__/main.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Forbidden non-null assertion

Check warning on line 141 in __tests__/main.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Forbidden non-null assertion

// eslint-disable-next-line github/no-then
const hsaErr = await run().then(
() => false,
() => {
return true
}
)
expect(hsaErr).toBeFalsy()
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(1, `Got file ${myFile}`)

expect(setOutputMock).toHaveBeenNthCalledWith(
1,
'markdownContent',
expect.stringMatching(/.+/)
)
expect(errorMock).not.toHaveBeenCalled()

expect(JSON.stringify(main.config0?.includeRepos)).toEqual(
JSON.stringify([500, 501])
)
expect(JSON.stringify(newConf.includeRepos)).toEqual(
JSON.stringify([500, 501])
)
}, 10000)

it('bad workspace id', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string) => {
Expand Down Expand Up @@ -197,7 +259,7 @@ describe('action', () => {
// Verify that all the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
`Need to export WORKSPACE_ID (${WORKSPACE_ID}) and REPO_ID (${REPO_ID}) (${FROM_PIPELINE})`
`Need to export WORKSPACE_ID (${WORKSPACE_ID}) (${FROM_PIPELINE})`
)
expect(errorMock).not.toHaveBeenCalled()
}, 10000)
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inputs:
required: true
REPO_ID:
description: 'Your github repo ID'
required: true
required: false
FROM_PIPELINE:
description: 'Zenhub start pipeline'
required: true
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Main implements IMain {
const repoId = core.getInput('REPO_ID')
const workspaceId =
core.getInput('WORKSPACE_ID') || process.env.WORKSPACE_ID
if (!workspaceId || !repoId) {
const errMsg = `Need to export WORKSPACE_ID (${workspaceId || ''}) and REPO_ID (${repoId}) (${core.getInput('FROM_PIPELINE')})`
if (!workspaceId) {
const errMsg = `Need to export WORKSPACE_ID (${workspaceId || ''}) (${core.getInput('FROM_PIPELINE')})`
console.error(errMsg)
throw new Error(errMsg)
}
Expand Down

0 comments on commit 218efbd

Please sign in to comment.