summaryrefslogtreecommitdiffstats
path: root/models/pull.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/pull.go')
-rw-r--r--models/pull.go25
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