forked from AxisCommunications/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional URL path to Jira links (AxisCommunications#113)
* Added url pathname as part of Jira URL * Add changeset * Add tests * Remove v2 from split function --------- Co-authored-by: Frida Jacobsson <[email protected]>
- Loading branch information
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@axis-backstage/plugin-jira-dashboard': patch | ||
--- | ||
|
||
Added the url pathname as part of the base URL for all links to Jira. This because Jira Server have additional path in the Jira base URl and links were broken. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { getJiraBaseUrl, getProjectUrl, getIssueUrl } from './lib'; | ||
|
||
const mockedProject = { | ||
name: 'Backstage', | ||
key: 'BS', | ||
description: 'This is our Backstage project', | ||
avatarUrls: { | ||
'48x48': 'https://api.dicebear.com/6.x/open-peeps/svg?seed=Duane', | ||
}, | ||
projectTypeKey: 'Software', | ||
projectCategory: { | ||
name: 'Software Portals', | ||
}, | ||
lead: { | ||
key: 'fridaja', | ||
displayName: 'Frida Jacobsson', | ||
}, | ||
self: 'https://jira.com/rest/api/2/project/123', | ||
}; | ||
|
||
describe('getJiraBaseUrl', () => { | ||
it('should return the base URL of a Jira instance', () => { | ||
const baseUrl = 'https://jira.com/rest/api/2/project/123'; | ||
const expected = 'https://jira.com'; | ||
expect(getJiraBaseUrl(baseUrl)).toEqual(expected); | ||
}); | ||
|
||
it('should handle URLs with additional paths', () => { | ||
const baseUrl = 'https://jira.com/my-path/rest/api/2/project/123'; | ||
const expected = 'https://jira.com/my-path'; | ||
expect(getJiraBaseUrl(baseUrl)).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('getProjectUrl', () => { | ||
it('should return the URL to a Jira project', () => { | ||
const expected = 'https://jira.com/browse/BS'; | ||
expect(getProjectUrl(mockedProject)).toEqual(expected); | ||
}); | ||
it('should handle URLs with additional paths', () => { | ||
const expected = 'https://jira.com/my-path/browse/BS'; | ||
mockedProject.self = 'https://jira.com/my-path/rest/api/2/project/123'; | ||
expect(getProjectUrl(mockedProject)).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('getIssueUrl', () => { | ||
it('should return the URL to an issue', () => { | ||
const issueUrl = 'https://jira.com/rest/api/2/issue/123'; | ||
const issueKey = 'PROJ-123'; | ||
const expected = 'https://jira.com/browse/PROJ-123'; | ||
expect(getIssueUrl(issueUrl, issueKey)).toEqual(expected); | ||
}); | ||
it('should handle URLs with additional paths', () => { | ||
const issueUrl = 'https://jira.com/my-path/rest/api/2/issue/123'; | ||
const issueKey = 'PROJ-123'; | ||
const expected = 'https://jira.com/my-path/browse/PROJ-123'; | ||
expect(getIssueUrl(issueUrl, issueKey)).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import { Project } from '@axis-backstage/plugin-jira-dashboard-common'; | ||
|
||
export const getJiraBaseUrl = (a: string) => { | ||
const url = new URL(a); | ||
const path = url.pathname.split('/rest/api')[0]; | ||
return url.origin + path; | ||
}; | ||
|
||
/** | ||
* Get the URL to a Jira project. | ||
*/ | ||
export const getProjectUrl = (project: Project) => { | ||
const url = new URL(project.self); | ||
return `https://${url.host}/browse/${project.key}`; | ||
return `${getJiraBaseUrl(project.self)}/browse/${project.key}`; | ||
}; | ||
|
||
/** | ||
* Get the URL to a issue. | ||
*/ | ||
export const getIssueUrl = (issueUrl: string, issueKey: string) => { | ||
const url = new URL(issueUrl); | ||
return `https://${url.host}/browse/${issueKey}`; | ||
return `${getJiraBaseUrl(issueUrl)}/browse/${issueKey}`; | ||
}; |