From df5f1d9dca6cd995aa8e71df896c8c4689f1ee1a Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 18 Feb 2020 20:04:10 +0000 Subject: [PATCH] Prevent nil pointer in GetPullRequestCommitStatusState (#10342) (#10344) Backport #10344 Ensure that pr.HeadRepo is loaded before using it in GetPullRequestCommitStatusState. Fixes error on merging with successful commit merge statuses. --- services/pull/commit_status.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go index 77aca4855..a4803bfb9 100644 --- a/services/pull/commit_status.go +++ b/services/pull/commit_status.go @@ -91,6 +91,11 @@ func IsPullCommitStatusPass(pr *models.PullRequest) (bool, error) { // GetPullRequestCommitStatusState returns pull request merged commit status state func GetPullRequestCommitStatusState(pr *models.PullRequest) (structs.CommitStatusState, error) { + // Ensure HeadRepo is loaded + if err := pr.LoadHeadRepo(); err != nil { + return "", errors.Wrap(err, "LoadHeadRepo") + } + // check if all required status checks are successful headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) if err != nil {