mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 16:47:34 +00:00
Patch PR titles without discovery reads (#35525)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -91,7 +91,7 @@ describe('GitHub GraphQL rate-limit guard', () => {
|
||||
})
|
||||
).resolves.toEqual({ ok: true })
|
||||
await expect(
|
||||
updatePRTitle('/repo-root', 7, 'New title', undefined, {
|
||||
updatePRTitle('/repo-root', 7, ' New title @literal ', undefined, {
|
||||
owner: 'stablyai',
|
||||
repo: 'orca',
|
||||
host: 'github.com'
|
||||
@@ -131,7 +131,14 @@ describe('GitHub GraphQL rate-limit guard', () => {
|
||||
)
|
||||
expect(ghExecFileAsyncMock).toHaveBeenNthCalledWith(
|
||||
4,
|
||||
['pr', 'edit', '7', '--title', 'New title', '--repo', 'stablyai/orca'],
|
||||
[
|
||||
'api',
|
||||
'-X',
|
||||
'PATCH',
|
||||
'repos/stablyai/orca/pulls/7',
|
||||
'--raw-field',
|
||||
'title= New title @literal '
|
||||
],
|
||||
{ cwd: '/repo-root', host: 'github.com' }
|
||||
)
|
||||
})
|
||||
|
||||
@@ -6,7 +6,30 @@ import {
|
||||
classifyPullRequestUpdateError,
|
||||
type LocalGitExecOptions
|
||||
} from '../../gh-utils'
|
||||
import { resolveGitHubRepoExecution, type GitHubApiRepository } from '../../github-api-repository'
|
||||
import {
|
||||
resolveGitHubRepoExecution,
|
||||
type GitHubApiRepository,
|
||||
type GitHubRepoExecOptions
|
||||
} from '../../github-api-repository'
|
||||
|
||||
async function patchPullRequest(
|
||||
repository: GitHubApiRepository,
|
||||
prNumber: number,
|
||||
fields: string[],
|
||||
ghOptions: GitHubRepoExecOptions
|
||||
): Promise<void> {
|
||||
await ghExecFileAsync(
|
||||
[
|
||||
'api',
|
||||
'-X',
|
||||
'PATCH',
|
||||
`repos/${repository.owner}/${repository.repo}/pulls/${prNumber}`,
|
||||
...fields.flatMap((field) => ['--raw-field', field])
|
||||
],
|
||||
ghOptions
|
||||
)
|
||||
}
|
||||
|
||||
export async function updatePRTitle(
|
||||
repoPath: string,
|
||||
prNumber: number,
|
||||
@@ -26,13 +49,7 @@ export async function updatePRTitle(
|
||||
}
|
||||
await acquire()
|
||||
try {
|
||||
const args = ['pr', 'edit', String(prNumber), '--title', title]
|
||||
if (ownerRepo) {
|
||||
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
|
||||
}
|
||||
await ghExecFileAsync(args, {
|
||||
...ghOptions
|
||||
})
|
||||
await patchPullRequest(ownerRepo, prNumber, [`title=${title}`], ghOptions)
|
||||
invalidateReviewLookupsAfterPRMutation(repoPath, connectionId)
|
||||
return true
|
||||
} catch (err) {
|
||||
@@ -78,16 +95,7 @@ export async function updatePRDetails(
|
||||
|
||||
await acquire()
|
||||
try {
|
||||
await ghExecFileAsync(
|
||||
[
|
||||
'api',
|
||||
'-X',
|
||||
'PATCH',
|
||||
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${prNumber}`,
|
||||
...fields.flatMap((field) => ['--raw-field', field])
|
||||
],
|
||||
ghOptions
|
||||
)
|
||||
await patchPullRequest(ownerRepo, prNumber, fields, ghOptions)
|
||||
invalidateReviewLookupsAfterPRMutation(repoPath, connectionId)
|
||||
return { ok: true }
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user