Skip to content

Commit e642c47

Browse files
alexr00Copilot
andcommitted
Include caller name
Co-authored-by: Copilot <copilot@github.com>
1 parent 6596ede commit e642c47

8 files changed

Lines changed: 50 additions & 29 deletions

src/github/folderRepositoryManager.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ConflictResolutionCoordinator } from './conflictResolutionCoordinator';
1212
import { Conflict, ConflictResolutionModel } from './conflictResolutionModel';
1313
import { CredentialStore } from './credentials';
1414
import { CopilotWorkingStatus, GitHubRepository, isRateLimitError, ItemsData, PULL_REQUEST_PAGE_SIZE, PullRequestChangeEvent, PullRequestData, TeamReviewerRefreshKind, ViewerPermission } from './githubRepository';
15-
import { PullRequestResponse, PullRequestState } from './graphql';
15+
import { PullRequestState } from './graphql';
1616
import { IAccount, ILabel, IMilestone, IProject, IPullRequestsPagingOptions, Issue, ITeam, MergeMethod, PRType, PullRequestMergeability, RepoAccessAndMergeMethods, User } from './interface';
1717
import { IssueModel } from './issueModel';
1818
import { PullRequestGitHelper, PullRequestMetadata } from './pullRequestGitHelper';
@@ -24,7 +24,6 @@ import {
2424
getPRFetchQuery,
2525
getStateFromQuery,
2626
loginComparator,
27-
parseGraphQLPullRequest,
2827
teamComparator,
2928
variableSubstitution,
3029
} from './utils';
@@ -952,7 +951,7 @@ export class FolderRepositoryManager extends Disposable {
952951
);
953952

954953
if (githubRepo) {
955-
const pullRequest: PullRequestModel | undefined = await githubRepo.getPullRequest(prNumber);
954+
const pullRequest: PullRequestModel | undefined = await githubRepo.getPullRequest(prNumber, 'FolderRepositoryManager.getLocalPullRequests');
956955

957956
if (pullRequest) {
958957
pullRequest.localBranchName = localBranchName;
@@ -1307,7 +1306,7 @@ export class FolderRepositoryManager extends Disposable {
13071306
async getPullRequestsForCategory(githubRepository: GitHubRepository, categoryQuery: string, page?: number): Promise<PullRequestData | undefined> {
13081307
try {
13091308
Logger.debug(`Fetch pull request category ${categoryQuery} - enter`, this.id);
1310-
const { octokit, query, schema } = await githubRepository.ensure();
1309+
const { octokit } = await githubRepository.ensure();
13111310

13121311
/* __GDPR__
13131312
"pr.search.category" : {
@@ -1323,18 +1322,11 @@ export class FolderRepositoryManager extends Disposable {
13231322
page: page || 1,
13241323
});
13251324

1326-
const promises: Promise<{ data: PullRequestResponse, repo: GitHubRepository } | undefined>[] = data.items.map(async (item) => {
1325+
const promises: Promise<{ data: PullRequestModel | undefined, repo: GitHubRepository } | undefined>[] = data.items.map(async (item) => {
13271326
const protocol = new Protocol(item.repository_url);
13281327

13291328
const prRepo = await this.createGitHubRepositoryFromOwnerName(protocol.owner, protocol.repositoryName);
1330-
const { data } = await query<PullRequestResponse>({
1331-
query: schema.PullRequest,
1332-
variables: {
1333-
owner: prRepo.remote.owner,
1334-
name: prRepo.remote.repositoryName,
1335-
number: item.number
1336-
}
1337-
});
1329+
const data = await prRepo.getPullRequest(item.number, 'FolderRepositoryManager.getPullRequests');
13381330
return { data, repo: prRepo };
13391331
});
13401332

@@ -1343,16 +1335,12 @@ export class FolderRepositoryManager extends Disposable {
13431335

13441336
const pullRequests = (await Promise.all(pullRequestResponses
13451337
.map(async response => {
1346-
if (!response?.data.repository) {
1338+
if (!response?.data) {
13471339
Logger.appendLine('Pull request doesn\'t appear to exist.', this.id);
13481340
return null;
13491341
}
13501342

1351-
// Pull requests fetched with a query can be from any repo.
1352-
// We need to use the correct GitHubRepository for this PR.
1353-
return response.repo.createOrUpdatePullRequestModel(
1354-
await parseGraphQLPullRequest(response.data.repository.pullRequest, response.repo), true
1355-
);
1343+
return response.data;
13561344
})))
13571345
.filter(item => item !== null) as PullRequestModel[];
13581346

@@ -2364,7 +2352,7 @@ export class FolderRepositoryManager extends Disposable {
23642352
const githubRepo = await this.resolveItem(owner, repositoryName);
23652353
Logger.trace(`Found GitHub repo for pr #${pullRequestNumber}: ${githubRepo ? 'yes' : 'no'}`, this.id);
23662354
if (githubRepo) {
2367-
const pr = await githubRepo.getPullRequest(pullRequestNumber, useCache);
2355+
const pr = await githubRepo.getPullRequest(pullRequestNumber, 'FolderRepositoryManager.resolvePullRequest', useCache);
23682356
Logger.trace(`Found GitHub pr repo for pr #${pullRequestNumber}: ${pr ? 'yes' : 'no'}`, this.id);
23692357
return pr;
23702358
}
@@ -2644,7 +2632,7 @@ export class FolderRepositoryManager extends Disposable {
26442632
}
26452633

26462634
async fetchById(githubRepo: GitHubRepository, id: number): Promise<PullRequestModel | undefined> {
2647-
const pullRequest = await githubRepo.getPullRequest(id);
2635+
const pullRequest = await githubRepo.getPullRequest(id, 'FolderRepositoryManager.fetchById');
26482636
if (pullRequest) {
26492637
return pullRequest;
26502638
} else {

src/github/githubRepository.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ export interface PullRequestChangeEvent {
188188

189189
export class GitHubRepository extends Disposable {
190190
static ID = 'GitHubRepository';
191+
private static _allRepoIds: Set<number> = new Set();
192+
private static _succeededPullRequests: Map<number, Set<number>> = new Map();
191193
protected _initialized: boolean = false;
192194
protected _hub: GitHub | undefined;
193195
protected _metadata: Promise<IMetadata> | undefined;
@@ -291,6 +293,7 @@ export class GitHubRepository extends Disposable {
291293
silent: boolean = false
292294
) {
293295
super();
296+
GitHubRepository._allRepoIds.add(this._id);
294297
this._queriesSchema = mergeQuerySchemaWithShared(sharedSchema.default, defaultSchema);
295298
// kick off the comments controller early so that the Comments view is visible and doesn't pop up later in an way that's jarring
296299
if (!silent) {
@@ -1207,7 +1210,7 @@ export class GitHubRepository extends Disposable {
12071210
}
12081211
}
12091212

1210-
async getPullRequest(id: number, useCache: boolean = false): Promise<PullRequestModel | undefined> {
1213+
async getPullRequest(id: number, callerName: string, useCache: boolean = false): Promise<PullRequestModel | undefined> {
12111214
if (useCache && this._pullRequestModelsByNumber.has(id)) {
12121215
Logger.debug(`Using cached pull request model for ${id}`, this.id);
12131216
return this._pullRequestModelsByNumber.get(id)!.model;
@@ -1233,9 +1236,39 @@ export class GitHubRepository extends Disposable {
12331236
Logger.debug(`Fetch pull request ${id} - done`, this.id);
12341237
const pr = this.createOrUpdatePullRequestModel(await parseGraphQLPullRequest(data.repository.pullRequest, this));
12351238
await pr.getLastUpdateTime(new Date(pr.item.updatedAt));
1239+
let repoIds = GitHubRepository._succeededPullRequests.get(id);
1240+
if (!repoIds) {
1241+
repoIds = new Set();
1242+
GitHubRepository._succeededPullRequests.set(id, repoIds);
1243+
}
1244+
repoIds.add(this._id);
12361245
return pr;
12371246
} catch (e) {
12381247
Logger.error(`Unable to fetch PR: ${e}`, this.id);
1248+
const succeededRepos = GitHubRepository._succeededPullRequests.get(id);
1249+
const succeededInOtherRepo = succeededRepos ? succeededRepos.size > 0 && !succeededRepos.has(this._id) : false;
1250+
const properties: { succeededInOtherRepo: string; callerName: string; errorCode?: string } = {
1251+
succeededInOtherRepo: String(succeededInOtherRepo),
1252+
callerName
1253+
};
1254+
if (e.status !== undefined) {
1255+
properties.errorCode = String(e.status);
1256+
} else if (e.graphQLErrors?.[0]?.extensions?.code) {
1257+
properties.errorCode = String(e.graphQLErrors[0].extensions.code);
1258+
}
1259+
/* __GDPR__
1260+
"pr.getPullRequestFailed" : {
1261+
"prNumber": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
1262+
"gitHubRepoCount": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
1263+
"succeededInOtherRepo": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
1264+
"errorCode": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
1265+
"callerName": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
1266+
}
1267+
*/
1268+
this.telemetry.sendTelemetryErrorEvent('pr.getPullRequestFailed', properties, {
1269+
prNumber: id,
1270+
gitHubRepoCount: GitHubRepository._allRepoIds.size
1271+
});
12391272
return;
12401273
}
12411274
}

src/github/issueModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
503503

504504
for (const unseenPrs of crossRefs) {
505505
// Kick off getting the new PRs so that the system knows about them (and refreshes the tree when they're found)
506-
this.githubRepository.getPullRequest(unseenPrs.source.number);
506+
this.githubRepository.getPullRequest(unseenPrs.source.number, 'IssueModel.getTimelineEvents');
507507
}
508508

509509
this.timelineEvents = events;

src/github/overviewRestorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class OverviewRestorer extends Disposable implements vscode.WebviewPanelS
6262
}
6363
return IssueOverviewPanel.createOrShow(this._telemetry, this._extensionUri, folderManager, identity, issueModel, undefined, true, webviewPanel);
6464
} else {
65-
const pullRequestModel = await repo.getPullRequest(state.number, true);
65+
const pullRequestModel = await repo.getPullRequest(state.number, 'OverviewRestorer.deserializeWebviewPanel', true);
6666
if (!pullRequestModel) {
6767
webviewPanel.dispose();
6868
return;

src/github/pullRequestModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
344344
let rejectMessage: string | undefined;
345345
if (this.isActive) {
346346
localHead = repository.state.HEAD?.commit;
347-
remoteHead = (await this.githubRepository.getPullRequest(this.number))?.head?.sha;
347+
remoteHead = (await this.githubRepository.getPullRequest(this.number, 'PullRequestModel.approve'))?.head?.sha;
348348
rejectMessage = vscode.l10n.t('The remote head of the pull request branch has changed. Please pull the latest changes from the remote branch before approving.');
349349
} else {
350350
localHead = this.head?.sha;
351-
remoteHead = (await this.githubRepository.getPullRequest(this.number))?.head?.sha;
351+
remoteHead = (await this.githubRepository.getPullRequest(this.number, 'PullRequestModel.approve'))?.head?.sha;
352352
rejectMessage = vscode.l10n.t('The remote head of the pull request branch has changed. Please refresh the pull request before approving.');
353353
}
354354

src/issues/userCompletionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class UserCompletionProvider implements vscode.CompletionItemProvider {
238238
);
239239

240240
if (githubRepo) {
241-
const pr = await githubRepo.getPullRequest(prNumber);
241+
const pr = await githubRepo.getPullRequest(prNumber, 'UserCompletionProvider.provideCompletionItems');
242242
this.cachedForPrNumber = prNumber;
243243
this.cachedPrTimelineEvents = await pr!.getTimelineEvents();
244244
}

src/lm/tools/activePullRequestTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export abstract class PullRequestTool implements vscode.LanguageModelTool<FetchI
5555

5656
if ((options.input as PullRequestToolParams | undefined)?.refresh) {
5757
await Promise.all([
58-
pullRequest.githubRepository.getPullRequest(pullRequest.number),
58+
pullRequest.githubRepository.getPullRequest(pullRequest.number, 'ActivePullRequestTool.invoke'),
5959
pullRequest.getTimelineEvents(),
6060
pullRequest.initializeReviewThreadCacheAndReviewComments(),
6161
]);

src/view/pullRequestCommentController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export class PullRequestCommentController extends CommentControllerBase implemen
374374
if (e.graphQLErrors?.length && e.graphQLErrors[0].type === 'NOT_FOUND') {
375375
vscode.window.showWarningMessage('The comment that you\'re replying to was deleted. Refresh to update.', 'Refresh').then(result => {
376376
if (result === 'Refresh') {
377-
this.pullRequestModel.githubRepository.getPullRequest(this.pullRequestModel.number);
377+
this.pullRequestModel.githubRepository.getPullRequest(this.pullRequestModel.number, 'PullRequestCommentController.replyThread');
378378
}
379379
});
380380
} else {

0 commit comments

Comments
 (0)