|
|
@ -129,8 +129,12 @@ func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error) |
|
|
|
|
|
|
|
|
|
|
|
// GetMilestoneByID returns the milestone via id .
|
|
|
|
// GetMilestoneByID returns the milestone via id .
|
|
|
|
func GetMilestoneByID(id int64) (*Milestone, error) { |
|
|
|
func GetMilestoneByID(id int64) (*Milestone, error) { |
|
|
|
|
|
|
|
return getMilestoneByID(x, id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getMilestoneByID(e Engine, id int64) (*Milestone, error) { |
|
|
|
var m Milestone |
|
|
|
var m Milestone |
|
|
|
has, err := x.ID(id).Get(&m) |
|
|
|
has, err := e.ID(id).Get(&m) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} else if !has { |
|
|
|
} else if !has { |
|
|
@ -155,10 +159,6 @@ func UpdateMilestone(m *Milestone, oldIsClosed bool) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := updateMilestoneCompleteness(sess, m.ID); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if IsClosed changed, update milestone numbers of repository
|
|
|
|
// if IsClosed changed, update milestone numbers of repository
|
|
|
|
if oldIsClosed != m.IsClosed { |
|
|
|
if oldIsClosed != m.IsClosed { |
|
|
|
if err := updateRepoMilestoneNum(sess, m.RepoID); err != nil { |
|
|
|
if err := updateRepoMilestoneNum(sess, m.RepoID); err != nil { |
|
|
@ -171,23 +171,31 @@ func UpdateMilestone(m *Milestone, oldIsClosed bool) error { |
|
|
|
|
|
|
|
|
|
|
|
func updateMilestone(e Engine, m *Milestone) error { |
|
|
|
func updateMilestone(e Engine, m *Milestone) error { |
|
|
|
m.Name = strings.TrimSpace(m.Name) |
|
|
|
m.Name = strings.TrimSpace(m.Name) |
|
|
|
_, err := e.ID(m.ID).AllCols(). |
|
|
|
_, err := e.ID(m.ID).AllCols().Update(m) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return updateMilestoneCounters(e, m.ID) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// updateMilestoneCounters calculates NumIssues, NumClosesIssues and Completeness
|
|
|
|
|
|
|
|
func updateMilestoneCounters(e Engine, id int64) error { |
|
|
|
|
|
|
|
_, err := e.ID(id). |
|
|
|
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where( |
|
|
|
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where( |
|
|
|
builder.Eq{"milestone_id": m.ID}, |
|
|
|
builder.Eq{"milestone_id": id}, |
|
|
|
)). |
|
|
|
)). |
|
|
|
SetExpr("num_closed_issues", builder.Select("count(*)").From("issue").Where( |
|
|
|
SetExpr("num_closed_issues", builder.Select("count(*)").From("issue").Where( |
|
|
|
builder.Eq{ |
|
|
|
builder.Eq{ |
|
|
|
"milestone_id": m.ID, |
|
|
|
"milestone_id": id, |
|
|
|
"is_closed": true, |
|
|
|
"is_closed": true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
)). |
|
|
|
)). |
|
|
|
Update(m) |
|
|
|
Update(&Milestone{}) |
|
|
|
return err |
|
|
|
if err != nil { |
|
|
|
} |
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
func updateMilestoneCompleteness(e Engine, milestoneID int64) error { |
|
|
|
_, err = e.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?", |
|
|
|
_, err := e.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?", |
|
|
|
id, |
|
|
|
milestoneID, |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -256,25 +264,15 @@ func changeMilestoneAssign(e *xorm.Session, doer *User, issue *Issue, oldMilesto |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if oldMilestoneID > 0 { |
|
|
|
if oldMilestoneID > 0 { |
|
|
|
if err := updateMilestoneTotalNum(e, oldMilestoneID); err != nil { |
|
|
|
if err := updateMilestoneCounters(e, oldMilestoneID); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if issue.IsClosed { |
|
|
|
|
|
|
|
if err := updateMilestoneClosedNum(e, oldMilestoneID); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if issue.MilestoneID > 0 { |
|
|
|
if issue.MilestoneID > 0 { |
|
|
|
if err := updateMilestoneTotalNum(e, issue.MilestoneID); err != nil { |
|
|
|
if err := updateMilestoneCounters(e, issue.MilestoneID); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if issue.IsClosed { |
|
|
|
|
|
|
|
if err := updateMilestoneClosedNum(e, issue.MilestoneID); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if oldMilestoneID > 0 || issue.MilestoneID > 0 { |
|
|
|
if oldMilestoneID > 0 || issue.MilestoneID > 0 { |
|
|
@ -558,29 +556,6 @@ func updateRepoMilestoneNum(e Engine, repoID int64) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func updateMilestoneTotalNum(e Engine, milestoneID int64) (err error) { |
|
|
|
|
|
|
|
if _, err = e.Exec("UPDATE `milestone` SET num_issues=(SELECT count(*) FROM issue WHERE milestone_id=?) WHERE id=?", |
|
|
|
|
|
|
|
milestoneID, |
|
|
|
|
|
|
|
milestoneID, |
|
|
|
|
|
|
|
); err != nil { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updateMilestoneCompleteness(e, milestoneID) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func updateMilestoneClosedNum(e Engine, milestoneID int64) (err error) { |
|
|
|
|
|
|
|
if _, err = e.Exec("UPDATE `milestone` SET num_closed_issues=(SELECT count(*) FROM issue WHERE milestone_id=? AND is_closed=?) WHERE id=?", |
|
|
|
|
|
|
|
milestoneID, |
|
|
|
|
|
|
|
true, |
|
|
|
|
|
|
|
milestoneID, |
|
|
|
|
|
|
|
); err != nil { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updateMilestoneCompleteness(e, milestoneID) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// _____ _ _ _____ _
|
|
|
|
// _____ _ _ _____ _
|
|
|
|
// |_ _| __ __ _ ___| | _____ __| |_ _(_)_ __ ___ ___ ___
|
|
|
|
// |_ _| __ __ _ ___| | _____ __| |_ _(_)_ __ ___ ___ ___
|
|
|
|
// | || '__/ _` |/ __| |/ / _ \/ _` | | | | | '_ ` _ \ / _ \/ __|
|
|
|
|
// | || '__/ _` |/ __| |/ / _ \/ _` | | | | | '_ ` _ \ / _ \/ __|
|
|
|
|