Update issue-user when change milestone
parent
f4486f3eec
commit
db6b71ad03
|
@ -161,6 +161,13 @@ func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 {
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .___ ____ ___
|
||||||
|
// | | ______ ________ __ ____ | | \______ ___________
|
||||||
|
// | |/ ___// ___/ | \_/ __ \| | / ___// __ \_ __ \
|
||||||
|
// | |\___ \ \___ \| | /\ ___/| | /\___ \\ ___/| | \/
|
||||||
|
// |___/____ >____ >____/ \___ >______//____ >\___ >__|
|
||||||
|
// \/ \/ \/ \/ \/
|
||||||
|
|
||||||
// IssueUser represents an issue-user relation.
|
// IssueUser represents an issue-user relation.
|
||||||
type IssueUser struct {
|
type IssueUser struct {
|
||||||
Id int64
|
Id int64
|
||||||
|
@ -404,6 +411,13 @@ type Label struct {
|
||||||
NumOpenIssues int `xorm:"-"`
|
NumOpenIssues int `xorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _____ .__.__ __
|
||||||
|
// / \ |__| | ____ _______/ |_ ____ ____ ____
|
||||||
|
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
|
||||||
|
// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
|
||||||
|
// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
|
||||||
|
// \/ \/ \/ \/ \/
|
||||||
|
|
||||||
// Milestone represents a milestone of repository.
|
// Milestone represents a milestone of repository.
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
Id int64
|
Id int64
|
||||||
|
@ -517,7 +531,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
||||||
func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
|
func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
|
||||||
sess := orm.NewSession()
|
sess := orm.NewSession()
|
||||||
defer sess.Close()
|
defer sess.Close()
|
||||||
if err = sess.Begin(); err != nil {
|
if err = sess.Begin(); err != nil {
|
||||||
|
@ -531,7 +545,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.NumIssues--
|
m.NumIssues--
|
||||||
if isIssueClosed {
|
if issue.IsClosed {
|
||||||
m.NumClosedIssues--
|
m.NumClosedIssues--
|
||||||
}
|
}
|
||||||
if m.NumIssues > 0 {
|
if m.NumIssues > 0 {
|
||||||
|
@ -543,6 +557,12 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawSql := "UPDATE `issue_user` SET milestone_id = 0 WHERE issue_id = ?"
|
||||||
|
if _, err = sess.Exec(rawSql, issue.Id); err != nil {
|
||||||
|
sess.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if mid > 0 {
|
if mid > 0 {
|
||||||
|
@ -551,7 +571,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.NumIssues++
|
m.NumIssues++
|
||||||
if isIssueClosed {
|
if issue.IsClosed {
|
||||||
m.NumClosedIssues++
|
m.NumClosedIssues++
|
||||||
}
|
}
|
||||||
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
|
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
|
||||||
|
@ -559,6 +579,12 @@ func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawSql := "UPDATE `issue_user` SET milestone_id = ? WHERE issue_id = ?"
|
||||||
|
if _, err = sess.Exec(rawSql, m.Id, issue.Id); err != nil {
|
||||||
|
sess.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sess.Commit()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
@ -587,9 +613,22 @@ func DeleteMilestone(m *Milestone) (err error) {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawSql = "UPDATE `issue_user` SET milestone_id = 0 WHERE milestone_id = ?"
|
||||||
|
if _, err = sess.Exec(rawSql, m.Id); err != nil {
|
||||||
|
sess.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
return sess.Commit()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _________ __
|
||||||
|
// \_ ___ \ ____ _____ _____ ____ _____/ |_
|
||||||
|
// / \ \/ / _ \ / \ / \_/ __ \ / \ __\
|
||||||
|
// \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
|
||||||
|
// \______ /\____/|__|_| /__|_| /\___ >___| /__|
|
||||||
|
// \/ \/ \/ \/ \/
|
||||||
|
|
||||||
// Issue types.
|
// Issue types.
|
||||||
const (
|
const (
|
||||||
IT_PLAIN = iota // Pure comment.
|
IT_PLAIN = iota // Pure comment.
|
||||||
|
|
|
@ -426,7 +426,7 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
|
||||||
|
|
||||||
// Not check for invalid milestone id and give responsibility to owners.
|
// Not check for invalid milestone id and give responsibility to owners.
|
||||||
issue.MilestoneId = mid
|
issue.MilestoneId = mid
|
||||||
if err = models.ChangeMilestoneAssign(oldMid, mid, issue.IsClosed); err != nil {
|
if err = models.ChangeMilestoneAssign(oldMid, mid, issue); err != nil {
|
||||||
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
|
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
|
||||||
return
|
return
|
||||||
} else if err = models.UpdateIssue(issue); err != nil {
|
} else if err = models.UpdateIssue(issue); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue