From d0cd6a0dec97eff6587e786738388349e0a9e310 Mon Sep 17 00:00:00 2001 From: Severin Wischmann Date: Thu, 30 Jan 2025 13:36:11 +0100 Subject: [PATCH] Changes functionality in line with comment Based on [this comment](https://github.com/backstage/backstage/issues/28565#issuecomment-2624141216), the path is now the `id` Signed-off-by: Severin Wischmann --- .../src/autocomplete/autocomplete.test.ts | 16 ++++++++-------- .../src/autocomplete/autocomplete.ts | 4 +--- plugins/scaffolder-react/report.api.md | 1 - plugins/scaffolder-react/src/api/types.ts | 2 +- .../fields/RepoUrlPicker/GitlabRepoPicker.tsx | 2 +- .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 3 +-- .../src/components/fields/RepoUrlPicker/types.ts | 2 -- .../fields/RepoUrlPicker/utils.test.ts | 6 ++---- .../src/components/fields/RepoUrlPicker/utils.ts | 7 +------ 9 files changed, 15 insertions(+), 28 deletions(-) diff --git a/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.test.ts b/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.test.ts index a60d317077..a2e2f18ab2 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.test.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.test.ts @@ -79,8 +79,8 @@ describe('handleAutocompleteRequest', () => { mockClient.Users.showCurrentUser.mockResolvedValue({ id: 3 }); mockClient.Groups.allProjects.mockResolvedValue([ - { name: 'Repo 1', path: 'repo-1', id: 1 }, - { name: 'Repo 2', path: 'repo-2', 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: 'Repo 1', path: 'repo-1', id: '1' }, - { title: 'Repo 2', path: 'repo-2', 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' }, ], }); }); diff --git a/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.ts b/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.ts index d9f2f4351d..4eddd844e5 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/autocomplete/autocomplete.ts @@ -32,7 +32,6 @@ export function createHandleAutocompleteRequest(options: { }): Promise<{ results: { title?: string; - path?: string; id: string; }[]; }> { @@ -98,8 +97,7 @@ export function createHandleAutocompleteRequest(options: { return { results: response.map(project => ({ title: project.name.trim(), - path: project.path, - id: project.id.toString(), + id: project.path, })), }; } diff --git a/plugins/scaffolder-react/report.api.md b/plugins/scaffolder-react/report.api.md index d83d64d834..8a6b4739a4 100644 --- a/plugins/scaffolder-react/report.api.md +++ b/plugins/scaffolder-react/report.api.md @@ -215,7 +215,6 @@ export interface ScaffolderApi { }): Promise<{ results: { title?: string; - path?: string; id: string; }[]; }>; diff --git a/plugins/scaffolder-react/src/api/types.ts b/plugins/scaffolder-react/src/api/types.ts index 293a6a55e7..8e4d989a55 100644 --- a/plugins/scaffolder-react/src/api/types.ts +++ b/plugins/scaffolder-react/src/api/types.ts @@ -245,5 +245,5 @@ export interface ScaffolderApi { provider: string; resource: string; context?: Record; - }): Promise<{ results: { title?: string; path?: string; id: string }[] }>; + }): Promise<{ results: { title?: string; id: string }[] }>; } diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/GitlabRepoPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/GitlabRepoPicker.tsx index abd7071f44..d97c9431ee 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/GitlabRepoPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/GitlabRepoPicker.tsx @@ -98,7 +98,7 @@ export const GitlabRepoPicker = ( .then(({ results }) => { onChange({ availableRepos: results.map(r => { - return { name: r.title!, path: r.path, id: r.id }; + return { name: r.title!, id: r.id }; }), }); }) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index 41b00cc642..ef6654b60c 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -244,8 +244,7 @@ export const RepoUrlPicker = ( onChange={repo => setState(prevState => ({ ...prevState, - repoName: repo.path || repo.name, - id: repo.id || '', + repoName: repo.id || repo.name, })) } rawErrors={rawErrors} diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/types.ts b/plugins/scaffolder/src/components/fields/RepoUrlPicker/types.ts index e5c62aed08..74d45fa401 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/types.ts +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/types.ts @@ -15,7 +15,6 @@ */ export interface AvailableRepositories { name: string; - path?: string; id?: string; } @@ -26,7 +25,6 @@ export interface RepoUrlPickerState { organization?: string; workspace?: string; project?: string; - id?: string; availableRepos?: AvailableRepositories[]; } diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.test.ts b/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.test.ts index ce3c938e31..c90b357cf1 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.test.ts +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.test.ts @@ -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', }); }); }); diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.ts b/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.ts index 145a3e256f..408b87413b 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.ts +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/utils.ts @@ -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 }; }