From 5a7e85f20b5d88a2d5cdd5aa1d8120abd199d02e Mon Sep 17 00:00:00 2001 From: wonjerry Date: Thu, 16 Jul 2026 11:29:48 +0900 Subject: [PATCH] fix(github): encode PR content paths by segment --- src/main/github/work-item-details.test.ts | 6 +++--- src/main/github/work-item-details.ts | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/github/work-item-details.test.ts b/src/main/github/work-item-details.test.ts index cc46b2b30..1a30e1e7f 100644 --- a/src/main/github/work-item-details.test.ts +++ b/src/main/github/work-item-details.test.ts @@ -667,10 +667,10 @@ describe('getWorkItemDetails', () => { }) ghExecFileAsyncMock.mockImplementation(async (args: string[]) => { const endpoint = args.find((arg) => arg.startsWith('repos/')) ?? '' - if (endpoint === 'repos/team/orca/contents/src/enterprise.ts?ref=base-sha') { + if (endpoint === 'repos/team/orca/contents/src/path%23with%3Fchars.ts?ref=base-sha') { return { stdout: 'base content' } } - if (endpoint === 'repos/team/orca/contents/src/enterprise.ts?ref=head-sha') { + if (endpoint === 'repos/team/orca/contents/src/path%23with%3Fchars.ts?ref=head-sha') { return { stdout: 'head content' } } throw new Error(`unexpected gh call: ${args.join(' ')}`) @@ -679,7 +679,7 @@ describe('getWorkItemDetails', () => { const contents = await getPRFileContents({ repoPath: '/repo-root', prNumber: 7, - path: 'src/enterprise.ts', + path: 'src/path#with?chars.ts', status: 'modified', headSha: 'head-sha', baseSha: 'base-sha' diff --git a/src/main/github/work-item-details.ts b/src/main/github/work-item-details.ts index c3997aec6..bb7233818 100644 --- a/src/main/github/work-item-details.ts +++ b/src/main/github/work-item-details.ts @@ -76,6 +76,10 @@ function ghApiHostArgs(ownerRepo: GitHubOwnerRepoSlug): string[] { return ownerRepo.host && ownerRepo.host !== 'github.com' ? ['--hostname', ownerRepo.host] : [] } +function encodeGitHubContentPath(path: string): string { + return path.split('/').map(encodeURIComponent).join('/') +} + const PR_FILE_VIEWED_STATES_QUERY = `query($owner: String!, $repo: String!, $number: Int!, $after: String) { repository(owner: $owner, name: $repo) { pullRequest(number: $number) { @@ -1251,7 +1255,7 @@ async function fetchContentAtRef(args: { '-H', 'Accept: application/vnd.github.raw', ...ghApiHostArgs(args.ownerRepo), - `repos/${args.ownerRepo.owner}/${args.ownerRepo.repo}/contents/${encodeURI(args.path)}?ref=${encodeURIComponent(args.ref)}` + `repos/${args.ownerRepo.owner}/${args.ownerRepo.repo}/contents/${encodeGitHubContentPath(args.path)}?ref=${encodeURIComponent(args.ref)}` ], { ...ghRepoExecOptions(