Skip to content

fix pulls broken when fork repository deleted #6754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions models/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down