diff options
author | Elias Norberg <elias@aisle.se> | 2019-04-02 21:54:29 +0200 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-04-02 15:54:29 -0400 |
commit | bf5af87eef8913004df63aef58f71628f9c057d0 (patch) | |
tree | 9f49b1076a95d0ebc961a71a3ebb5d146c5d64c3 /models/pull.go | |
parent | 09fb036ad625ec5178319c30df47aac313fdbbe3 (diff) | |
download | gitea-bf5af87eef8913004df63aef58f71628f9c057d0.tar.gz gitea-bf5af87eef8913004df63aef58f71628f9c057d0.zip |
Show last commit status in pull request lists (#6465)
Diffstat (limited to 'models/pull.go')
-rw-r--r-- | models/pull.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/models/pull.go b/models/pull.go index ccd8155317..88f9b1f6e8 100644 --- a/models/pull.go +++ b/models/pull.go @@ -292,6 +292,31 @@ func (pr *PullRequest) CanAutoMerge() bool { return pr.Status == PullRequestStatusMergeable } +// GetLastCommitStatus returns the last commit status for this pull request. +func (pr *PullRequest) GetLastCommitStatus() (status *CommitStatus, err error) { + if err = pr.GetHeadRepo(); err != nil { + return nil, err + } + + headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) + if err != nil { + return nil, err + } + + repo := pr.HeadRepo + lastCommitID, err := headGitRepo.GetBranchCommitID(pr.HeadBranch) + if err != nil { + return nil, err + } + + var statusList []*CommitStatus + statusList, err = GetLatestCommitStatus(repo, lastCommitID, 0) + if err != nil { + return nil, err + } + return CalcCommitStatus(statusList), nil +} + // MergeStyle represents the approach to merge commits into base branch. type MergeStyle string |