Merge pull request #28656 from swnia/gitlabrepourlpickerfix

Gitlabrepourlpickerfix
This commit is contained in:
Ben Lambert
2025-02-04 10:43:00 +01:00
committed by GitHub
7 changed files with 19 additions and 22 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-scaffolder-backend-module-gitlab': patch
'@backstage/plugin-scaffolder': patch
---
Fixed bug of passing wrong value to `onChange` handler when using `GitLab` autocomplete
@@ -79,8 +79,8 @@ describe('handleAutocompleteRequest', () => {
mockClient.Users.showCurrentUser.mockResolvedValue({ id: 3 });
mockClient.Groups.allProjects.mockResolvedValue([
{ name: 'repo1', id: 1 },
{ name: 'repo2', id: 2 },
{ name: 'Repo 1', path: 'repo-1' },
{ name: 'Repo 2', path: 'repo-2' },
]);
const result = await handleAutocompleteRequest({
@@ -91,8 +91,8 @@ describe('handleAutocompleteRequest', () => {
expect(result).toEqual({
results: [
{ title: 'repo1', id: '1' },
{ title: 'repo2', id: '2' },
{ title: 'Repo 1', id: 'repo-1' },
{ title: 'Repo 2', id: 'repo-2' },
],
});
});
@@ -104,8 +104,8 @@ describe('handleAutocompleteRequest', () => {
mockClient.Users.showCurrentUser.mockResolvedValue({ id: 1 });
mockClient.Users.allProjects.mockResolvedValue([
{ name: 'repo1', id: 1 },
{ name: 'repo2', id: 2 },
{ name: 'Repo 1', path: 'repo-1' },
{ name: 'Repo 2', path: 'repo-2' },
]);
const result = await handleAutocompleteRequest({
@@ -116,8 +116,8 @@ describe('handleAutocompleteRequest', () => {
expect(result).toEqual({
results: [
{ title: 'repo1', id: '1' },
{ title: 'repo2', id: '2' },
{ title: 'Repo 1', id: 'repo-1' },
{ title: 'Repo 2', id: 'repo-2' },
],
});
});
@@ -97,7 +97,7 @@ export function createHandleAutocompleteRequest(options: {
return {
results: response.map(project => ({
title: project.name.trim(),
id: project.id.toString(),
id: project.path,
})),
};
}
@@ -244,8 +244,7 @@ export const RepoUrlPicker = (
onChange={repo =>
setState(prevState => ({
...prevState,
repoName: repo.name,
id: repo.id || '',
repoName: repo.id || repo.name,
}))
}
rawErrors={rawErrors}
@@ -25,7 +25,6 @@ export interface RepoUrlPickerState {
organization?: string;
workspace?: string;
project?: string;
id?: string;
availableRepos?: AvailableRepositories[];
}
@@ -53,10 +53,9 @@ describe('utils', () => {
organization: 'organization',
workspace: 'workspace',
project: 'backstage',
id: '1234',
}),
).toBe(
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage&id=1234',
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage',
);
});
});
@@ -65,7 +64,7 @@ describe('utils', () => {
it('should parse a complete string', () => {
expect(
parseRepoPickerUrl(
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage&id=1234',
'github.com?owner=owner&repo=backstage&organization=organization&workspace=workspace&project=backstage',
),
).toEqual({
host: 'github.com',
@@ -74,7 +73,6 @@ describe('utils', () => {
organization: 'organization',
workspace: 'workspace',
project: 'backstage',
id: '1234',
});
});
});
@@ -37,9 +37,6 @@ export function serializeRepoPickerUrl(data: RepoUrlPickerState) {
if (data.project) {
params.set('project', data.project);
}
if (data.id) {
params.set('id', data.id);
}
return `${data.host}?${params.toString()}`;
}
@@ -53,7 +50,6 @@ export function parseRepoPickerUrl(
let organization = '';
let workspace = '';
let project = '';
let id = '';
try {
if (url) {
@@ -64,10 +60,9 @@ export function parseRepoPickerUrl(
organization = parsed.searchParams.get('organization') || '';
workspace = parsed.searchParams.get('workspace') || '';
project = parsed.searchParams.get('project') || '';
id = parsed.searchParams.get('id') || '';
}
} catch {
/* ok */
}
return { host, owner, repoName, organization, workspace, project, id };
return { host, owner, repoName, organization, workspace, project };
}