diff --git a/index.js b/index.js index b573057..ad093a9 100644 --- a/index.js +++ b/index.js @@ -911,6 +911,12 @@ class GithubScm extends Scm { return Buffer.from(file.data.content, file.data.encoding).toString(); } catch (err) { logger.error('Failed to getFile: ', err); + + if (err.status === 404) { + // Returns an empty file if there is no screwdriver.yaml + return ''; + } + throw err; } } diff --git a/test/index.test.js b/test/index.test.js index a4ea65c..b6c85ec 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1053,6 +1053,26 @@ jobs: }); }); + it('promises to get empty content when file is not found', () => { + const err = new Error('githubError'); + + err.status = 404; + + githubMock.repos.getContents.rejects(err); + + return scm.getFile(config) + .then((data) => { + assert.deepEqual(data, ''); + + assert.calledWith(githubMock.repos.getContents, { + owner: 'screwdriver-cd', + repo: 'models', + path: config.path, + ref: config.ref + }); + }); + }); + it('returns error when path is not a file', () => { const expectedErrorMessage = 'Path (screwdriver.yaml) does not point to file'; @@ -1076,7 +1096,7 @@ jobs: it('returns an error when github command fails', () => { const err = new Error('githubError'); - err.status = 404; + err.status = 403; githubMock.repos.getContents.rejects(err);