Skip to content

Commit b244a34

Browse files
Copilotrzhao271
andauthored
fix: use SubtleCrypto.digest() for sha256Hex in browser, propagate async through parse functions
Co-authored-by: rzhao271 <7199958+rzhao271@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/02d6fd03-1129-4492-ab95-06726304775e
1 parent 5a96afc commit b244a34

File tree

4 files changed

+88
-84
lines changed

4 files changed

+88
-84
lines changed

src/github/githubRepository.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,9 +1430,9 @@ export class GitHubRepository extends Disposable {
14301430
}
14311431

14321432
ret.push(
1433-
...result.data.repository.mentionableUsers.nodes.map(node => {
1433+
...await Promise.all(result.data.repository.mentionableUsers.nodes.map(node => {
14341434
return parseAccount(node, this);
1435-
}),
1435+
})),
14361436
);
14371437

14381438
hasNextPage = result.data.repository.mentionableUsers.pageInfo.hasNextPage;
@@ -1457,7 +1457,7 @@ export class GitHubRepository extends Disposable {
14571457
login,
14581458
},
14591459
});
1460-
return parseGraphQLUser(data, this);
1460+
return await parseGraphQLUser(data, this);
14611461
} catch (e) {
14621462
// Ignore cases where the user doesn't exist
14631463
if (!(e.message as (string | undefined))?.startsWith('GraphQL error: Could not resolve to a User with the login of')) {
@@ -1518,9 +1518,9 @@ export class GitHubRepository extends Disposable {
15181518
const users = (result.data as AssignableUsersResponse).repository?.assignableUsers ?? (result.data as SuggestedActorsResponse).repository?.suggestedActors;
15191519

15201520
ret.push(
1521-
...(users?.nodes.map(node => {
1521+
...(await Promise.all(users?.nodes.map(node => {
15221522
return parseAccount(node, this);
1523-
}) || []),
1523+
}) || [])),
15241524
);
15251525

15261526
hasNextPage = users?.pageInfo.hasNextPage;
@@ -1616,17 +1616,17 @@ export class GitHubRepository extends Disposable {
16161616
},
16171617
});
16181618

1619-
result.data.organization.teams.nodes.forEach(node => {
1619+
for (const node of result.data.organization.teams.nodes) {
16201620
const team: ITeam = {
1621-
avatarUrl: getAvatarWithEnterpriseFallback(node.avatarUrl, undefined, this.remote.isEnterprise),
1621+
avatarUrl: await getAvatarWithEnterpriseFallback(node.avatarUrl, undefined, this.remote.isEnterprise),
16221622
name: node.name,
16231623
url: node.url,
16241624
slug: node.slug,
16251625
id: node.id,
16261626
org: remote.owner
16271627
};
16281628
orgTeams.push({ ...team, repositoryNames: node.repositories.nodes.map(repo => repo.name) });
1629-
});
1629+
}
16301630

16311631
hasNextPage = result.data.organization.teams.pageInfo.hasNextPage;
16321632
after = result.data.organization.teams.pageInfo.endCursor;
@@ -1671,9 +1671,9 @@ export class GitHubRepository extends Disposable {
16711671
}
16721672

16731673
ret.push(
1674-
...result.data.repository.pullRequest.participants.nodes.map(node => {
1674+
...await Promise.all(result.data.repository.pullRequest.participants.nodes.map(node => {
16751675
return parseAccount(node, this);
1676-
}),
1676+
})),
16771677
);
16781678
} catch (e) {
16791679
Logger.debug(`Unable to fetch participants from a PullRequest: ${e}`, this.id);
@@ -1767,15 +1767,15 @@ export class GitHubRepository extends Disposable {
17671767
statuses: []
17681768
};
17691769
} else {
1770-
const dedupedStatuses = this.deduplicateStatusChecks(statusCheckRollup.contexts.nodes.map(context => {
1770+
const dedupedStatuses = this.deduplicateStatusChecks(await Promise.all(statusCheckRollup.contexts.nodes.map(async context => {
17711771
if (isCheckRun(context)) {
17721772
return {
17731773
id: context.id,
17741774
databaseId: context.databaseId,
17751775
url: context.checkSuite?.app?.url,
17761776
avatarUrl:
17771777
context.checkSuite?.app?.logoUrl &&
1778-
getAvatarWithEnterpriseFallback(
1778+
await getAvatarWithEnterpriseFallback(
17791779
context.checkSuite.app.logoUrl,
17801780
undefined,
17811781
this.remote.isEnterprise,
@@ -1795,7 +1795,7 @@ export class GitHubRepository extends Disposable {
17951795
databaseId: undefined,
17961796
url: context.targetUrl ?? undefined,
17971797
avatarUrl: context.avatarUrl
1798-
? getAvatarWithEnterpriseFallback(context.avatarUrl, undefined, this.remote.isEnterprise)
1798+
? await getAvatarWithEnterpriseFallback(context.avatarUrl, undefined, this.remote.isEnterprise)
17991799
: undefined,
18001800
state: this.mapStateAsCheckState(context.state),
18011801
description: context.description,
@@ -1807,7 +1807,7 @@ export class GitHubRepository extends Disposable {
18071807
isCheckRun: false,
18081808
};
18091809
}
1810-
}));
1810+
})));
18111811

18121812
checks = {
18131813
state: this.computeOverallCheckState(dedupedStatuses),

src/github/issueModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
281281
});
282282

283283
this._onDidChange.fire({ timeline: true });
284-
return parseGraphQlIssueComment(data!.addComment.commentEdge.node, this.githubRepository);
284+
return await parseGraphQlIssueComment(data!.addComment.commentEdge.node, this.githubRepository);
285285
}
286286

287287
async editIssueComment(comment: IComment, text: string): Promise<IComment> {
@@ -299,7 +299,7 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
299299
});
300300

301301
this._onDidChange.fire({ timeline: true });
302-
return parseGraphQlIssueComment(data!.updateIssueComment.issueComment, this.githubRepository);
302+
return await parseGraphQlIssueComment(data!.updateIssueComment.issueComment, this.githubRepository);
303303
} catch (e) {
304304
throw new Error(formatError(e));
305305
}

src/github/pullRequestModel.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
564564

565565
this.hasPendingReview = false;
566566
await this.updateDraftModeContext();
567-
const reviewEvent = parseGraphQLReviewEvent(data!.submitPullRequestReview.pullRequestReview, this.githubRepository);
567+
const reviewEvent = await parseGraphQLReviewEvent(data!.submitPullRequestReview.pullRequestReview, this.githubRepository);
568568

569569
const threadWithComment = (this._reviewThreadsCache ?? []).find(thread =>
570570
thread.comments.length ? (thread.comments[0].pullRequestReviewId === reviewEvent.id) : undefined,
@@ -649,7 +649,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
649649
});
650650

