Fixed validation for RepoUrlPicker
Signed-off-by: Veith M. Bürgerhoff <veith.buergerhoff@gmail.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-azure': patch
|
||||
'@backstage/plugin-scaffolder-node': patch
|
||||
'@backstage/plugin-scaffolder': patch
|
||||
---
|
||||
|
||||
Fixed a bug where the RepoUrlPicker would still require the 'owner' field after the usage was changed to 'repo'.
|
||||
@@ -29,7 +29,7 @@ export const examples: TemplateExample[] = [
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'dev.azure.com?organization=organization&owner=project&repo=repo',
|
||||
'dev.azure.com?organization=organization&project=project&repo=repo',
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -45,7 +45,7 @@ export const examples: TemplateExample[] = [
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'dev.azure.com?organization=organization&owner=project&repo=repo',
|
||||
'dev.azure.com?organization=organization&project=project&repo=repo',
|
||||
description: 'Initialize a git repository',
|
||||
},
|
||||
},
|
||||
@@ -63,7 +63,7 @@ export const examples: TemplateExample[] = [
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'dev.azure.com?organization=organization&owner=project&repo=repo',
|
||||
'dev.azure.com?organization=organization&project=project&repo=repo',
|
||||
defaultBranch: 'main',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -55,7 +55,9 @@ describe('publish:azure', () => {
|
||||
const action = createPublishAzureAction({ integrations, config });
|
||||
|
||||
const mockContext = createMockActionContext({
|
||||
input: { repoUrl: 'dev.azure.com?repo=repo&owner=owner&organization=org' },
|
||||
input: {
|
||||
repoUrl: 'dev.azure.com?repo=repo&project=project&organization=org',
|
||||
},
|
||||
});
|
||||
|
||||
const mockGitClient = {
|
||||
@@ -77,19 +79,19 @@ describe('publish:azure', () => {
|
||||
...mockContext,
|
||||
input: { repoUrl: 'dev.azure.com?repo=bob' },
|
||||
}),
|
||||
).rejects.toThrow(/missing owner/);
|
||||
).rejects.toThrow(/missing project/);
|
||||
|
||||
await expect(
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: { repoUrl: 'dev.azure.com?owner=owner' },
|
||||
input: { repoUrl: 'dev.azure.com?project=project' },
|
||||
}),
|
||||
).rejects.toThrow(/missing repo/);
|
||||
|
||||
await expect(
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: { repoUrl: 'dev.azure.com?owner=owner&repo=repo' },
|
||||
input: { repoUrl: 'dev.azure.com?project=project&repo=repo' },
|
||||
}),
|
||||
).rejects.toThrow(/missing organization/);
|
||||
});
|
||||
@@ -98,7 +100,9 @@ describe('publish:azure', () => {
|
||||
await expect(
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: { repoUrl: 'azure.com?repo=bob&owner=owner&organization=org' },
|
||||
input: {
|
||||
repoUrl: 'azure.com?repo=bob&project=project&organization=org',
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/No matching integration configuration/);
|
||||
});
|
||||
@@ -109,7 +113,7 @@ describe('publish:azure', () => {
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl:
|
||||
'myazurehostnotoken.com?repo=bob&owner=owner&organization=org',
|
||||
'myazurehostnotoken.com?repo=bob&project=project&organization=org',
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(
|
||||
@@ -122,7 +126,7 @@ describe('publish:azure', () => {
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org',
|
||||
repoUrl: 'dev.azure.com?repo=bob&project=project&organization=org',
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/Unable to create the repository/);
|
||||
@@ -138,7 +142,8 @@ describe('publish:azure', () => {
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'myazurehostnotoken.com?repo=bob&owner=owner&organization=org',
|
||||
repoUrl:
|
||||
'myazurehostnotoken.com?repo=bob&project=project&organization=org',
|
||||
token: 'lols',
|
||||
},
|
||||
});
|
||||
@@ -152,7 +157,7 @@ describe('publish:azure', () => {
|
||||
{
|
||||
name: 'bob',
|
||||
},
|
||||
'owner',
|
||||
'project',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -166,7 +171,7 @@ describe('publish:azure', () => {
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org',
|
||||
repoUrl: 'dev.azure.com?repo=bob&project=project&organization=org',
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/No remote URL returned/);
|
||||
@@ -182,7 +187,7 @@ describe('publish:azure', () => {
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org',
|
||||
repoUrl: 'dev.azure.com?repo=bob&project=project&organization=org',
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/No Id returned/);
|
||||
@@ -198,7 +203,7 @@ describe('publish:azure', () => {
|
||||
action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org',
|
||||
repoUrl: 'dev.azure.com?repo=bob&project=project&organization=org',
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/No web URL returned/);
|
||||
@@ -214,7 +219,7 @@ describe('publish:azure', () => {
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org',
|
||||
repoUrl: 'dev.azure.com?repo=bob&project=project&organization=org',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -227,7 +232,7 @@ describe('publish:azure', () => {
|
||||
{
|
||||
name: 'bob',
|
||||
},
|
||||
'owner',
|
||||
'project',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ export function createPublishAzureAction(options: {
|
||||
gitAuthorEmail,
|
||||
} = ctx.input;
|
||||
|
||||
const { owner, repo, host, organization } = parseRepoUrl(
|
||||
const { project, repo, host, organization } = parseRepoUrl(
|
||||
repoUrl,
|
||||
integrations,
|
||||
);
|
||||
@@ -166,11 +166,14 @@ export function createPublishAzureAction(options: {
|
||||
const webApi = new WebApi(url, authHandler);
|
||||
const client = await webApi.getGitApi();
|
||||
const createOptions: GitRepositoryCreateOptions = { name: repo };
|
||||
const returnedRepo = await client.createRepository(createOptions, owner);
|
||||
const returnedRepo = await client.createRepository(
|
||||
createOptions,
|
||||
project,
|
||||
);
|
||||
|
||||
if (!returnedRepo) {
|
||||
throw new InputError(
|
||||
`Unable to create the repository with Organization ${organization}, Project ${owner} and Repo ${repo}.
|
||||
`Unable to create the repository with Organization ${organization}, Project ${project} and Repo ${repo}.
|
||||
Please make sure that both the Org and Project are typed corrected and exist.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,10 @@ export const parseRepoUrl = (
|
||||
checkRequiredParams(parsed, 'project', 'repo');
|
||||
break;
|
||||
}
|
||||
case 'azure': {
|
||||
checkRequiredParams(parsed, 'project', 'repo');
|
||||
break;
|
||||
}
|
||||
case 'gitlab': {
|
||||
// project is the projectID, and if defined, owner and repo won't be needed.
|
||||
if (!project) {
|
||||
|
||||
@@ -54,7 +54,14 @@ export const repoPickerValidation = (
|
||||
);
|
||||
}
|
||||
}
|
||||
// For anything other than bitbucket and gerrit
|
||||
if (integrationApi?.byHost(host)?.type === 'azure') {
|
||||
if (!searchParams.get('project')) {
|
||||
validation.addError(
|
||||
'Incomplete repository location provided, project not provided',
|
||||
);
|
||||
}
|
||||
}
|
||||
// For anything other than bitbucket, azure, and gerrit
|
||||
else if (integrationApi?.byHost(host)?.type !== 'gerrit') {
|
||||
if (!searchParams.get('owner')) {
|
||||
validation.addError(
|
||||
|
||||
Reference in New Issue
Block a user