diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-03 23:09:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-03 23:09:10 +0800 |
commit | 3e0525b47d2d84a251341950cb08da36f42663dd (patch) | |
tree | c3ca9207bccf61968eb2cbab99bc2f06b1235e87 /models | |
parent | 68bdaf0a6b712b522dd465f72a32195f410134a3 (diff) | |
download | gitea-3e0525b47d2d84a251341950cb08da36f42663dd.tar.gz gitea-3e0525b47d2d84a251341950cb08da36f42663dd.zip |
Track assignee for issue (#808)
* track assignee for issue
* fix lint
* use getUserByID instead Get
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 21 | ||||
-rw-r--r-- | models/issue_comment.go | 63 |
2 files changed, 73 insertions, 11 deletions
diff --git a/models/issue.go b/models/issue.go index 4b80c41325..7d7591837e 100644 --- a/models/issue.go +++ b/models/issue.go @@ -703,11 +703,23 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) { // ChangeAssignee changes the Asssignee field of this issue. func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) { + var oldAssigneeID = issue.AssigneeID issue.AssigneeID = assigneeID if err = UpdateIssueUserByAssignee(issue); err != nil { return fmt.Errorf("UpdateIssueUserByAssignee: %v", err) } + sess := x.NewSession() + defer sess.Close() + + if err = issue.loadRepo(sess); err != nil { + return fmt.Errorf("loadRepo: %v", err) + } + + if _, err = createAssigneeComment(sess, doer, issue.Repo, issue, oldAssigneeID, assigneeID); err != nil { + return fmt.Errorf("createAssigneeComment: %v", err) + } + issue.Assignee, err = GetUserByID(issue.AssigneeID) if err != nil && !IsErrUserNotExist(err) { log.Error(4, "GetUserByID [assignee_id: %v]: %v", issue.AssigneeID, err) @@ -798,6 +810,15 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) { } } + if opts.Issue.AssigneeID > 0 { + if err = opts.Issue.loadRepo(e); err != nil { + return err + } + if _, err = createAssigneeComment(e, doer, opts.Issue.Repo, opts.Issue, -1, opts.Issue.AssigneeID); err != nil { + return err + } + } + if opts.IsPull { _, err = e.Exec("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?", opts.Issue.RepoID) } else { diff --git a/models/issue_comment.go b/models/issue_comment.go index d128e2ebab..9e5e87e3c9 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -40,6 +40,8 @@ const ( CommentTypeLabel // Milestone changed CommentTypeMilestone + // Assignees changed + CommentTypeAssignees ) // CommentTag defines comment tag type @@ -55,17 +57,22 @@ const ( // Comment represents a comment in commit and issue page. type Comment struct { - ID int64 `xorm:"pk autoincr"` - Type CommentType - PosterID int64 `xorm:"INDEX"` - Poster *User `xorm:"-"` - IssueID int64 `xorm:"INDEX"` - LabelID int64 - Label *Label `xorm:"-"` - OldMilestoneID int64 - MilestoneID int64 - OldMilestone *Milestone `xorm:"-"` - Milestone *Milestone `xorm:"-"` + ID int64 `xorm:"pk autoincr"` + Type CommentType + PosterID int64 `xorm:"INDEX"` + Poster *User `xorm:"-"` + IssueID int64 `xorm:"INDEX"` + LabelID int64 + Label *Label `xorm:"-"` + OldMilestoneID int64 + MilestoneID int64 + OldMilestone *Milestone `xorm:"-"` + Milestone *Milestone `xorm:"-"` + OldAssigneeID int64 + AssigneeID int64 + Assignee *User `xorm:"-"` + OldAssignee *User `xorm:"-"` + CommitID int64 Line int64 Content string `xorm:"TEXT"` @@ -240,6 +247,25 @@ func (c *Comment) LoadMilestone() error { return nil } +// LoadAssignees if comment.Type is CommentTypeAssignees, then load assignees +func (c *Comment) LoadAssignees() error { + var err error + if c.OldAssigneeID > 0 { + c.OldAssignee, err = getUserByID(x, c.OldAssigneeID) + if err != nil { + return err + } + } + + if c.AssigneeID > 0 { + c.Assignee, err = getUserByID(x, c.AssigneeID) + if err != nil { + return err + } + } + return nil +} + // MailParticipants sends new comment emails to repository watchers // and mentioned people. func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (err error) { @@ -276,6 +302,8 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err LabelID: LabelID, OldMilestoneID: opts.OldMilestoneID, MilestoneID: opts.MilestoneID, + OldAssigneeID: opts.OldAssigneeID, + AssigneeID: opts.AssigneeID, CommitID: opts.CommitID, CommitSHA: opts.CommitSHA, Line: opts.LineNum, @@ -416,6 +444,17 @@ func createMilestoneComment(e *xorm.Session, doer *User, repo *Repository, issue }) } +func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldAssigneeID, assigneeID int64) (*Comment, error) { + return createComment(e, &CreateCommentOptions{ + Type: CommentTypeAssignees, + Doer: doer, + Repo: repo, + Issue: issue, + OldAssigneeID: oldAssigneeID, + AssigneeID: assigneeID, + }) +} + // CreateCommentOptions defines options for creating comment type CreateCommentOptions struct { Type CommentType @@ -426,6 +465,8 @@ type CreateCommentOptions struct { OldMilestoneID int64 MilestoneID int64 + OldAssigneeID int64 + AssigneeID int64 CommitID int64 CommitSHA string LineNum int64 |