651651
const { comments, databaseId } = data!.deletePullRequestReview.pullRequestReview;
652-
const deletedReviewComments = comments.nodes.map(comment => parseGraphQLComment(comment, false, false, this.githubRepository));
652+
const deletedReviewComments = await Promise.all(comments.nodes.map(comment => parseGraphQLComment(comment, false, false, this.githubRepository)));
653653

654654
// Update local state: remove all draft comments (and their threads if emptied) that belonged to the deleted review
655655
const deletedCommentIds = new Set(deletedReviewComments.map(c => c.id));
@@ -772,7 +772,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
772772
}
773773

774774
const thread = data.addPullRequestReviewThread.thread;
775-
const newThread = parseGraphQLReviewThread(thread, this.githubRepository);
775+
const newThread = await parseGraphQLReviewThread(thread, this.githubRepository);
776776
if (!this._reviewThreadsCache) {
777777
this._reviewThreadsCache = [];
778778
}
@@ -824,7 +824,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
824824
}
825825

826826
const { comment } = data.addPullRequestReviewComment;
827-
const newComment = parseGraphQLComment(comment, false, false, this.githubRepository);
827+
const newComment = await parseGraphQLComment(comment, false, false, this.githubRepository);
828828

829829
if (isSingleComment) {
830830
newComment.isDraft = false;
@@ -1023,7 +1023,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
10231023
throw new Error('Editing review comment failed.');
10241024
}
10251025

