-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathgithub-issue.model.ts
More file actions
88 lines (82 loc) · 2.54 KB
/
github-issue.model.ts
File metadata and controls
88 lines (82 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { IssueState, IssueStateReason } from '../../../../../graphql/graphql-types';
import { PullrequestReviewState } from '../pullrequest-review.model';
import { ReviewDecision } from '../repo-item.model';
import { GithubComment } from './github-comment.model';
import { GithubLabel } from './github-label.model';
export class GithubIssue {
id: string; // Github's backend's id
number: number; // Issue's display id
assignees: Array<{
login: string;
}>;
body: string;
created_at: string;
labels: Array<GithubLabel>;
state: IssueState;
stateReason: IssueStateReason;
title: string;
updated_at: string;
closed_at: string;
url: string;
user: {
// author
login: string;
};
milestone?: {
number: string; // id for milestone
title: string;
state: string;
};
comments?: Array<GithubComment>;
issueOrPr?: string;
isDraft: boolean;
headRepository?: {
nameWithOwner: string;
};
reviews?: Array<{
state: PullrequestReviewState;
author: {
login: string;
avatarUrl: string;
};
}>;
reviewDecision?: ReviewDecision | null;
constructor(githubIssue: {}) {
Object.assign(this, githubIssue);
this.labels = [];
for (const label of githubIssue['labels']) {
this.labels.push(new GithubLabel(label));
}
}
/**
*
* @param name Depending on the isCategorical flag, this name either refers to the category name of label or the exact name of label.
* @param isCategorical Whether the label is categorical.
*/
findLabel(name: string, isCategorical: boolean = true): string {
if (!isCategorical) {
const label = this.labels.find((l) => !l.isCategorical() && l.name === name);
return label ? label.getValue() : undefined;
}
// Find labels with the same category name as what is specified in the parameter.
const labels = this.labels.filter((l) => l.isCategorical() && l.getCategory() === name);
if (labels.length === 0) {
return undefined;
} else if (labels.length === 1) {
return labels[0].getValue();
} else {
// If Label order is not specified, return the first label value else
// If Label order is specified, return the highest ranking label value
if (!GithubLabel.LABEL_ORDER[name]) {
return labels[0].getValue();
} else {
const order = GithubLabel.LABEL_ORDER[name];
return labels
.reduce((result, currLabel) => {
return order[currLabel.getValue()] > order[result.getValue()] ? currLabel : result;
})
.getValue();
}
}
}
}