summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2019-08-03 21:38:42 +0300
committerGitHub <noreply@github.com>2019-08-03 21:38:42 +0300
commit6c0c5c531065dad3c59889e45676b0b0374f39aa (patch)
tree4d376c5625db793311c7cdbb0a27e63e7eb7c5d5 /models
parent4fe490f062a4bdf943d9b58398ecbd5b1d2b1b7e (diff)
downloadgitea-6c0c5c531065dad3c59889e45676b0b0374f39aa.tar.gz
gitea-6c0c5c531065dad3c59889e45676b0b0374f39aa.zip
Fix milestone completness calculation when migrating (#7725)
Diffstat (limited to 'models')
-rw-r--r--models/migrate.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/models/migrate.go b/models/migrate.go
index b30e6a9d1c..85be3a312c 100644
--- a/models/migrate.go
+++ b/models/migrate.go
@@ -62,38 +62,50 @@ func insertIssue(sess *xorm.Session, issue *Issue) error {
if _, err := sess.Insert(issueLabels); err != nil {
return err
}
+
+ cols := make([]string, 0)
if !issue.IsPull {
sess.ID(issue.RepoID).Incr("num_issues")
+ cols = append(cols, "num_issues")
if issue.IsClosed {
sess.Incr("num_closed_issues")
+ cols = append(cols, "num_closed_issues")
}
} else {
sess.ID(issue.RepoID).Incr("num_pulls")
+ cols = append(cols, "num_pulls")
if issue.IsClosed {
sess.Incr("num_closed_pulls")
+ cols = append(cols, "num_closed_pulls")
}
}
- if _, err := sess.NoAutoTime().Update(issue.Repo); err != nil {
+ if _, err := sess.NoAutoTime().Cols(cols...).Update(issue.Repo); err != nil {
return err
}
+ cols = []string{"num_issues"}
sess.Incr("num_issues")
if issue.IsClosed {
sess.Incr("num_closed_issues")
+ cols = append(cols, "num_closed_issues")
}
- if _, err := sess.In("id", labelIDs).NoAutoTime().Update(new(Label)); err != nil {
+ if _, err := sess.In("id", labelIDs).NoAutoTime().Cols(cols...).Update(new(Label)); err != nil {
return err
}
if issue.MilestoneID > 0 {
+ cols = []string{"num_issues"}
sess.Incr("num_issues")
+ cl := "num_closed_issues"
if issue.IsClosed {
sess.Incr("num_closed_issues")
+ cols = append(cols, "num_closed_issues")
+ cl = "(num_closed_issues + 1)"
}
if _, err := sess.ID(issue.MilestoneID).
- SetExpr("completeness", "num_closed_issues * 100 / num_issues").
- NoAutoTime().
+ SetExpr("completeness", cl+" * 100 / (num_issues + 1)").
+ NoAutoTime().Cols(cols...).
Update(new(Milestone)); err != nil {
return err
}