Skip to content

Commit

Permalink
Fix jira URL prefixes to work with new jira boards (#217)
Browse files Browse the repository at this point in the history
* Fix jira URL prefixes to work with new jira boards

The JIRA board URLS changed for new JIRA boards. They now contain
optional trailing slashes and also allow further nested routes.
Examples:

* `/jira/software/projects/ABCD/boards/7`
* `/jira/software/projects/ABCD/boards/7/backlog`

Where before, only this URL was recognized:

* `/jira/software/projects/BCHP/boards/7/`
  • Loading branch information
tessi authored Apr 9, 2020
1 parent 12ba96a commit b122a83
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/common/adapters/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ function isJiraPage(loc, doc) {
return false;
}

const pathSuffixes = new RegExp('/(browse/[^/]+|projects/[^/]+/issues/[^/]+|secure/RapidBoard.jspa|jira/software/projects/[^/]+/boards/[^/]+/)$', 'g');
const pathSuffixes = new RegExp(
'/(browse/[^/]+|projects/[^/]+/issues/[^/]+|secure/RapidBoard.jspa|jira/software/projects/[^/]+/boards/.*)$',
'g',
);
function getPathPrefix(loc) {
return loc.pathname.replace(pathSuffixes, '');
}
Expand All @@ -31,9 +34,9 @@ function getSelectedIssueId(loc, prefix = '') {

const path = loc.pathname.substr(prefix.length); // strip path prefix

return (['/projects/:project/issues/:id', '/browse/:id']
return ['/projects/:project/issues/:id', '/browse/:id']
.map((pattern) => match(pattern, path).id)
.find(Boolean));
.find(Boolean);
}

function extractTicketInfo(response) {
Expand Down
58 changes: 51 additions & 7 deletions src/common/adapters/jira.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,72 @@ describe('jira adapter', () => {

it('uses the endpoints for the current host', async () => {
await scan(loc('my-subdomain.atlassian.net', `/browse/${key}`), doc);
expect(client).toHaveBeenCalledWith('https://my-subdomain.atlassian.net/rest/api/latest');
expect(client).toHaveBeenCalledWith(
'https://my-subdomain.atlassian.net/rest/api/latest',
);
expect(api.get).toHaveBeenCalled();
});

it('extracts tickets from the active sprints tab', async () => {
const result = await scan(loc('my-subdomain.atlassian.net', '/', `?selectedIssue=${key}`), doc);
const result = await scan(
loc('my-subdomain.atlassian.net', '/', `?selectedIssue=${key}`),
doc,
);
expect(api.get).toHaveBeenCalledWith(`issue/${key}`);
expect(result).toEqual([ticket]);
});

it('extracts tickets from the issues tab', async () => {
const result = await scan(loc('my-subdomain.atlassian.net', `/projects/TT/issues/${key}`, { filter: 'something' }), doc);
const result = await scan(
loc('my-subdomain.atlassian.net', `/projects/TT/issues/${key}`, {
filter: 'something',
}),
doc,
);
expect(api.get).toHaveBeenCalledWith(`issue/${key}`);
expect(result).toEqual([ticket]);
});

it('extracts tickets when browsing an issue', async () => {
const result = await scan(loc('my-subdomain.atlassian.net', `/browse/${key}`), doc);
const result = await scan(
loc('my-subdomain.atlassian.net', `/browse/${key}`),
doc,
);
expect(api.get).toHaveBeenCalledWith(`issue/${key}`);
expect(result).toEqual([ticket]);
});


it('extracts tickets from new generation software projects', async () => {
const result = await scan(loc('my-subdomain.atlassian.net', '/jira/software/projects/TT/boards/8/backlog', `?selectedIssue=${key}`), doc);
const result = await scan(
loc(
'my-subdomain.atlassian.net',
'/jira/software/projects/TT/boards/8',
`?selectedIssue=${key}`,
),
doc,
);
expect(client).toHaveBeenCalledWith(
'https://my-subdomain.atlassian.net/rest/api/latest',
);
expect(api.get).toHaveBeenCalledWith(`issue/${key}`);
expect(result).toEqual([ticket]);
});

it('extracts tickets from new generation software projects from the board-URL', async () => {
const result = await scan(
loc(
'my-subdomain.atlassian.net',
'/jira/software/projects/TT/boards/7/backlog',
`?selectedIssue=${key}`,
),
doc,
);
expect(client).toHaveBeenCalledWith(
'https://my-subdomain.atlassian.net/rest/api/latest',
);
expect(api.get).toHaveBeenCalledWith(`issue/${key}`);
expect(result).toEqual([ticket]);
});

it('extracts tickets on self-managed instances', async () => {
const result = await scan(loc('jira.local', `/browse/${key}`), doc);
Expand All @@ -92,7 +129,14 @@ describe('jira adapter', () => {

it('extracts tickets on self-managed instances (with path prefix)', async () => {
const results = await Promise.all([
scan(loc('jira.local', '/prefix/secure/RapidBoard.jspa', `?selectedIssue=${key}`), doc),
scan(
loc(
'jira.local',
'/prefix/secure/RapidBoard.jspa',
`?selectedIssue=${key}`,
),
doc,
),
scan(loc('jira.local', `/prefix/projects/TT/issues/${key}`), doc),
scan(loc('jira.local', `/prefix/browse/${key}`), doc),
]);
Expand Down

0 comments on commit b122a83

Please sign in to comment.