fix(github): encode PR content paths by segment
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user