feat: Update gitlab repo push error handling slightly when the commit action is not create
Signed-off-by: Peter Macdonald <peterm4c@pm.me>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-gitlab': patch
|
||||
---
|
||||
|
||||
If the commit action is not `create` log a more appropriate error message to the end user advising that the files they're trying to modify might not exist
|
||||
@@ -376,4 +376,75 @@ describe('createGitLabCommit', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
it('throws appropriate error for create action when commit fails', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
commitMessage: 'Create my new commit',
|
||||
branchName: 'some-branch',
|
||||
commitAction: 'create',
|
||||
};
|
||||
mockDir.setContent({
|
||||
[workspacePath]: {
|
||||
'foo.txt': 'Hello there!',
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = createMockActionContext({ input, workspacePath });
|
||||
mockGitlabClient.Commits.create.mockRejectedValue(
|
||||
new Error('Commit failed'),
|
||||
);
|
||||
|
||||
await expect(instance.handler(ctx)).rejects.toThrow(
|
||||
'Committing the changes to some-branch failed. Please check that none of the files created by the template already exists. Error: Commit failed',
|
||||
);
|
||||
});
|
||||
|
||||
it('throws appropriate error for update action when commit fails', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
commitMessage: 'Update my commit',
|
||||
branchName: 'some-branch',
|
||||
commitAction: 'update',
|
||||
};
|
||||
mockDir.setContent({
|
||||
[workspacePath]: {
|
||||
'foo.txt': 'Hello there!',
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = createMockActionContext({ input, workspacePath });
|
||||
mockGitlabClient.Commits.create.mockRejectedValue(
|
||||
new Error('Commit failed'),
|
||||
);
|
||||
|
||||
await expect(instance.handler(ctx)).rejects.toThrow(
|
||||
"Modifying the files in some-branch failed. Please verify that all files you're trying to modify exist in the repository. Error: Commit failed",
|
||||
);
|
||||
});
|
||||
|
||||
it('throws appropriate error for delete action when commit fails', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
commitMessage: 'Delete my commit',
|
||||
branchName: 'some-branch',
|
||||
commitAction: 'delete',
|
||||
};
|
||||
mockDir.setContent({
|
||||
[workspacePath]: {
|
||||
'foo.txt': 'Hello there!',
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = createMockActionContext({ input, workspacePath });
|
||||
mockGitlabClient.Commits.create.mockRejectedValue(
|
||||
new Error('Commit failed'),
|
||||
);
|
||||
|
||||
await expect(instance.handler(ctx)).rejects.toThrow(
|
||||
"Modifying the files in some-branch failed. Please verify that all files you're trying to modify exist in the repository. Error: Commit failed",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -203,6 +203,13 @@ export const createGitlabRepoPushAction = (options: {
|
||||
ctx.output('projectPath', repoID);
|
||||
ctx.output('commitHash', commitId);
|
||||
} catch (e) {
|
||||
if (commitAction !== 'create') {
|
||||
throw new InputError(
|
||||
`Modifying the files in ${branchName} failed. Please verify that all files you're trying to modify exist in the repository. ${getErrorMessage(
|
||||
e,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
throw new InputError(
|
||||
`Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${getErrorMessage(
|
||||
e,
|
||||
|
||||
Reference in New Issue
Block a user