Skip to content

Commit e94bcab

Browse files
committed
Set the PR state before attempting to update it, to avoid GH erroring with "Cannot change the base branch of a closed pull request"
1 parent 32d356b commit e94bcab

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,19 @@ func migratePullRequests(ctx context.Context, githubPath, gitlabPath []string, p
10561056
newState = pointer("closed")
10571057
}
10581058

1059+
if pullRequest.State != nil && newState != nil && *pullRequest.State != *newState {
1060+
pullRequestState := &github.PullRequest{
1061+
Number: pullRequest.Number,
1062+
State: newState,
1063+
}
1064+
1065+
if pullRequest, _, err = gh.PullRequests.Edit(ctx, githubPath[0], githubPath[1], pullRequestState.GetNumber(), pullRequestState); err != nil {
1066+
sendErr(fmt.Errorf("updating pull request state: %v", err))
1067+
failureCount++
1068+
continue
1069+
}
1070+
}
1071+
10591072
if (newState != nil && (pullRequest.State == nil || *pullRequest.State != *newState)) ||
10601073
(pullRequest.Title == nil || *pullRequest.Title != mergeRequest.Title) ||
10611074
(pullRequest.Body == nil || *pullRequest.Body != body) ||
@@ -1065,7 +1078,6 @@ func migratePullRequests(ctx context.Context, githubPath, gitlabPath []string, p
10651078
pullRequest.Title = &mergeRequest.Title
10661079
pullRequest.Body = &body
10671080
pullRequest.Draft = &mergeRequest.Draft
1068-
pullRequest.State = newState
10691081
pullRequest.MaintainerCanModify = nil
10701082
if pullRequest, _, err = gh.PullRequests.Edit(ctx, githubPath[0], githubPath[1], pullRequest.GetNumber(), pullRequest); err != nil {
10711083
sendErr(fmt.Errorf("updating pull request: %v", err))

0 commit comments

Comments
 (0)