Skip to content

Commit 491b74b

Browse files
committed
feat(get-service-versions) Add success-if-not-found parameter to return empty list instead of raising error
1 parent af0e3ea commit 491b74b

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

get-service-versions/action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ inputs:
1919
description: GitHub token for destination repository
2020
required: true
2121
default: ${{ github.token }}
22+
success-if-not-found:
23+
description: If true, the action will not fail if the namespace is not found
24+
required: false
25+
default: 'true'
2226

2327
outputs:
2428
application-versions:

get-service-versions/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const main = async (): Promise<void> => {
88
sourceRepository: core.getInput('source-repository', { required: true }),
99
destinationRepository: core.getInput('destination-repository', { required: true }),
1010
destinationRepositoryToken: core.getInput('destination-repository-token', { required: true }),
11+
successIfNotFound: core.getBooleanInput('success-if-not-found') || true,
1112
})
1213
}
1314

get-service-versions/src/run.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Inputs = {
88
sourceRepository: string
99
destinationRepository: string
1010
destinationRepositoryToken: string
11+
successIfNotFound: boolean
1112
}
1213

1314
type Outputs = ApplicationVersion[]
@@ -20,9 +21,20 @@ export const run = async (inputs: Inputs): Promise<void> => {
2021
}
2122
}
2223

23-
const getServiceVersions = async (inputs: Inputs): Promise<Outputs> => {
24+
export const getServiceVersions = async (inputs: Inputs): Promise<Outputs> => {
2425
core.info(`Checking out the namespace branch`)
25-
const namespaceDirectory = await checkoutNamespaceBranch(inputs)
26+
let namespaceDirectory: string
27+
28+
try {
29+
namespaceDirectory = await checkoutNamespaceBranch(inputs)
30+
} catch (error) {
31+
if (inputs.successIfNotFound) {
32+
core.warning(`Namespace branch not found, returning empty list`)
33+
return []
34+
}
35+
36+
throw error
37+
}
2638
core.debug(`Namespace directory: ${namespaceDirectory}`)
2739

2840
const applicationFiles = await listApplicationFiles(namespaceDirectory)

get-service-versions/tests/aplication.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
import * as os from 'os'
22
import * as path from 'path'
33
import { promises as fs } from 'fs'
4+
import { getServiceVersions } from '../src/run.js'
45
import { listApplicationFiles, readApplication } from '../src/application.js'
56

67
const createEmptyDirectory = async () => await fs.mkdtemp(path.join(os.tmpdir(), 'bootstrap-pull-request-'))
78

9+
describe('getServiceVersions', () => {
10+
it('returnes empty list if successIfNotFound', async () => {
11+
const result = await getServiceVersions({
12+
overlay: 'overlay',
13+
namespace: 'namespace',
14+
sourceRepository: 'sourceRepository',
15+
destinationRepository: 'destinationRepository',
16+
destinationRepositoryToken: 'destinationRepositoryToken',
17+
successIfNotFound: true,
18+
})
19+
20+
expect(result).toStrictEqual([])
21+
})
22+
})
23+
824
describe('listApplicationFiles', () => {
925
it('lists up the application files, not other files', async () => {
1026
const namespaceDirectory = await createEmptyDirectory()

0 commit comments

Comments
 (0)