Skip to content

Commit

Permalink
[API] get pull, return head branch sha, even if deleted (go-gitea#14931)
Browse files Browse the repository at this point in the history
* API: return head branch sha, even if deleted

* relax if ref not resolvable
  • Loading branch information
6543 authored Mar 8, 2021
1 parent 14d8cb7 commit 177da71
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/convert/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
}
}

if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
return nil
}
defer baseGitRepo.Close()
refs, err := baseGitRepo.GetRefsFiltered(apiPullRequest.Head.Ref)
if err != nil {
log.Error("GetRefsFiltered[%s]: %v", apiPullRequest.Head.Ref, err)
return nil
} else if len(refs) == 0 {
log.Error("unable to resolve PR head ref")
} else {
apiPullRequest.Head.Sha = refs[0].Object.String()
}
}

if pr.Status != models.PullRequestStatusChecking {
mergeable := !(pr.Status == models.PullRequestStatusConflict || pr.Status == models.PullRequestStatusError) && !pr.IsWorkInProgress()
apiPullRequest.Mergeable = mergeable
Expand Down

0 comments on commit 177da71

Please sign in to comment.