From e9ae926e040c94ce66666ae6c330c93918fa321c Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 27 May 2016 18:23:39 -0700 Subject: [PATCH] #809 fix wrong closed issue count when create closed issue via API Add start count corrector for Repository.NumClosedIssues --- README.md | 2 +- gogs.go | 2 +- models/repo.go | 21 +++++++++++++++++++-- routers/api/v1/repo/issue.go | 8 +++++++- templates/.VERSION | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f56dc33a1..a6cb1630d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) -##### Current version: 0.9.27 +##### Current version: 0.9.28 | Web | UI | Preview | |:-------------:|:-------:|:-------:| diff --git a/gogs.go b/gogs.go index 294101226..3795310e2 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.9.27.0512" +const APP_VER = "0.9.28.0527" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 1715067df..6cc16eca1 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1830,9 +1830,26 @@ func CheckRepoStats() { repoStatsCheck(checkers[i]) } - // FIXME: use checker when v0.9, stop supporting old fork repo format. + // ***** START: Repository.NumClosedIssues ***** + desc := "repository count 'num_closed_issues'" + results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=?)", true) + if err != nil { + log.Error(4, "Select %s: %v", desc, err) + } else { + for _, result := range results { + id := com.StrTo(result["id"]).MustInt64() + log.Trace("Updating %s: %d", desc, id) + _, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=?) WHERE id=?", id, true, id) + if err != nil { + log.Error(4, "Update %s[%d]: %v", desc, id, err) + } + } + } + // ***** END: Repository.NumClosedIssues ***** + + // FIXME: use checker when stop supporting old fork repo format. // ***** START: Repository.NumForks ***** - results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)") + results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)") if err != nil { log.Error(4, "Select repository count 'num_forks': %v", err) } else { diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 8c9336ba9..a80adbc35 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -57,7 +57,6 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { PosterID: ctx.User.Id, Poster: ctx.User, Content: form.Body, - IsClosed: form.Closed, } if ctx.Repo.IsWriter() { @@ -86,6 +85,13 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { return } + if form.Closed { + if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil { + ctx.Error(500, "issue.ChangeStatus", err) + return + } + } + // Refetch from database to assign some automatic values var err error issue, err = models.GetIssueByID(issue.ID) diff --git a/templates/.VERSION b/templates/.VERSION index 382132196..e10c86284 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.9.27.0512 \ No newline at end of file +0.9.28.0527 \ No newline at end of file