From 8312cf4d5c72d1115b78a528e5dd978059c94650 Mon Sep 17 00:00:00 2001 From: Bogdan Christescu Date: Thu, 16 Feb 2023 21:28:20 +0100 Subject: [PATCH 1/3] added test case for gitlab repository located in a subgroup Signed-off-by: Bogdan Christescu --- .../src/ReportIssue/IssueLink.test.tsx | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx index 5fff56ecb7..9a34fcf011 100644 --- a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx +++ b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.test.tsx @@ -26,7 +26,7 @@ import { import { IssueLink } from './IssueLink'; -const defaultProps = { +const defaultGithubProps = { repository: { type: 'github', name: 'backstage', @@ -40,14 +40,28 @@ const defaultProps = { }, }; +const defaultGitlabProps = { + repository: { + type: 'gitlab', + name: 'backstageSubgroup/backstage', + owner: 'backstage', + protocol: 'https', + resource: 'gitlab.com', + }, + template: { + title: 'Documentation feedback', + body: '## Documentation Feedback 📝', + }, +}; + describe('FeedbackLink', () => { const apiSpy = new MockAnalyticsApi(); - it('Should open new issue tab', () => { + it('Should open new Github issue tab', () => { render( wrapInTestApp( - + , ), ); @@ -55,19 +69,39 @@ describe('FeedbackLink', () => { const link = screen.getByText(/Open new Github issue/); expect(link).toBeInTheDocument(); expect(link).toHaveAttribute('target', '_blank'); - const encodedTitle = encodeURIComponent(defaultProps.template.title); - const encodedBody = encodeURIComponent(defaultProps.template.body); + const encodedTitle = encodeURIComponent(defaultGithubProps.template.title); + const encodedBody = encodeURIComponent(defaultGithubProps.template.body); expect(link).toHaveAttribute( 'href', `https://github.com/backstage/backstage/issues/new?title=${encodedTitle}&body=${encodedBody}`, ); }); + it('Should open new Gitlab issue tab', () => { + render( + wrapInTestApp( + + + , + ), + ); + + const link = screen.getByText(/Open new Gitlab issue/); + expect(link).toBeInTheDocument(); + expect(link).toHaveAttribute('target', '_blank'); + const encodedTitle = encodeURIComponent(defaultGithubProps.template.title); + const encodedBody = encodeURIComponent(defaultGithubProps.template.body); + expect(link).toHaveAttribute( + 'href', + `https://gitlab.com/backstage/backstageSubgroup/backstage/issues/new?issue[title]=${encodedTitle}&issue[description]=${encodedBody}`, + ); + }); + it('Should track click events', async () => { render( wrapInTestApp( - + , ), ); From 6afd63fcdbf9077790015daf6f2fae1ef739c885 Mon Sep 17 00:00:00 2001 From: Bogdan Christescu Date: Thu, 16 Feb 2023 21:30:01 +0100 Subject: [PATCH 2/3] encode the whole url instead of encoding name and owner separately Signed-off-by: Bogdan Christescu --- .../src/ReportIssue/IssueLink.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx index bb2de22350..eb16476fa6 100644 --- a/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx +++ b/plugins/techdocs-module-addons-contrib/src/ReportIssue/IssueLink.tsx @@ -59,14 +59,13 @@ const getUrl = (repository: Repository, template: ReportIssueTemplate) => { const encodedTitle = encodeURIComponent(title); const encodedBody = encodeURIComponent(body); const { protocol, resource, owner, name, type } = repository; - const encodedOwner = encodeURIComponent(owner); - const encodedName = encodeURIComponent(name); - const url = `${protocol}://${resource}/${encodedOwner}/${encodedName}`; + const url = `${protocol}://${resource}/${owner}/${name}`; + const encodedUrl = encodeURI(url); if (type === 'github') { - return `${url}/issues/new?title=${encodedTitle}&body=${encodedBody}`; + return `${encodedUrl}/issues/new?title=${encodedTitle}&body=${encodedBody}`; } - return `${url}/issues/new?issue[title]=${encodedTitle}&issue[description]=${encodedBody}`; + return `${encodedUrl}/issues/new?issue[title]=${encodedTitle}&issue[description]=${encodedBody}`; }; export const IssueLink = ({ template, repository }: IssueLinkProps) => { From 37cf85fb85cd85d328fa1f5d57dcfc285642a7bd Mon Sep 17 00:00:00 2001 From: Bogdan Christescu Date: Thu, 16 Feb 2023 21:56:14 +0100 Subject: [PATCH 3/3] changeset Signed-off-by: Bogdan Christescu --- .changeset/unlucky-sloths-explain.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/unlucky-sloths-explain.md diff --git a/.changeset/unlucky-sloths-explain.md b/.changeset/unlucky-sloths-explain.md new file mode 100644 index 0000000000..3d5f963a73 --- /dev/null +++ b/.changeset/unlucky-sloths-explain.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs-module-addons-contrib': patch +--- + +Fixed bug in IssueLink component where the URL was not generated properly when the repository was located inside a Gitlab subgroup