feat(scaffolder): allow to create Gerrit project using default owner
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': patch
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Allow to create Gerrit project using default owner
|
||||
@@ -62,13 +62,6 @@ describe('publish:gerrit', () => {
|
||||
});
|
||||
|
||||
it('should throw an error when the repoUrl is not well formed', async () => {
|
||||
await expect(
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: { repoUrl: 'gerrithost.org?workspace=w&repo=repo', description },
|
||||
}),
|
||||
).rejects.toThrow(/missing owner/);
|
||||
|
||||
await expect(
|
||||
action.handler({
|
||||
...mockContext,
|
||||
@@ -188,6 +181,56 @@ describe('publish:gerrit', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('can correctly create a new project without specifying owner', async () => {
|
||||
expect.assertions(5);
|
||||
server.use(
|
||||
rest.put('https://gerrithost.org/a/projects/repo', (req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe(
|
||||
'Basic Z2Vycml0dXNlcjp1c2VydG9rZW4=',
|
||||
);
|
||||
expect(req.body).toEqual({
|
||||
create_empty_commit: false,
|
||||
owners: [],
|
||||
description,
|
||||
parent: 'workspace',
|
||||
});
|
||||
return res(
|
||||
ctx.status(201),
|
||||
ctx.set('Content-Type', 'application/json'),
|
||||
ctx.json({}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
repoUrl: 'gerrithost.org?workspace=workspace&repo=repo',
|
||||
sourcePath: 'repository/',
|
||||
},
|
||||
});
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: `${mockContext.workspacePath}/repository/`,
|
||||
remoteUrl: 'https://gerrithost.org/a/repo',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'gerrituser', password: 'usertoken' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: expect.stringContaining('initial commit\n\nChange-Id:'),
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
|
||||
expect(mockContext.output).toHaveBeenCalledWith(
|
||||
'remoteUrl',
|
||||
'https://gerrithost.org/a/repo',
|
||||
);
|
||||
expect(mockContext.output).toHaveBeenCalledWith(
|
||||
'repoContentsUrl',
|
||||
'https://gerrithost.org/repo/+/refs/heads/master',
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ const createGerritProject = async (
|
||||
options: {
|
||||
projectName: string;
|
||||
parent: string;
|
||||
owner: string;
|
||||
owner?: string;
|
||||
description: string;
|
||||
},
|
||||
): Promise<void> => {
|
||||
@@ -42,7 +42,7 @@ const createGerritProject = async (
|
||||
body: JSON.stringify({
|
||||
parent,
|
||||
description,
|
||||
owners: [owner],
|
||||
owners: owner ? [owner] : [],
|
||||
create_empty_commit: false,
|
||||
}),
|
||||
headers: {
|
||||
@@ -174,11 +174,6 @@ export function createPublishGerritAction(options: {
|
||||
);
|
||||
}
|
||||
|
||||
if (!owner) {
|
||||
throw new InputError(
|
||||
`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing owner`,
|
||||
);
|
||||
}
|
||||
if (!workspace) {
|
||||
throw new InputError(
|
||||
`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`,
|
||||
|
||||
@@ -85,7 +85,7 @@ export const parseRepoUrl = (
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!owner) {
|
||||
if (!owner && type !== 'gerrit') {
|
||||
throw new InputError(
|
||||
`Invalid repo URL passed to publisher: ${repoUrl}, missing owner`,
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ import React from 'react';
|
||||
import { GerritRepoPicker } from './GerritRepoPicker';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
describe('BitbucketRepoPicker', () => {
|
||||
describe('GerritRepoPicker', () => {
|
||||
describe('owner input field', () => {
|
||||
it('calls onChange when the owner input changes', () => {
|
||||
const onChange = jest.fn();
|
||||
|
||||
@@ -29,18 +29,14 @@ export const GerritRepoPicker = (props: {
|
||||
const { workspace, owner } = state;
|
||||
return (
|
||||
<>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !workspace}
|
||||
>
|
||||
<FormControl margin="normal" error={rawErrors?.length > 0 && !workspace}>
|
||||
<InputLabel htmlFor="ownerInput">Owner</InputLabel>
|
||||
<Input
|
||||
id="ownerInput"
|
||||
onChange={e => onChange({ owner: e.target.value })}
|
||||
value={owner}
|
||||
/>
|
||||
<FormHelperText>The owner of the project</FormHelperText>
|
||||
<FormHelperText>The owner of the project (optional)</FormHelperText>
|
||||
</FormControl>
|
||||
<FormControl
|
||||
margin="normal"
|
||||
|
||||
@@ -54,8 +54,8 @@ export const repoPickerValidation = (
|
||||
);
|
||||
}
|
||||
}
|
||||
// For anything other than bitbucket
|
||||
else {
|
||||
// For anything other than bitbucket and gerrit
|
||||
else if (integrationApi?.byHost(host)?.type !== 'gerrit') {
|
||||
if (!searchParams.get('owner')) {
|
||||
validation.addError(
|
||||
'Incomplete repository location provided, owner not provided',
|
||||
|
||||
Reference in New Issue
Block a user