diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-07-26 00:16:45 -0700 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-07-26 15:16:45 +0800 |
commit | 48898e5d0b9ed678b0373b28a5aefa8b5405d37f (patch) | |
tree | d2e9477c5336b3233dda94561cbcf977100a6cb9 /models/issue.go | |
parent | dde0052ca2c478f298942f6fbbe88d27259374ae (diff) | |
download | gitea-48898e5d0b9ed678b0373b28a5aefa8b5405d37f.tar.gz gitea-48898e5d0b9ed678b0373b28a5aefa8b5405d37f.zip |
Fix PR nil-dereference bug (#2195)
* Fix PR nil-dereference bug
* Revert to original error format
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/models/issue.go b/models/issue.go index a8dfb3233f..e2772052f7 100644 --- a/models/issue.go +++ b/models/issue.go @@ -148,6 +148,19 @@ func (issue *Issue) loadAssignee(e Engine) (err error) { return } +func (issue *Issue) loadPullRequest(e Engine) (err error) { + if issue.IsPull && issue.PullRequest == nil { + issue.PullRequest, err = getPullRequestByIssueID(e, issue.ID) + if err != nil { + if IsErrPullRequestNotExist(err) { + return err + } + return fmt.Errorf("getPullRequestByIssueID [%d]: %v", issue.ID, err) + } + } + return nil +} + func (issue *Issue) loadAttributes(e Engine) (err error) { if err = issue.loadRepo(e); err != nil { return @@ -172,12 +185,9 @@ func (issue *Issue) loadAttributes(e Engine) (err error) { return } - if issue.IsPull && issue.PullRequest == nil { + if err = issue.loadPullRequest(e); err != nil && !IsErrPullRequestNotExist(err) { // It is possible pull request is not yet created. - issue.PullRequest, err = getPullRequestByIssueID(e, issue.ID) - if err != nil && !IsErrPullRequestNotExist(err) { - return fmt.Errorf("getPullRequestByIssueID [%d]: %v", issue.ID, err) - } + return err } if issue.Attachments == nil { @@ -321,8 +331,15 @@ func (issue *Issue) HasLabel(labelID int64) bool { func (issue *Issue) sendLabelUpdatedWebhook(doer *User) { var err error if issue.IsPull { - err = issue.PullRequest.LoadIssue() - if err != nil { + if err = issue.loadRepo(x); err != nil { + log.Error(4, "loadRepo: %v", err) + return + } + if err = issue.loadPullRequest(x); err != nil { + log.Error(4, "loadPullRequest: %v", err) + return + } + if err = issue.PullRequest.LoadIssue(); err != nil { log.Error(4, "LoadIssue: %v", err) return } @@ -430,6 +447,8 @@ func (issue *Issue) ClearLabels(doer *User) (err error) { if err := issue.loadRepo(sess); err != nil { return err + } else if err = issue.loadPullRequest(sess); err != nil { + return err } if has, err := hasAccess(sess, doer.ID, issue.Repo, AccessModeWrite); err != nil { |