豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 34fda39

Browse files
authored
feat: enhance PR detection logging in chat session provider (#4789)
1 parent 13c0ce6 commit 34fda39

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,12 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
367367
|| worktreeProperties.pullRequestState === 'merged'
368368
|| !worktreeProperties.branchName
369369
|| !worktreeProperties.repositoryPath) {
370+
this.logService.debug(`[CopilotCLIChatSessionItemProvider] Skipping PR detection on session open for ${sessionId}: version=${worktreeProperties?.version}, prState=${worktreeProperties?.version === 2 ? worktreeProperties.pullRequestState : 'n/a'}, branch=${!!worktreeProperties?.branchName}, repoPath=${!!worktreeProperties?.repositoryPath}`);
370371
return;
371372
}
372373

374+
this.logService.debug(`[CopilotCLIChatSessionItemProvider] Detecting PR on session open for ${sessionId}, branch=${worktreeProperties.branchName}, existingPrUrl=${worktreeProperties.pullRequestUrl ?? 'none'}`);
375+
373376
const prResult = await detectPullRequestFromGitHubAPI(
374377
worktreeProperties.branchName,
375378
worktreeProperties.repositoryPath,
@@ -382,14 +385,19 @@ export class CopilotCLIChatSessionItemProvider extends Disposable implements vsc
382385
const currentProperties = await this.worktreeManager.getWorktreeProperties(sessionId);
383386
if (currentProperties?.version === 2
384387
&& (currentProperties.pullRequestUrl !== prResult.url || currentProperties.pullRequestState !== prResult.state)) {
388+
this.logService.debug(`[CopilotCLIChatSessionItemProvider] Updating PR metadata for ${sessionId}: url=${prResult.url}, state=${prResult.state} (was url=${currentProperties.pullRequestUrl ?? 'none'}, state=${currentProperties.pullRequestState ?? 'none'})`);
385389
await this.worktreeManager.setWorktreeProperties(sessionId, {
386390
...currentProperties,
387391
pullRequestUrl: prResult.url,
388392
pullRequestState: prResult.state,
389393
changes: undefined,
390394
});
391395
this.notifySessionsChange();
396+
} else {
397+
this.logService.debug(`[CopilotCLIChatSessionItemProvider] PR metadata unchanged for ${sessionId}, skipping update`);
392398
}
399+
} else {
400+
this.logService.debug(`[CopilotCLIChatSessionItemProvider] No PR found via GitHub API for ${sessionId}`);
393401
}
394402
} catch (error) {
395403
this.logService.trace(`[CopilotCLIChatSessionItemProvider] Failed to detect pull request on session open for ${sessionId}: ${error instanceof Error ? error.message : String(error)}`);
@@ -1533,6 +1541,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
15331541
let prUrl = session.createdPullRequestUrl;
15341542
let prState = 'open';
15351543

1544+
this.logService.debug(`[CopilotCLIChatSessionParticipant] handlePullRequestCreated for ${sessionId}: createdPullRequestUrl=${prUrl ?? 'none'}`);
1545+
15361546
const worktreeProperties = await this.copilotCLIWorktreeManagerService.getWorktreeProperties(sessionId);
15371547

15381548
if (!worktreeProperties || worktreeProperties.version !== 2) {
@@ -1544,13 +1554,17 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
15441554
// with branch info — v1 worktrees can't store PR URLs, and sessions
15451555
// without worktree properties have nothing to look up.
15461556
if (worktreeProperties.branchName && worktreeProperties.repositoryPath) {
1557+
this.logService.debug(`[CopilotCLIChatSessionParticipant] No PR URL from session, attempting retry detection for ${sessionId}, branch=${worktreeProperties.branchName}`);
15471558
const prResult = await this.detectPullRequestWithRetry(sessionId);
15481559
prUrl = prResult?.url;
15491560
prState = prResult?.state ?? 'open';
1561+
} else {
1562+
this.logService.debug(`[CopilotCLIChatSessionParticipant] Skipping retry detection for ${sessionId}: branch=${worktreeProperties.branchName ?? 'none'}, repoPath=${!!worktreeProperties.repositoryPath}`);
15501563
}
15511564
}
15521565

15531566
if (!prUrl) {
1567+
this.logService.debug(`[CopilotCLIChatSessionParticipant] No PR detected for ${sessionId} after all attempts`);
15541568
return;
15551569
}
15561570

@@ -1580,14 +1594,17 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
15801594

15811595
for (let attempt = 0; attempt < maxRetries; attempt++) {
15821596
const delay = initialDelay * Math.pow(2, attempt);
1597+
this.logService.debug(`[CopilotCLIChatSessionParticipant] PR detection retry for ${sessionId}: attempt ${attempt + 1}/${maxRetries}, waiting ${delay}ms`);
15831598
await new Promise<void>(resolve => setTimeout(resolve, delay));
15841599

15851600
const prResult = await this.detectPullRequestForSession(sessionId);
15861601
if (prResult) {
1602+
this.logService.debug(`[CopilotCLIChatSessionParticipant] PR detected on attempt ${attempt + 1} for ${sessionId}: url=${prResult.url}, state=${prResult.state}`);
15871603
return prResult;
15881604
}
15891605
}
15901606

1607+
this.logService.debug(`[CopilotCLIChatSessionParticipant] PR detection exhausted all ${maxRetries} retries for ${sessionId}`);
15911608
return undefined;
15921609
}
15931610

@@ -1600,6 +1617,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
16001617
try {
16011618
const worktreeProperties = await this.copilotCLIWorktreeManagerService.getWorktreeProperties(sessionId);
16021619
if (!worktreeProperties?.branchName || !worktreeProperties.repositoryPath) {
1620+
this.logService.debug(`[CopilotCLIChatSessionParticipant] detectPullRequestForSession: missing worktree info for ${sessionId}, branch=${worktreeProperties?.branchName ?? 'none'}, repoPath=${!!worktreeProperties?.repositoryPath}`);
16031621
return undefined;
16041622
}
16051623

@@ -2646,14 +2664,18 @@ async function detectPullRequestFromGitHubAPI(
26462664
): Promise<{ url: string; state: string } | undefined> {
26472665
const repoContext = await gitService.getRepository(URI.file(repositoryPath));
26482666
if (!repoContext) {
2667+
logService.debug(`[detectPullRequestFromGitHubAPI] No git repository found for path: ${repositoryPath}`);
26492668
return undefined;
26502669
}
26512670

26522671
const repoInfo = getGitHubRepoInfoFromContext(repoContext);
26532672
if (!repoInfo) {
2673+
logService.debug(`[detectPullRequestFromGitHubAPI] Could not extract GitHub repo info from repository at: ${repositoryPath}`);
26542674
return undefined;
26552675
}
26562676

2677+
logService.debug(`[detectPullRequestFromGitHubAPI] Querying GitHub API for PR on ${repoInfo.id.org}/${repoInfo.id.repo}, branch=${branchName}`);
2678+
26572679
const pr = await octoKitService.findPullRequestByHeadBranch(
26582680
repoInfo.id.org,
26592681
repoInfo.id.repo,
@@ -2667,5 +2689,6 @@ async function detectPullRequestFromGitHubAPI(
26672689
return { url: pr.url, state: prState };
26682690
}
26692691

2692+
logService.debug(`[detectPullRequestFromGitHubAPI] No PR found for ${repoInfo.id.org}/${repoInfo.id.repo}, branch=${branchName}`);
26702693
return undefined;
26712694
}

0 commit comments

Comments
 (0)