FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-pull-request-github/src/github/issueModel.ts at master · cone56/vscode-pull-request-github · GitHub
cone56
/
vscode-pull-request-github
Public
forked from
microsoft/vscode-pull-request-github
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
vscode-pull-request-github
/
src
/
github
/
issueModel.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
295 lines (253 loc) · 8.05 KB
Breadcrumbs
vscode-pull-request-github
/
src
/
github
/
issueModel.ts
Copy path
File metadata and controls
295 lines (253 loc) · 8.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*---------------------------------------------------------------------------------------------
* 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
*
as
OctokitTypes
from
'@octokit/types'
;
import
{
IComment
}
from
'../common/comment'
;
import
{
Remote
}
from
'../common/remote'
;
import
{
GitHubRepository
}
from
'./githubRepository'
;
import
{
AddIssueCommentResponse
,
AddReactionResponse
,
DeleteReactionResponse
,
EditIssueCommentResponse
,
TimelineEventsResponse
,
UpdatePullRequestResponse
}
from
'./graphql'
;
import
{
IAccount
,
Issue
,
GithubItemStateEnum
,
IMilestone
,
IPullRequestEditData
}
from
'./interface'
;
import
{
getReactionGroup
,
parseGraphQlIssueComment
,
parseGraphQLTimelineEvents
}
from
'./utils'
;
import
{
formatError
}
from
'../common/utils'
;
import
Logger
from
'../common/logger'
;
import
{
TimelineEvent
}
from
'../common/timelineEvent'
;
export
class
IssueModel
{
static
ID
=
'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
assignees
?:
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
;
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
.
assignees
)
{
this
.
assignees
=
issue
.
assignees
;
}
}
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
;
}
async
edit
(
toEdit
:
IPullRequestEditData
)
:
Promise
<
{
body
:
string
,
bodyHTML
:
string
,
title
:
string
}
>
{
try
{
const
{
mutate
,
schema
}
=
await
this
.
githubRepository
.
ensure
(
)
;
const
{
data
}
=
await
mutate
<
UpdatePullRequestResponse
>
(
{
mutation
:
schema
.
UpdatePullRequest
,
variables
:
{
input
:
{
pullRequestId
:
this
.
graphNodeId
,
body
:
toEdit
.
body
,
title
:
toEdit
.
title
}
}
}
)
;
return
data
!
.
updatePullRequest
.
pullRequest
;
}
catch
(
e
)
{
throw
new
Error
(
formatError
(
e
)
)
;
}
}
canEdit
(
)
:
boolean
{
const
username
=
this
.
author
&&
this
.
author
.
login
;
return
this
.
githubRepository
.
isCurrentUser
(
username
)
;
}
async
getIssueComments
(
)
:
Promise
<
OctokitTypes
.
IssuesListCommentsResponseData
>
{
Logger
.
debug
(
`Fetch issue comments of PR #
${
this
.
number
}
- enter`
,
IssueModel
.
ID
)
;
const
{
octokit
,
remote
}
=
await
this
.
githubRepository
.
ensure
(
)
;
const
promise
=
await
octokit
.
issues
.
listComments
(
{
owner
:
remote
.
owner
,
repo
:
remote
.
repositoryName
,
issue_number
:
this
.
number
,
per_page
:
100
}
)
;
Logger
.
debug
(
`Fetch issue comments of PR #
${
this
.
number
}
- done`
,
IssueModel
.
ID
)
;
return
promise
.
data
;
}
async
createIssueComment
(
text
:
string
)
:
Promise
<
IComment
>
{
const
{
mutate
,
schema
}
=
await
this
.
githubRepository
.
ensure
(
)
;
const
{
data
}
=
await
mutate
<
AddIssueCommentResponse
>
(
{
mutation
:
schema
.
AddIssueComment
,
variables
:
{
input
:
{
subjectId
:
this
.
graphNodeId
,
body
:
text
}
}
}
)
;
return
parseGraphQlIssueComment
(
data
!
.
addComment
.
commentEdge
.
node
)
;
}
async
editIssueComment
(
comment
:
IComment
,
text
:
string
)
:
Promise
<
IComment
>
{
try
{
const
{
mutate
,
schema
}
=
await
this
.
githubRepository
.
ensure
(
)
;
const
{
data
}
=
await
mutate
<
EditIssueCommentResponse
>
(
{
mutation
:
schema
.
EditIssueComment
,
variables
:
{
input
:
{
id
:
comment
.
graphNodeId
,
body
:
text
}
}
}
)
;
return
parseGraphQlIssueComment
(
data
!
.
updateIssueComment
.
issueComment
)
;
}
catch
(
e
)
{
throw
new
Error
(
formatError
(
e
)
)
;
}
}
async
deleteIssueComment
(
commentId
:
string
)
:
Promise
<
void
>
{
try
{
const
{
octokit
,
remote
}
=
await
this
.
githubRepository
.
ensure
(
)
;
await
octokit
.
issues
.
deleteComment
(
{
owner
:
remote
.
owner
,
repo
:
remote
.
repositoryName
,
comment_id
:
Number
(
commentId
)
}
)
;
}
catch
(
e
)
{
throw
new
Error
(
formatError
(
e
)
)
;
}
}
async
addLabels
(
labels
:
string
[
]
)
:
Promise
<
void
>
{
const
{
octokit
,
remote
}
=
await
this
.
githubRepository
.
ensure
(
)
;
await
octokit
.
issues
.
addLabels
(
{
owner
:
remote
.
owner
,
repo
:
remote
.
repositoryName
,
issue_number
:
this
.
number
,
labels
}
)
;
}
async
removeLabel
(
label
:
string
)
:
Promise
<
void
>
{
const
{
octokit
,
remote
}
=
await
this
.
githubRepository
.
ensure
(
)
;
await
octokit
.
issues
.
removeLabel
(
{
owner
:
remote
.
owner
,
repo
:
remote
.
repositoryName
,
issue_number
:
this
.
number
,
name
:
label
}
)
;
}
async
getIssueTimelineEvents
(
)
:
Promise
<
TimelineEvent
[
]
>
{
Logger
.
debug
(
`Fetch timeline events of issue #
${
this
.
number
}
- enter`
,
IssueModel
.
ID
)
;
const
githubRepository
=
this
.
githubRepository
;
const
{
query
,
remote
,
schema
}
=
await
githubRepository
.
ensure
(
)
;
try
{
const
{
data
}
=
await
query
<
TimelineEventsResponse
>
(
{
query
:
schema
.
IssueTimelineEvents
,
variables
:
{
owner
:
remote
.
owner
,
name
:
remote
.
repositoryName
,
number
:
this
.
number
}
}
)
;
const
ret
=
data
.
repository
.
pullRequest
.
timelineItems
.
nodes
;
const
events
=
parseGraphQLTimelineEvents
(
ret
,
githubRepository
)
;
return
events
;
}
catch
(
e
)
{
console
.
log
(
e
)
;
return
[
]
;
}
}
async
addCommentReaction
(
graphNodeId
:
string
,
reaction
:
vscode
.
CommentReaction
)
:
Promise
<
AddReactionResponse
>
{
const
reactionEmojiToContent
=
getReactionGroup
(
)
.
reduce
(
(
prev
,
curr
)
=>
{
prev
[
curr
.
label
]
=
curr
.
title
;
return
prev
;
}
,
{
}
as
{
[
key
:
string
]
:
string
}
)
;
const
{
mutate
,
schema
}
=
await
this
.
githubRepository
.
ensure
(
)
;
const
{
data
}
=
await
mutate
<
AddReactionResponse
>
(
{
mutation
:
schema
.
AddReaction
,
variables
:
{
input
:
{
subjectId
:
graphNodeId
,
content
:
reactionEmojiToContent
[
reaction
.
label
!
]
}
}
}
)
;
return
data
!
;
}
async
deleteCommentReaction
(
graphNodeId
:
string
,
reaction
:
vscode
.
CommentReaction
)
:
Promise
<
DeleteReactionResponse
>
{
const
reactionEmojiToContent
=
getReactionGroup
(
)
.
reduce
(
(
prev
,
curr
)
=>
{
prev
[
curr
.
label
]
=
curr
.
title
;
return
prev
;
}
,
{
}
as
{
[
key
:
string
]
:
string
}
)
;
const
{
mutate
,
schema
}
=
await
this
.
githubRepository
.
ensure
(
)
;
const
{
data
}
=
await
mutate
<
DeleteReactionResponse
>
(
{
mutation
:
schema
.
DeleteReaction
,
variables
:
{
input
:
{
subjectId
:
graphNodeId
,
content
:
reactionEmojiToContent
[
reaction
.
label
!
]
}
}
}
)
;
return
data
!
;
}
}
Back
|
FazBrowse Home
|
New Git URL