Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/test/fixtures/pullRequestModel.summarized.ts
13406 views
1
2
export class PullRequestModel extends IssueModel<PullRequest> implements IPullRequestModel {
3
async createCommentReply(
4
body: string,
5
inReplyTo: string,
6
isSingleComment: boolean,
7
commitId?: string,
8
): Promise<IComment | undefined> {}
9
10
/**
11
* Check whether there is an existing pending review and update the context key to control what comment actions are shown.
12
*/
13
async validateDraftMode(): Promise<boolean> {}
14
15
private async updateDraftModeContext() {}
16
17
/**
18
* Edit an existing review comment.
19
* @param comment The comment to edit
20
* @param text The new comment text
21
*/
22
async editReviewComment(comment: IComment, text: string): Promise<IComment> {}
23
24
/**
25
* Deletes a review comment.
26
* @param commentId The comment id to delete
27
*/
28
async deleteReviewComment(commentId: string): Promise<void> {}
29
30
/**
31
* Get existing requests to review.
32
*/
33
async getReviewRequests(): Promise<IAccount[]> {}
34
35
/**
36
* Add reviewers to a pull request
37
* @param reviewers A list of GitHub logins
38
*/
39
async requestReview(reviewers: string[]): Promise<void> {}
40
41
/**
42
* Remove a review request that has not yet been completed
43
* @param reviewer A GitHub Login
44
*/
45
async deleteReviewRequest(reviewers: string[]): Promise<void> {}
46
47
async deleteAssignees(assignees: string[]): Promise<void> {}
48
49
private diffThreads(oldReviewThreads: IReviewThread[], newReviewThreads: IReviewThread[]): void {
50
51
newReviewThreads.forEach(thread => {});
52
53
oldReviewThreads.forEach(thread => {});
54
55
this._onDidChangeReviewThreads.fire({
56
added,
57
changed,
58
removed,
59
});
60
}
61
62
async getReviewThreads(): Promise<IReviewThread[]> {
63
const { remote, query, schema } = await this.githubRepository.ensure();
64
try {} catch (e) {}
65
}
66
67
/**
68
* Get all review comments.
69
*/
70
async initializeReviewComments(): Promise<void> {
71
const { remote, query, schema } = await this.githubRepository.ensure();
72
try {} catch (e) {}
73
}
74
75
/**
76
* Get a list of the commits within a pull request.
77
*/
78
async getCommits(): Promise<OctokitCommon.PullsListCommitsResponseData> {
79
try {} catch (e) {}
80
}
81
82
/**
83
* Get all changed files within a commit
84
* @param commit The commit
85
*/
86
async getCommitChangedFiles(
87
commit: OctokitCommon.PullsListCommitsResponseData[0],
88
): Promise<OctokitCommon.ReposGetCommitResponseFiles> {
89
try {} catch (e) {}
90
}
91
92
/**
93
* Gets file content for a file at the specified commit
94
* @param filePath The file path
95
* @param commit The commit
96
*/
97
async getFile(filePath: string, commit: string) {
98
const { octokit, remote } = await this.githubRepository.ensure();
99
const fileContent = await octokit.call(octokit.api.repos.getContent, {
100
owner: remote.owner,
101
repo: remote.repositoryName,
102
path: filePath,
103
ref: commit,
104
});
105
106
if (Array.isArray(fileContent.data)) {}
107
108
const contents = (fileContent.data as any).content ?? '';
109
const buff = buffer.Buffer.from(contents, (fileContent.data as any).encoding);
110
return buff.toString();
111
}
112
113
/**
114
* Get the timeline events of a pull request, including comments, reviews, commits, merges, deletes, and assigns.
115
*/
116
async getTimelineEvents(): Promise<TimelineEvent[]> {
117
Logger.debug(`Fetch timeline events of PR #${this.number} - enter`, PullRequestModel.ID);
118
const { query, remote, schema } = await this.githubRepository.ensure();
119
120
try {
121
122
const ret = data.repository.pullRequest.timelineItems.nodes;
123
const events = parseGraphQLTimelineEvents(ret, this.githubRepository);
124
125
this.addReviewTimelineEventComments(events, reviewThreads);
126
insertNewCommitsSinceReview(events, latestReviewCommitInfo?.sha, currentUser, this.head);
127
128
return events;
129
} catch (e) {
130
console.log(e);
131
return [];
132
}
133
}
134
135
private addReviewTimelineEventComments(events: TimelineEvent[], reviewThreads: IReviewThread[]): void {
136
interface CommentNode extends IComment {
137
childComments?: CommentNode[];
138
}
139
140
const reviewEvents = events.filter((e): e is CommonReviewEvent => e.event === EventType.Reviewed);
141
const reviewComments = reviewThreads.reduce((previous, current) => (previous as IComment[]).concat(current.comments), []);
142
143
const reviewEventsById = reviewEvents.reduce((index, evt) => {
144
index[evt.id] = evt;
145
evt.comments = [];
146
return index;
147
}, {} as { [key: number]: CommonReviewEvent });
148
149
const commentsById = reviewComments.reduce((index, evt) => {
150
index[evt.id] = evt;
151
return index;
152
}, {} as { [key: number]: CommentNode });
153
154
const roots: CommentNode[] = [];
155
let i = reviewComments.length;
156
while (i-- > 0) {
157
const c: CommentNode = reviewComments[i];
158
if (!c.inReplyToId) {
159
roots.unshift(c);
160
continue;
161
}
162
const parent = commentsById[c.inReplyToId];
163
parent.childComments = parent.childComments || [];
164
parent.childComments = [c, ...(c.childComments || []), ...parent.childComments];
165
}
166
167
roots.forEach(c => {
168
const review = reviewEventsById[c.pullRequestReviewId!];
169
if (review) {}
170
});
171
172
reviewThreads.forEach(thread => {
173
if (!thread.prReviewDatabaseId || !reviewEventsById[thread.prReviewDatabaseId]) {}
174
const prReviewThreadEvent = reviewEventsById[thread.prReviewDatabaseId];
175
prReviewThreadEvent.reviewThread = {
176
threadId: thread.id,
177
canResolve: thread.viewerCanResolve,
178
canUnresolve: thread.viewerCanUnresolve,
179
isResolved: thread.isResolved
180
};
181
182
});
183
184
const pendingReview = reviewEvents.filter(r => r.state.toLowerCase() === 'pending')[0];
185
if (pendingReview) {
186
// Ensures that pending comments made in reply to other reviews are included for the pending review
187
pendingReview.comments = reviewComments.filter(c => c.isDraft);
188
}
189
}
190
191
private async _getReviewRequiredCheck() {
192
const { query, remote, octokit, schema } = await this.githubRepository.ensure();
193
194
const [branch, reviewStates] = await Promise.all([
195
octokit.call(octokit.api.repos.getBranch, { branch: this.base.ref, owner: remote.owner, repo: remote.repositoryName }),
196
query<LatestReviewsResponse>({
197
query: schema.LatestReviews,
198
variables: {
199
owner: remote.owner,
200
name: remote.repositoryName,
201
number: this.number,
202
}
203
})
204
]);
205
if (branch.data.protected && branch.data.protection.required_status_checks && branch.data.protection.required_status_checks.enforcement_level !== 'off') {
206
// We need to add the "review required" check manually.
207
return {
208
id: REVIEW_REQUIRED_CHECK_ID,
209
context: 'Branch Protection',
210
description: vscode.l10n.t('Other requirements have not been met.'),
211
state: (reviewStates.data as LatestReviewsResponse).repository.pullRequest.latestReviews.nodes.every(node => node.state !== 'CHANGES_REQUESTED') ? CheckState.Neutral : CheckState.Failure,
212
target_url: this.html_url
213
};
214
}
215
return undefined;
216
}
217
218
/**
219
* Get the status checks of the pull request, those for the last commit.
220
*/
221
async getStatusChecks(): Promise<PullRequestChecks | undefined> {
222
let checks = await this.githubRepository.getStatusChecks(this.number);
223
224
// Fun info: The checks don't include whether a review is required.
225
// Also, unless you're an admin on the repo, you can't just do octokit.repos.getBranchProtection
226
if ((this.item.mergeable === PullRequestMergeability.NotMergeable) && (!checks || checks.statuses.every(status => status.state === CheckState.Success))) {
227
__SELECTION_HERE__
228
if (reviewRequiredCheck) {
229
if (!checks) {
230
checks = {
231
state: CheckState.Failure,
232
statuses: []
233
};
234
}
235
checks.statuses.push(reviewRequiredCheck);
236
checks.state = CheckState.Failure;
237
}
238
}
239
240
return checks;
241
}
242
243
static async openDiffFromComment(
244
folderManager: FolderRepositoryManager,
245
pullRequestModel: PullRequestModel,
246
comment: IComment,
247
): Promise<void> {
248
const contentChanges = await pullRequestModel.getFileChangesInfo();
249
const change = contentChanges.find(
250
fileChange => fileChange.fileName === comment.path || fileChange.previousFileName === comment.path,
251
);
252
if (!change) {
253
throw new Error(`Can't find matching file`);
254
}
255
256
const pathSegments = comment.path!.split('/');
257
this.openDiff(folderManager, pullRequestModel, change, pathSegments[pathSegments.length - 1]);
258
}
259
260
static async openFirstDiff(
261
folderManager: FolderRepositoryManager,
262
pullRequestModel: PullRequestModel,
263
) {
264
const contentChanges = await pullRequestModel.getFileChangesInfo();
265
if (!contentChanges.length) {
266
return;
267
}
268
269
const firstChange = contentChanges[0];
270
this.openDiff(folderManager, pullRequestModel, firstChange, firstChange.fileName);
271
}
272
273
static async openDiff(
274
folderManager: FolderRepositoryManager,
275
pullRequestModel: PullRequestModel,
276
change: SlimFileChange | InMemFileChange,
277
diffTitle: string
278
): Promise<void> {
279
280
281
let headUri, baseUri: vscode.Uri;
282
if (!pullRequestModel.equals(folderManager.activePullRequest)) {} else {}
283
284
vscode.commands.executeCommand(
285
'vscode.diff',
286
baseUri,
287
headUri,
288
`${diffTitle} (Pull Request)`,
289
{},
290
);
291
}
292
293
private _fileChanges: Map<string, SlimFileChange | InMemFileChange> = new Map();
294
get fileChanges(): Map<string, SlimFileChange | InMemFileChange> {}
295
296
async getFileChangesInfo() {}
297
298
/**
299
* List the changed files in a pull request.
300
*/
301
private async getRawFileChangesInfo(): Promise<IRawFileChange[]> {}
302
}
303
304