1026-
const newComment = parseGraphQLComment(
1026+
const newComment = await parseGraphQLComment(
10271027
data.updatePullRequestReviewComment.pullRequestReviewComment,
10281028
!!comment.isResolved,
10291029
!!comment.isOutdated,
@@ -1341,7 +1341,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
13411341
return [];
13421342
}
13431343

1344-
const reviewers: (IAccount | ITeam)[] = parseGraphQLReviewers(data, githubRepository);
1344+
const reviewers: (IAccount | ITeam)[] = await parseGraphQLReviewers(data, githubRepository);
13451345
if (this.reviewers?.length !== reviewers.length || (this.reviewers.some(r => !reviewers.some(rr => rr.id === r.id)))) {
13461346
this.reviewers = reviewers;
13471347
this._onDidChange.fire({ reviewers: true });
@@ -1452,8 +1452,8 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
14521452
});
14531453
}
14541454

1455-
private setReviewThreadCacheFromRaw(raw: ReviewThread[]): IReviewThread[] {
1456-
const reviewThreads: IReviewThread[] = raw.map(thread => parseGraphQLReviewThread(thread, this.githubRepository));
1455+
private async setReviewThreadCacheFromRaw(raw: ReviewThread[]): Promise<IReviewThread[]> {
1456+
const reviewThreads: IReviewThread[] = await Promise.all(raw.map(thread => parseGraphQLReviewThread(thread, this.githubRepository)));
14571457
const oldReviewThreads = this._reviewThreadsCache ?? [];
14581458
this._reviewThreadsCache = reviewThreads;
14591459
this.diffThreads(oldReviewThreads, reviewThreads);
@@ -1556,7 +1556,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
15561556
per_page: 100
15571557
});
15581558
const workStartedInitiator = (timeline.data.find(event => event.event === 'copilot_work_started') as { actor: RestAccount } | undefined)?.actor;
1559-
return workStartedInitiator ? [parseAccount(workStartedInitiator, this.githubRepository)] : [];
1559+
return workStartedInitiator ? [await parseAccount(workStartedInitiator, this.githubRepository)] : [];
15601560
}
15611561

15621562
protected override getUpdatesQuery(schema: any): any {
@@ -2105,7 +2105,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
21052105

21062106
const index = this._reviewThreadsCache?.findIndex(thread => thread.id === threadId) ?? -1;
21072107
if (index > -1) {
2108-
const thread = parseGraphQLReviewThread(data.resolveReviewThread.thread, this.githubRepository);
2108+
const thread = await parseGraphQLReviewThread(data.resolveReviewThread.thread, this.githubRepository);
21092109
this._reviewThreadsCache?.splice(index, 1, thread);
21102110
this._onDidChangeReviewThreads.fire({ added: [], changed: [thread], removed: [] });
21112111
}
@@ -2148,7 +2148,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
21482148

21492149
const index = this._reviewThreadsCache?.findIndex(thread => thread.id === threadId) ?? -1;
21502150
if (index > -1) {
2151-
const thread = parseGraphQLReviewThread(data.unresolveReviewThread.thread, this.githubRepository);
2151+
const thread = await parseGraphQLReviewThread(data.unresolveReviewThread.thread, this.githubRepository);
21522152
this._reviewThreadsCache?.splice(index, 1, thread);
21532153
this._onDidChangeReviewThreads.fire({ added: [], changed: [thread], removed: [] });
21542154
}

0 commit comments

Comments
 (0)