fix(github): encode PR content paths by segment

This commit is contained in:
wonjerry
2026-07-19 17:57:10 -07:00
committed by Jinjing
parent df21270467
commit 5a7e85f20b
2 changed files with 8 additions and 4 deletions
+3 -3
View File
@@ -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'
+5 -1
View File
@@ -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(