summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-03-08 21:48:31 +0100
committerGitHub <noreply@github.com>2021-03-08 21:48:31 +0100
commit177da717a76d985436c283194229ca3b28a0f597 (patch)
tree31a48383893d16a11f70c9690201c805e72a8368 /modules
parent14d8cb781911ebb5a44fbcf02738e8e02f492e04 (diff)
downloadgitea-177da717a76d985436c283194229ca3b28a0f597.tar.gz
gitea-177da717a76d985436c283194229ca3b28a0f597.zip
[API] get pull, return head branch sha, even if deleted (#14931)
* API: return head branch sha, even if deleted * relax if ref not resolvable
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/pull.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/convert/pull.go b/modules/convert/pull.go
index 87eabcf53a..3c24f4532f 100644
--- a/modules/convert/pull.go
+++ b/modules/convert/pull.go
@@ -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