forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpullRequestModel.ts
More file actions
110 lines (89 loc) · 2.99 KB
/
pullRequestModel.ts
File metadata and controls
110 lines (89 loc) · 2.99 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
/*---------------------------------------------------------------------------------------------
* 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 { GitHubRef } from '../common/githubRef';
import { Remote } from '../common/remote';
import { GitHubRepository } from './githubRepository';
import { IAccount, PullRequest, PullRequestStateEnum } from './interface';
export class PullRequestModel {
public prNumber: number;
public title: string;
public html_url: string;
public state: PullRequestStateEnum = PullRequestStateEnum.Open;
public author: IAccount;
public assignee: IAccount;
public createdAt: string;
public updatedAt: string;
public localBranchName?: string;
public mergeBase?: string;
public get isOpen(): boolean {
return this.state === PullRequestStateEnum.Open;
}
public get isMerged(): boolean {
return this.state === PullRequestStateEnum.Merged;
}
public get userAvatar(): string {
if (this.prItem) {
return this.prItem.user.avatarUrl;
}
return '';
}
public get userAvatarUri(): vscode.Uri | undefined {
if (this.prItem) {
let key = this.userAvatar;
let gravatar = vscode.Uri.parse(`${key}&s=${64}`);
// hack, to ensure queries are not wrongly encoded.
const originalToStringFn = gravatar.toString;
gravatar.toString = function (skipEncoding?: boolean | undefined) {
return originalToStringFn.call(gravatar, true);
};
return gravatar;
}
return undefined;
}
public get body(): string {
if (this.prItem) {
return this.prItem.body;
}
return '';
}
public bodyHTML?: string;
public head: GitHubRef;
public base: GitHubRef;
constructor(public readonly githubRepository: GitHubRepository, public readonly remote: Remote, public prItem: PullRequest) {
this.update(prItem);
}
update(prItem: PullRequest): void {
this.prNumber = prItem.number;
this.title = prItem.title;
this.bodyHTML = prItem.bodyHTML;
this.html_url = prItem.url;
this.author = prItem.user;
if (prItem.state.toLowerCase() === 'open') {
this.state = PullRequestStateEnum.Open;
} else {
this.state = prItem.merged ? PullRequestStateEnum.Merged : PullRequestStateEnum.Closed;
}
if (prItem.assignee) {
this.assignee = prItem.assignee;
}
this.createdAt = prItem.createdAt;
this.updatedAt = prItem.updatedAt ? prItem.updatedAt : this.createdAt;
this.head = new GitHubRef(prItem.head!.ref, prItem.head!.label, prItem.head!.sha, prItem.head!.repo.cloneUrl);
this.base = new GitHubRef(prItem.base!.ref, prItem.base!.label, prItem.base!.sha, prItem.base!.repo.cloneUrl);
}
equals(other: PullRequestModel | undefined): boolean {
if (!other) {
return false;
}
if (this.prNumber !== other.prNumber) {
return false;
}
if (this.html_url !== other.html_url) {
return false;
}
return true;
}
}