diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-01 10:36:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-01 10:36:08 +0800 |
commit | 081485ecfddc88a05fdea0b0230672271658c086 (patch) | |
tree | bbaaa55ede02f311056f5df6c8b56301be09982d /models/issue.go | |
parent | 10644d6dd7574b031118bf01b2bd737017230ffd (diff) | |
download | gitea-081485ecfddc88a05fdea0b0230672271658c086.tar.gz gitea-081485ecfddc88a05fdea0b0230672271658c086.zip |
add milestone changed traker on issue view (#804)
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/models/issue.go b/models/issue.go index 1727da1d50..05b17e4da5 100644 --- a/models/issue.go +++ b/models/issue.go @@ -739,7 +739,7 @@ type NewIssueOptions struct { IsPull bool } -func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) { +func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) { opts.Issue.Title = strings.TrimSpace(opts.Issue.Title) opts.Issue.Index = opts.Repo.NextIssueIndex() @@ -754,9 +754,6 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) { if milestone != nil { opts.Issue.MilestoneID = milestone.ID opts.Issue.Milestone = milestone - if err = changeMilestoneAssign(e, opts.Issue, -1); err != nil { - return err - } } } @@ -785,6 +782,12 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) { return err } + if opts.Issue.MilestoneID > 0 { + if err = changeMilestoneAssign(e, doer, opts.Issue, -1); err != nil { + return err + } + } + if opts.IsPull { _, err = e.Exec("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?", opts.Issue.RepoID) } else { @@ -849,7 +852,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) return err } - if err = newIssue(sess, NewIssueOptions{ + if err = newIssue(sess, issue.Poster, NewIssueOptions{ Repo: repo, Issue: issue, LableIDs: labelIDs, @@ -1773,7 +1776,7 @@ func ChangeMilestoneIssueStats(issue *Issue) (err error) { return sess.Commit() } -func changeMilestoneAssign(e *xorm.Session, issue *Issue, oldMilestoneID int64) error { +func changeMilestoneAssign(e *xorm.Session, doer *User, issue *Issue, oldMilestoneID int64) error { if oldMilestoneID > 0 { m, err := getMilestoneByRepoID(e, issue.RepoID, oldMilestoneID) if err != nil { @@ -1810,18 +1813,28 @@ func changeMilestoneAssign(e *xorm.Session, issue *Issue, oldMilestoneID int64) } } + if err := issue.loadRepo(e); err != nil { + return err + } + + if oldMilestoneID > 0 || issue.MilestoneID > 0 { + if _, err := createMilestoneComment(e, doer, issue.Repo, issue, oldMilestoneID, issue.MilestoneID); err != nil { + return err + } + } + return updateIssue(e, issue) } // ChangeMilestoneAssign changes assignment of milestone for issue. -func ChangeMilestoneAssign(issue *Issue, oldMilestoneID int64) (err error) { +func ChangeMilestoneAssign(issue *Issue, doer *User, oldMilestoneID int64) (err error) { sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err } - if err = changeMilestoneAssign(sess, issue, oldMilestoneID); err != nil { + if err = changeMilestoneAssign(sess, doer, issue, oldMilestoneID); err != nil { return err } return sess.Commit() |