Track assignee for issue (#808)
* track assignee for issue * fix lint * use getUserByID instead Get
This commit is contained in:
parent
68bdaf0a6b
commit
3e0525b47d
|
@ -703,11 +703,23 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
||||||
|
|
||||||
// ChangeAssignee changes the Asssignee field of this issue.
|
// ChangeAssignee changes the Asssignee field of this issue.
|
||||||
func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
|
func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
|
||||||
|
var oldAssigneeID = issue.AssigneeID
|
||||||
issue.AssigneeID = assigneeID
|
issue.AssigneeID = assigneeID
|
||||||
if err = UpdateIssueUserByAssignee(issue); err != nil {
|
if err = UpdateIssueUserByAssignee(issue); err != nil {
|
||||||
return fmt.Errorf("UpdateIssueUserByAssignee: %v", err)
|
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)
|
issue.Assignee, err = GetUserByID(issue.AssigneeID)
|
||||||
if err != nil && !IsErrUserNotExist(err) {
|
if err != nil && !IsErrUserNotExist(err) {
|
||||||
log.Error(4, "GetUserByID [assignee_id: %v]: %v", issue.AssigneeID, 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 {
|
if opts.IsPull {
|
||||||
_, err = e.Exec("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?", opts.Issue.RepoID)
|
_, err = e.Exec("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?", opts.Issue.RepoID)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -40,6 +40,8 @@ const (
|
||||||
CommentTypeLabel
|
CommentTypeLabel
|
||||||
// Milestone changed
|
// Milestone changed
|
||||||
CommentTypeMilestone
|
CommentTypeMilestone
|
||||||
|
// Assignees changed
|
||||||
|
CommentTypeAssignees
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommentTag defines comment tag type
|
// CommentTag defines comment tag type
|
||||||
|
@ -66,6 +68,11 @@ type Comment struct {
|
||||||
MilestoneID int64
|
MilestoneID int64
|
||||||
OldMilestone *Milestone `xorm:"-"`
|
OldMilestone *Milestone `xorm:"-"`
|
||||||
Milestone *Milestone `xorm:"-"`
|
Milestone *Milestone `xorm:"-"`
|
||||||
|
OldAssigneeID int64
|
||||||
|
AssigneeID int64
|
||||||
|
Assignee *User `xorm:"-"`
|
||||||
|
OldAssignee *User `xorm:"-"`
|
||||||
|
|
||||||
CommitID int64
|
CommitID int64
|
||||||
Line int64
|
Line int64
|
||||||
Content string `xorm:"TEXT"`
|
Content string `xorm:"TEXT"`
|
||||||
|
@ -240,6 +247,25 @@ func (c *Comment) LoadMilestone() error {
|
||||||
return nil
|
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
|
// MailParticipants sends new comment emails to repository watchers
|
||||||
// and mentioned people.
|
// and mentioned people.
|
||||||
func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
|
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,
|
LabelID: LabelID,
|
||||||
OldMilestoneID: opts.OldMilestoneID,
|
OldMilestoneID: opts.OldMilestoneID,
|
||||||
MilestoneID: opts.MilestoneID,
|
MilestoneID: opts.MilestoneID,
|
||||||
|
OldAssigneeID: opts.OldAssigneeID,
|
||||||
|
AssigneeID: opts.AssigneeID,
|
||||||
CommitID: opts.CommitID,
|
CommitID: opts.CommitID,
|
||||||
CommitSHA: opts.CommitSHA,
|
CommitSHA: opts.CommitSHA,
|
||||||
Line: opts.LineNum,
|
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
|
// CreateCommentOptions defines options for creating comment
|
||||||
type CreateCommentOptions struct {
|
type CreateCommentOptions struct {
|
||||||
Type CommentType
|
Type CommentType
|
||||||
|
@ -426,6 +465,8 @@ type CreateCommentOptions struct {
|
||||||
|
|
||||||
OldMilestoneID int64
|
OldMilestoneID int64
|
||||||
MilestoneID int64
|
MilestoneID int64
|
||||||
|
OldAssigneeID int64
|
||||||
|
AssigneeID int64
|
||||||
CommitID int64
|
CommitID int64
|
||||||
CommitSHA string
|
CommitSHA string
|
||||||
LineNum int64
|
LineNum int64
|
||||||
|
|
|
@ -546,6 +546,9 @@ issues.remove_label_at = `removed the <div class="ui label" style="color: %s; ba
|
||||||
issues.add_milestone_at = `added this to the <b>%s</b> milestone %s`
|
issues.add_milestone_at = `added this to the <b>%s</b> milestone %s`
|
||||||
issues.change_milestone_at = `modified the milestone from <b>%s</b> to <b>%s</b> %s`
|
issues.change_milestone_at = `modified the milestone from <b>%s</b> to <b>%s</b> %s`
|
||||||
issues.remove_milestone_at = `removed this from the <b>%s</b> milestone %s`
|
issues.remove_milestone_at = `removed this from the <b>%s</b> milestone %s`
|
||||||
|
issues.self_assign_at = `self-assigned this %s`
|
||||||
|
issues.add_assignee_at = `was assigned by <b>%s</b> %s`
|
||||||
|
issues.remove_assignee_at = `removed their assignment %s`
|
||||||
issues.open_tab = %d Open
|
issues.open_tab = %d Open
|
||||||
issues.close_tab = %d Closed
|
issues.close_tab = %d Closed
|
||||||
issues.filter_label = Label
|
issues.filter_label = Label
|
||||||
|
|
|
@ -615,6 +615,11 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.Handle(500, "LoadMilestone", err)
|
ctx.Handle(500, "LoadMilestone", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if comment.Type == models.CommentTypeAssignees {
|
||||||
|
if err = comment.LoadAssignees(); err != nil {
|
||||||
|
ctx.Handle(500, "LoadAssignees", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,19 @@
|
||||||
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
|
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
|
||||||
{{if gt .OldMilestoneID 0}}{{if gt .MilestoneID 0}}{{$.i18n.Tr "repo.issues.change_milestone_at" .OldMilestone.Name .Milestone.Name $createdStr | Safe}}{{else}}{{$.i18n.Tr "repo.issues.remove_milestone_at" .OldMilestone.Name $createdStr | Safe}}{{end}}{{else if gt .MilestoneID 0}}{{$.i18n.Tr "repo.issues.add_milestone_at" .Milestone.Name $createdStr | Safe}}{{end}}</span>
|
{{if gt .OldMilestoneID 0}}{{if gt .MilestoneID 0}}{{$.i18n.Tr "repo.issues.change_milestone_at" .OldMilestone.Name .Milestone.Name $createdStr | Safe}}{{else}}{{$.i18n.Tr "repo.issues.remove_milestone_at" .OldMilestone.Name $createdStr | Safe}}{{end}}{{else if gt .MilestoneID 0}}{{$.i18n.Tr "repo.issues.add_milestone_at" .Milestone.Name $createdStr | Safe}}{{end}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
{{else if eq .Type 9}}
|
||||||
|
<div class="event">
|
||||||
|
<span class="octicon octicon-primitive-dot"></span>
|
||||||
|
{{if gt .AssigneeID 0}}{{if eq .Poster.ID .AssigneeID}}<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
||||||
|
<img src="{{.Poster.RelAvatarLink}}">
|
||||||
|
</a> <span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> {{$.i18n.Tr "repo.issues.self_assign_at" $createdStr | Safe}} </span>
|
||||||
|
{{else}}<a class="ui avatar image" href="{{.Assignee.HomeLink}}">
|
||||||
|
<img src="{{.Assignee.RelAvatarLink}}">
|
||||||
|
</a><span class="text grey"><a href="{{.Assignee.HomeLink}}">{{.Assignee.Name}}</a> {{$.i18n.Tr "repo.issues.add_assignee_at" .Poster.Name $createdStr | Safe}} </span>{{end}}{{else if gt .OldAssigneeID 0}}
|
||||||
|
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
||||||
|
<img src="{{.Poster.RelAvatarLink}}">
|
||||||
|
</a> <span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> {{$.i18n.Tr "repo.issues.remove_assignee_at" $createdStr | Safe}} </span>{{end}}
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue