forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissueModel.ts
More file actions
120 lines (101 loc) · 3.04 KB
/
issueModel.ts
File metadata and controls
120 lines (101 loc) · 3.04 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Remote } from '../common/remote';
import { GitHubRepository } from './githubRepository';
import { IAccount, Issue, GithubItemStateEnum, IMilestone } from './interface';
import { Protocol } from '../common/protocol';
export class IssueModel {
public id: number;
public graphNodeId: string;
public number: number;
public title: string;
public html_url: string;
public state: GithubItemStateEnum = GithubItemStateEnum.Open;
public author: IAccount;
public assignee: IAccount;
public createdAt: string;
public updatedAt: string;
public milestone?: IMilestone;
public readonly githubRepository: GitHubRepository;
public readonly remote: Remote;
public item: Issue;
public bodyHTML?: string;
constructor(githubRepository: GitHubRepository, remote: Remote, item: Issue) {
this.githubRepository = githubRepository;
if (item.repositoryName && item.repositoryOwner && item.repositoryUrl) {
this.remote = new Remote(item.repositoryName, item.repositoryUrl, new Protocol(item.repositoryUrl));
} else {
this.remote = remote;
}
this.item = item;
this.update(item);
}
public get isOpen(): boolean {
return this.state === GithubItemStateEnum.Open;
}
public get userAvatar(): string | undefined {
if (this.item) {
return this.item.user.avatarUrl;
}
return undefined;
}
public get userAvatarUri(): vscode.Uri | undefined {
if (this.item) {
const key = this.userAvatar;
if (key) {
const uri = vscode.Uri.parse(`${key}&s=${64}`);
// hack, to ensure queries are not wrongly encoded.
const originalToStringFn = uri.toString;
uri.toString = function (skipEncoding?: boolean | undefined) {
return originalToStringFn.call(uri, true);
};
return uri;
}
}
return undefined;
}
public get body(): string {
if (this.item) {
return this.item.body;
}
return '';
}
protected updateState(state: string) {
if (state.toLowerCase() === 'open') {
this.state = GithubItemStateEnum.Open;
} else {
this.state = GithubItemStateEnum.Closed;
}
}
update(issue: Issue): void {
this.id = issue.id;
this.graphNodeId = issue.graphNodeId;
this.number = issue.number;
this.title = issue.title;
this.bodyHTML = issue.bodyHTML;
this.html_url = issue.url;
this.author = issue.user;
this.milestone = issue.milestone;
this.createdAt = issue.createdAt;
this.updatedAt = issue.updatedAt;
this.updateState(issue.state);
if (issue.assignee) {
this.assignee = issue.assignee;
}
}
equals(other: IssueModel | undefined): boolean {
if (!other) {
return false;
}
if (this.number !== other.number) {
return false;
}
if (this.html_url !== other.html_url) {
return false;
}
return true;
}
}