Skip to content

Commit 1ee38b5

Browse files
Copilotalexr00
andcommitted
Add validation for head SHA and clarify handling of all mergeable states
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 6d43fac commit 1ee38b5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/github/pullRequestModel.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,9 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
12151215
return this.updateBranchWithGraphQL();
12161216
}
12171217

1218-
// When there are conflicts, use the REST API approach with conflict resolution
1218+
// For Conflict state, use the REST API approach with conflict resolution.
1219+
// For Unknown or NotMergeable states, the REST API approach will also be used as a fallback,
1220+
// though these states may fail for other reasons (e.g., blocked by branch protection).
12191221
return this.updateBranchWithConflictResolution(model);
12201222
}
12211223

@@ -1225,6 +1227,12 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
12251227
*/
12261228
private async updateBranchWithGraphQL(): Promise<boolean> {
12271229
Logger.debug(`Updating branch using GraphQL UpdatePullRequestBranch mutation - enter`, GitHubRepository.ID);
1230+
1231+
if (!this.head?.sha) {
1232+
Logger.error(`Cannot update branch: head SHA is not available`, GitHubRepository.ID);
1233+
return false;
1234+
}
1235+
12281236
try {
12291237
const { mutate, schema } = await this.githubRepository.ensure();
12301238

@@ -1233,7 +1241,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
12331241
variables: {
12341242
input: {
12351243
pullRequestId: this.graphNodeId,
1236-
expectedHeadOid: this.head?.sha
1244+
expectedHeadOid: this.head.sha
12371245
}
12381246
}
12391247
});

0 commit comments

Comments
 (0)