Skip to content

Commit

Permalink
fix(2094): return empty file when screwdriver.yaml is not found (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkisic authored Jun 8, 2020
1 parent 4bc29ac commit 5c6db91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
22 changes: 21 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);

Expand Down

0 comments on commit 5c6db91

Please sign in to comment.