diff --git a/models/error.go b/models/error.go index 6458594a03d1..febe3f3e04c0 100644 --- a/models/error.go +++ b/models/error.go @@ -1091,6 +1091,24 @@ func (err ErrPullRequestAlreadyExists) Error() string { err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch) } +// ErrPullRequestHeadRepoMissing represents a "ErrPullRequestHeadRepoMissing" error +type ErrPullRequestHeadRepoMissing struct { + ID int64 + HeadRepoID int64 +} + +// IsErrErrPullRequestHeadRepoMissing checks if an error is a ErrPullRequestHeadRepoMissing. +func IsErrErrPullRequestHeadRepoMissing(err error) bool { + _, ok := err.(ErrPullRequestHeadRepoMissing) + return ok +} + +// Error does pretty-printing :D +func (err ErrPullRequestHeadRepoMissing) Error() string { + return fmt.Sprintf("pull request head repo missing [id: %d, head_repo_id: %d]", + err.ID, err.HeadRepoID) +} + // ErrInvalidMergeStyle represents an error if merging with disabled merge strategy type ErrInvalidMergeStyle struct { ID int64 diff --git a/models/pull.go b/models/pull.go index d059081a44ae..71a2439b2c33 100644 --- a/models/pull.go +++ b/models/pull.go @@ -299,6 +299,10 @@ func (pr *PullRequest) GetLastCommitStatus() (status *CommitStatus, err error) { return nil, err } + if pr.HeadRepo == nil { + return nil, ErrPullRequestHeadRepoMissing{pr.ID, pr.HeadRepoID} + } + headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) if err != nil { return nil, err diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 42661ef738af..4b76bf5ad971 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -223,7 +223,12 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB return } - if isPullOption == util.OptionalBoolTrue { + if issues[i].IsPull { + if err := issues[i].LoadPullRequest(); err != nil { + ctx.ServerError("LoadPullRequest", err) + return + } + commitStatus[issues[i].PullRequest.ID], _ = issues[i].PullRequest.GetLastCommitStatus() } }