Skip to content

Commit

Permalink
fix: allow viewing selected for development tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
XerxesDGreat authored and tagoro9 committed Aug 24, 2023
1 parent 31c3f62 commit 58b6437
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
50 changes: 32 additions & 18 deletions src/issue-tracker/jira/Jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,20 @@ export class Jira implements Tracker {

public getCurrentUserOpenIssues(): Observable<Issue[]> {
return zip(this.getCurrentUser(), this.getStatuses()).pipe(
switchMap(([user, status]: [User, Partial<Record<IssueStatus, JiraIssueStatus>>]) => {
switchMap(([user, status]: [User, Partial<Record<IssueStatus, JiraIssueStatus[]>>]) => {
const qs = {
expand: 'transitions, renderedFields',
jql: `assignee=${user.accountId} AND status IN (${[
IssueStatus.BACKLOG,
IssueStatus.SELECTED_FOR_DEVELOPMENT,
]
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.flatMap((s) => (status[s] ? status[s]!.map((t) => "'" + t.name + "'") : undefined))
.filter((s) => s !== undefined)
.join(',')}) ORDER BY CREATED DESC`,
};
return this.client.get<{ issues: JiraIssue[] }>(`/search`, {
qs: {
expand: 'transitions, renderedFields',
jql: `assignee=${user.accountId} AND status IN (${[
IssueStatus.BACKLOG,
IssueStatus.SELECTED_FOR_DEVELOPMENT,
]
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.map((s) => (status[s] ? "'" + status[s]!.name + "'" : undefined))
.filter((s) => s !== undefined)
.join(',')}) ORDER BY CREATED DESC`,
},
qs: qs,
});
}),
map(prop('body')),
Expand Down Expand Up @@ -375,16 +376,29 @@ export class Jira implements Tracker {
);
}

// TODO This should be cacheable, but cacheable does not understand observables yer
private getStatuses(): Observable<Partial<Record<IssueStatus, JiraIssueStatus>>> {
/**
* Get all the statuses from Jira for any project and then map then to the internal fotingo statuses. Ensure no duplicate statuses are returned
* for each internal status
* @private
*/
// TODO This should be cacheable, but cacheable does not understand observables yet
private getStatuses(): Observable<Partial<Record<IssueStatus, JiraIssueStatus[]>>> {
return this.client.get<JiraIssueStatus[]>('/status').pipe(
map(prop('body')),
map((status: JiraIssueStatus[]) => {
return Object.fromEntries(
Object.entries(IssueStatus).map(([key, value]) => [
key,
status.find((t) => this.config.status[value].test(t.name)),
]),
Object.entries(IssueStatus).map(([key, value]) => {
// Get statuses that match the internal status regex
const matchedStatues = status.filter((t) => this.config.status[value].test(t.name));
return [
key,
// Ensure only one status per name is returned
matchedStatues.filter(
(status, index, collection) =>
collection.findIndex((t) => t.name === status.name) === index,
),
];
}),
);
}),
);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface Issue {
id: string;
key: string;
};
raw?: unknown;
sanitizedSummary: string;
summary: string;
type: IssueType;
Expand Down
19 changes: 19 additions & 0 deletions test/issue-tracker/Jira.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,23 @@ describe('jira', () => {
});
});
});

describe('getCurrentUserOpenIssues', () => {
it('gets the issues in all the configured selected for development status regexes', async () => {
httpClientMocks.get.mockReturnValueOnce(of(data.createHttpResponse(data.createJiraUser())));
httpClientMocks.get.mockReturnValueOnce(
of(data.createHttpResponse(data.createJiraStatuses())),
);
httpClientMocks.get.mockReturnValueOnce(of(data.createHttpResponse({ issues: [] })));
await lastValueFrom(jira.getCurrentUserOpenIssues());
expect(httpClientMocks.get.mock.calls[2][1]).toMatchInlineSnapshot(`
{
"qs": {
"expand": "transitions, renderedFields",
"jql": "assignee=Jerry.Rosenbaum AND status IN ('backlog','To do','to do') ORDER BY CREATED DESC",
},
}
`);
});
});
});
11 changes: 10 additions & 1 deletion test/lib/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faker } from '@faker-js/faker';
import { GitConfig } from 'src/git/Config';
import { JiraIssue } from 'src/issue-tracker/jira/types';
import { JiraIssue, JiraIssueStatus } from 'src/issue-tracker/jira/types';
import { HttpResponse } from 'src/network/HttpClient';
import {
Config,
Expand Down Expand Up @@ -107,6 +107,15 @@ export const data = {
},
};
},
createJiraStatuses(): JiraIssueStatus[] {
return ['To do', 'to do', 'selected for development', 'backlog', 'in progress'].map(
(statusName) => ({
description: faker.lorem.paragraph(),
id: String(faker.datatype.number(5000)),
name: statusName,
}),
);
},
createRelease(): Release {
return {
id: faker.random.word(),
Expand Down

0 comments on commit 58b6437

Please sign in to comment.