Skip to content
Snippets Groups Projects
Commit 47305e60 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix(github): catch 404 when committing files

parent b5965c62
No related branches found
No related tags found
No related merge requests found
...@@ -275,6 +275,7 @@ class Storage { ...@@ -275,6 +275,7 @@ class Storage {
logger.debug( logger.debug(
`commitFilesToBranch('${branchName}', files, message, '${parentBranch})'` `commitFilesToBranch('${branchName}', files, message, '${parentBranch})'`
); );
try {
delete branchFiles[branchName]; delete branchFiles[branchName];
const parentCommit = await getBranchCommit(parentBranch); const parentCommit = await getBranchCommit(parentBranch);
const parentTree = await getCommitTree(parentCommit); const parentTree = await getCommitTree(parentCommit);
...@@ -291,7 +292,6 @@ class Storage { ...@@ -291,7 +292,6 @@ class Storage {
const tree = await createTree(parentTree, fileBlobs); const tree = await createTree(parentTree, fileBlobs);
const commit = await createCommit(parentCommit, tree, message); const commit = await createCommit(parentCommit, tree, message);
const isBranchExisting = await branchExists(branchName); const isBranchExisting = await branchExists(branchName);
try {
if (isBranchExisting) { if (isBranchExisting) {
await updateBranch(branchName, commit); await updateBranch(branchName, commit);
logger.debug({ branch: branchName }, 'Branch updated'); logger.debug({ branch: branchName }, 'Branch updated');
...@@ -305,14 +305,9 @@ class Storage { ...@@ -305,14 +305,9 @@ class Storage {
} }
return 'created'; return 'created';
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
logger.debug({ if (err.statusCode === 404) {
files: files.filter( throw new Error('repository-changed');
file => }
!file.name.endsWith('package-lock.json') &&
!file.name.endsWith('npm-shrinkwrap.json') &&
!file.name.endsWith('yarn.lock')
),
});
throw err; throw err;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment