Skip to content

Commit ef63672

Browse files
committed
Skip baseRefName in PR updates when the base is unchanged
The updatePullRequest GraphQL mutation always included baseRefName, even when the value matched the PR's current base. GitHub's Stacks feature rejects any mutation that includes baseRefName on a stacked PR, causing "Cannot change the base branch because the pull request is part of a stack" errors on pushes that only update the title or body. Add a skipBaseUpdate flag to updatePullRequest. The push flow now compares each PR's base against the existing PR and omits baseRefName from the mutation when it hasn't changed. The dissolve-before-push path still fires when bases actually need retargeting (commit reordering), so the stacks API interaction is unchanged for that case. commit-id: I721013cf
1 parent a9f640f commit ef63672

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎git-jaspr/src/main/kotlin/sims/michael/gitjaspr/GitHubClient.kt‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface GitHubClient {
3535

3636
suspend fun createPullRequest(pullRequest: PullRequest): PullRequest
3737

38-
suspend fun updatePullRequest(pullRequest: PullRequest)
38+
suspend fun updatePullRequest(pullRequest: PullRequest, skipBaseUpdate: Boolean = false)
3939

4040
suspend fun closePullRequest(pullRequest: PullRequest)
4141

@@ -133,14 +133,19 @@ class GitHubClientImpl(
133133
return pr.toPullRequest(getCommitIdFromRemoteRef(pr.headRefName, remoteBranchPrefix))
134134
}
135135

136-
override suspend fun updatePullRequest(pullRequest: PullRequest) {
136+
override suspend fun updatePullRequest(pullRequest: PullRequest, skipBaseUpdate: Boolean) {
137137
logger.trace("updatePullRequest {}", pullRequest)
138138
checkNotNull(pullRequest.id) { "Cannot update $pullRequest without an ID" }
139139
val mutation =
140140
UpdatePullRequestMutation(
141141
UpdatePullRequestInput(
142142
pullRequestId = pullRequest.id,
143-
baseRefName = Optional.present(pullRequest.baseRefName),
143+
baseRefName =
144+
if (skipBaseUpdate) {
145+
Optional.absent()
146+
} else {
147+
Optional.present(pullRequest.baseRefName)
148+
},
144149
title = Optional.present(pullRequest.title),
145150
body = Optional.present(pullRequest.body),
146151
)

‎git-jaspr/src/main/kotlin/sims/michael/gitjaspr/GitJaspr.kt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,11 +1441,12 @@ class GitJaspr(
14411441
try {
14421442
for (pr in prsToMutate) {
14431443
if (pr.id == null) {
1444-
// create the pull request
14451444
ghClient.createPullRequest(pr)
14461445
} else {
1447-
// update the pull request
1448-
ghClient.updatePullRequest(pr)
1446+
val existingPr = existingPrsByCommitId[pr.commitId]
1447+
val baseUnchanged =
1448+
existingPr != null && existingPr.baseRefName == pr.baseRefName
1449+
ghClient.updatePullRequest(pr, skipBaseUpdate = baseUnchanged)
14491450
}
14501451
}
14511452
} catch (e: GitJasprException) {

‎git-jaspr/src/test/kotlin/sims/michael/gitjaspr/githubtests/GitHubStubClient.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class GitHubStubClient(
107107
// No op
108108
}
109109

110-
override suspend fun updatePullRequest(pullRequest: PullRequest) {
110+
override suspend fun updatePullRequest(pullRequest: PullRequest, skipBaseUpdate: Boolean) {
111111
logger.trace("updatePullRequest {}", pullRequest)
112112
synchronized(prs) {
113113
val i =

0 commit comments

Comments
 (0)