From d7db4f50239179f860c27aa71488883b720b7728 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 7 Feb 2019 12:10:42 +0100 Subject: [PATCH 01/10] fixes #5957 --- custom/conf/app.ini.sample | 2 + .../doc/advanced/config-cheat-sheet.en-us.md | 1 + models/action.go | 2 +- modules/setting/setting.go | 42 ++++++++++--------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 8a25c6610799d..58819d8f9b695 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -36,6 +36,8 @@ DISABLE_HTTP_GIT = false ACCESS_CONTROL_ALLOW_ORIGIN = ; Force ssh:// clone url instead of scp-style uri when default SSH port is used USE_COMPAT_SSH_URI = false +; Close issues as long as a commit on any branch marks it as fixed +CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false [repository.editor] ; List of file extensions for which lines should be wrapped in the CodeMirror editor diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 3494311de9f43..b90ddc46202d5 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -65,6 +65,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `ACCESS_CONTROL_ALLOW_ORIGIN`: **\**: Value for Access-Control-Allow-Origin header, default is not to present. **WARNING**: This maybe harmful to you website if you do not give it a right value. +- `CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH`: **false**: Close an issue if a commit on a non default branch marks it as closed. ### Repository - Pull Request (`repository.pull-request`) - `WORK_IN_PROGRESS_PREFIXES`: **WIP:,\[WIP\]**: List of prefixes used in Pull Request diff --git a/models/action.go b/models/action.go index c886408b2f488..0cec30b4dfa84 100644 --- a/models/action.go +++ b/models/action.go @@ -539,7 +539,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra } // Change issue status only if the commit has been pushed to the default branch. - if repo.DefaultBranch != branchName { + if repo.DefaultBranch != branchName && !setting.Repository.CloseIssuesViaCommitsInAnyBranch { continue } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 42f1de425e855..4cd0cdbf25b89 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -208,16 +208,17 @@ var ( // Repository settings Repository = struct { - AnsiCharset string - ForcePrivate bool - DefaultPrivate string - MaxCreationLimit int - MirrorQueueLength int - PullRequestQueueLength int - PreferredLicenses []string - DisableHTTPGit bool - AccessControlAllowOrigin string - UseCompatSSHURI bool + AnsiCharset string + ForcePrivate bool + DefaultPrivate string + MaxCreationLimit int + MirrorQueueLength int + PullRequestQueueLength int + PreferredLicenses []string + DisableHTTPGit bool + AccessControlAllowOrigin string + UseCompatSSHURI bool + CloseIssuesViaCommitsInAnyBranch bool // Repository editor settings Editor struct { @@ -245,16 +246,17 @@ var ( WorkInProgressPrefixes []string } `ini:"repository.pull-request"` }{ - AnsiCharset: "", - ForcePrivate: false, - DefaultPrivate: RepoCreatingLastUserVisibility, - MaxCreationLimit: -1, - MirrorQueueLength: 1000, - PullRequestQueueLength: 1000, - PreferredLicenses: []string{"Apache License 2.0,MIT License"}, - DisableHTTPGit: false, - AccessControlAllowOrigin: "", - UseCompatSSHURI: false, + AnsiCharset: "", + ForcePrivate: false, + DefaultPrivate: RepoCreatingLastUserVisibility, + MaxCreationLimit: -1, + MirrorQueueLength: 1000, + PullRequestQueueLength: 1000, + PreferredLicenses: []string{"Apache License 2.0,MIT License"}, + DisableHTTPGit: false, + AccessControlAllowOrigin: "", + UseCompatSSHURI: false, + CloseIssuesViaCommitsInAnyBranch: false, // Repository editor settings Editor: struct { From 85a60e35d0cb294d316a5d3105fd9c91b0c45620 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 7 Feb 2019 13:14:22 +0100 Subject: [PATCH 02/10] add tests to make sure config option is respected --- models/action_test.go | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/models/action_test.go b/models/action_test.go index 0310b0ad5d074..cd63bcec5a7e1 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -260,6 +260,85 @@ func TestUpdateIssuesCommit(t *testing.T) { CheckConsistencyFor(t, &Action{}) } +func TestUpdateIssuesCommit_Issue5957(t *testing.T) { + _ = setting.Repository + setting.Repository.CloseIssuesViaCommitsInAnyBranch = true + + assert.NoError(t, PrepareTestDatabase()) + pushCommits := []*PushCommit{ + { + Sha1: "abcdef1", + CommitterEmail: "user2@example.com", + CommitterName: "User Two", + AuthorEmail: "user4@example.com", + AuthorName: "User Four", + Message: "start working on #FST-1, #1", + }, + { + Sha1: "abcdef2", + CommitterEmail: "user2@example.com", + CommitterName: "User Two", + AuthorEmail: "user2@example.com", + AuthorName: "User Two", + Message: "a plain message", + }, + { + Sha1: "abcdef2", + CommitterEmail: "user2@example.com", + CommitterName: "User Two", + AuthorEmail: "user2@example.com", + AuthorName: "User Two", + Message: "close #2", + }, + } + + user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) + repo.Owner = user + + commentBean := &Comment{ + Type: CommentTypeCommitRef, + CommitSHA: "abcdef1", + PosterID: user.ID, + IssueID: 1, + } + issueBean := &Issue{RepoID: repo.ID, Index: 2} + + AssertNotExistsBean(t, commentBean) + AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 2}, "is_closed=1") + assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch)) + AssertExistsAndLoadBean(t, commentBean) + AssertExistsAndLoadBean(t, issueBean, "is_closed=1") + CheckConsistencyFor(t, &Action{}) + + // Test that push to a non-default branch closes an issue. + pushCommits = []*PushCommit{ + { + Sha1: "abcdef1", + CommitterEmail: "user2@example.com", + CommitterName: "User Two", + AuthorEmail: "user4@example.com", + AuthorName: "User Four", + Message: "close #1", + }, + } + repo = AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + commentBean = &Comment{ + Type: CommentTypeCommitRef, + CommitSHA: "abcdef1", + PosterID: user.ID, + IssueID: 6, + } + issueBean = &Issue{RepoID: repo.ID, Index: 1, ID: 6} + + AssertNotExistsBean(t, commentBean) + AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 1, ID: 6}, "is_closed=1") + assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch")) + AssertExistsAndLoadBean(t, commentBean) + AssertExistsAndLoadBean(t, issueBean, "is_closed=1") + CheckConsistencyFor(t, &Action{}) +} + func testCorrectRepoAction(t *testing.T, opts CommitRepoActionOptions, actionBean *Action) { AssertNotExistsBean(t, actionBean) assert.NoError(t, CommitRepoAction(opts)) From 9758ab38acdfe11ba8f2ccd9382bdc3836e7bad6 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 7 Feb 2019 13:18:48 +0100 Subject: [PATCH 03/10] use already defined struct --- models/action_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/action_test.go b/models/action_test.go index cd63bcec5a7e1..4810676b1bafa 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -332,7 +332,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) { issueBean = &Issue{RepoID: repo.ID, Index: 1, ID: 6} AssertNotExistsBean(t, commentBean) - AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 1, ID: 6}, "is_closed=1") + AssertNotExistsBean(t, issueBean, "is_closed=1") assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch")) AssertExistsAndLoadBean(t, commentBean) AssertExistsAndLoadBean(t, issueBean, "is_closed=1") From 9a8b9923727d13d78309a2a99a917865891c70d1 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 9 Feb 2019 11:27:08 +0100 Subject: [PATCH 04/10] - use migration to make the flag repo wide not for the entire gitea instance Also note that the config value can still be set so as to be able to control the value for new repositories that are to be created - fix copy/paste error in copyright header year and rearrange import - use repo config instead of server config value to determine if a commit should close an issue - update testsuite --- models/action.go | 3 +- models/action_test.go | 56 +++------------------------------ models/fixtures/issue.yml | 13 ++++++++ models/fixtures/repository.yml | 1 + models/migrations/migrations.go | 2 ++ models/migrations/v79.go | 27 ++++++++++++++++ models/repo.go | 15 ++++----- 7 files changed, 58 insertions(+), 59 deletions(-) create mode 100644 models/migrations/v79.go diff --git a/models/action.go b/models/action.go index 0cec30b4dfa84..ca6bfaf66634d 100644 --- a/models/action.go +++ b/models/action.go @@ -539,7 +539,8 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra } // Change issue status only if the commit has been pushed to the default branch. - if repo.DefaultBranch != branchName && !setting.Repository.CloseIssuesViaCommitsInAnyBranch { + // and if the repo is configured to allow only that + if repo.DefaultBranch != branchName && !repo.CloseIssuesViaCommitInAnyBranch { continue } diff --git a/models/action_test.go b/models/action_test.go index 4810676b1bafa..21ab4b85e0f52 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -261,10 +261,10 @@ func TestUpdateIssuesCommit(t *testing.T) { } func TestUpdateIssuesCommit_Issue5957(t *testing.T) { - _ = setting.Repository - setting.Repository.CloseIssuesViaCommitsInAnyBranch = true - assert.NoError(t, PrepareTestDatabase()) + user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + + // Test that push to a non-default branch closes an issue. pushCommits := []*PushCommit{ { Sha1: "abcdef1", @@ -272,64 +272,18 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) { CommitterName: "User Two", AuthorEmail: "user4@example.com", AuthorName: "User Four", - Message: "start working on #FST-1, #1", - }, - { - Sha1: "abcdef2", - CommitterEmail: "user2@example.com", - CommitterName: "User Two", - AuthorEmail: "user2@example.com", - AuthorName: "User Two", - Message: "a plain message", - }, - { - Sha1: "abcdef2", - CommitterEmail: "user2@example.com", - CommitterName: "User Two", - AuthorEmail: "user2@example.com", - AuthorName: "User Two", Message: "close #2", }, } - user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) - repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) - repo.Owner = user - + repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) commentBean := &Comment{ Type: CommentTypeCommitRef, CommitSHA: "abcdef1", PosterID: user.ID, - IssueID: 1, } - issueBean := &Issue{RepoID: repo.ID, Index: 2} - AssertNotExistsBean(t, commentBean) - AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 2}, "is_closed=1") - assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch)) - AssertExistsAndLoadBean(t, commentBean) - AssertExistsAndLoadBean(t, issueBean, "is_closed=1") - CheckConsistencyFor(t, &Action{}) - - // Test that push to a non-default branch closes an issue. - pushCommits = []*PushCommit{ - { - Sha1: "abcdef1", - CommitterEmail: "user2@example.com", - CommitterName: "User Two", - AuthorEmail: "user4@example.com", - AuthorName: "User Four", - Message: "close #1", - }, - } - repo = AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) - commentBean = &Comment{ - Type: CommentTypeCommitRef, - CommitSHA: "abcdef1", - PosterID: user.ID, - IssueID: 6, - } - issueBean = &Issue{RepoID: repo.ID, Index: 1, ID: 6} + issueBean := &Issue{RepoID: repo.ID, Index: 2, ID: 7} AssertNotExistsBean(t, commentBean) AssertNotExistsBean(t, issueBean, "is_closed=1") diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 4de8c4fa7e2cf..01bd8b86f6aa1 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -73,3 +73,16 @@ num_comments: 0 created_unix: 946684850 updated_unix: 978307200 + +- + id: 7 + repo_id: 2 + index: 2 + poster_id: 2 + name: issue7 + content: content for the seventh issue + is_closed: false + is_pull: false + created_unix: 946684830 + updated_unix: 978307200 + diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index d412e52d8e56c..a815ba7b668c1 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -22,6 +22,7 @@ num_pulls: 0 num_closed_pulls: 0 num_stars: 1 + close_issues_via_commit_in_any_branch: true - id: 3 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 533ff90738e77..a81536d851fae 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -210,6 +210,8 @@ var migrations = []Migration{ NewMigration("add theme to users", addUserDefaultTheme), // v78 -> v79 NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty), + // v79 -> v80 + NewMigration("add ca close issues via commit in any branch", addCanCloseIssuesViaCommitInAnyBranch), } // Migrate database to current version diff --git a/models/migrations/v79.go b/models/migrations/v79.go new file mode 100644 index 0000000000000..77922825a1ca7 --- /dev/null +++ b/models/migrations/v79.go @@ -0,0 +1,27 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "code.gitea.io/gitea/modules/setting" + + "github.com/go-xorm/xorm" +) + +func addCanCloseIssuesViaCommitInAnyBranch(x *xorm.Engine) error { + + type Repository struct { + ID int64 `xorm:"pk autoincr"` + CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"` + } + + if err := x.Sync2(new(Repository)); err != nil { + return err + } + + _, err := x.Exec("UPDATE repository SET close_issues_via_commit_in_any_branch = ?", + setting.Repository.CloseIssuesViaCommitsInAnyBranch) + return err +} diff --git a/models/repo.go b/models/repo.go index 873fd407fb931..f1428abf3ee11 100644 --- a/models/repo.go +++ b/models/repo.go @@ -197,13 +197,14 @@ type Repository struct { ExternalMetas map[string]string `xorm:"-"` Units []*RepoUnit `xorm:"-"` - IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` - ForkID int64 `xorm:"INDEX"` - BaseRepo *Repository `xorm:"-"` - Size int64 `xorm:"NOT NULL DEFAULT 0"` - IndexerStatus *RepoIndexerStatus `xorm:"-"` - IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"` - Topics []string `xorm:"TEXT JSON"` + IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` + ForkID int64 `xorm:"INDEX"` + BaseRepo *Repository `xorm:"-"` + Size int64 `xorm:"NOT NULL DEFAULT 0"` + IndexerStatus *RepoIndexerStatus `xorm:"-"` + IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"` + CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"` + Topics []string `xorm:"TEXT JSON"` CreatedUnix util.TimeStamp `xorm:"INDEX created"` UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` From 4d61befa640fad28c6f4a946e02adb169bf9df61 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 9 Feb 2019 12:18:31 +0100 Subject: [PATCH 05/10] use global config only when creating a new repository --- models/repo.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/models/repo.go b/models/repo.go index f1428abf3ee11..40d8f71e41b92 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1374,13 +1374,14 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err } repo := &Repository{ - OwnerID: u.ID, - Owner: u, - Name: opts.Name, - LowerName: strings.ToLower(opts.Name), - Description: opts.Description, - IsPrivate: opts.IsPrivate, - IsFsckEnabled: true, + OwnerID: u.ID, + Owner: u, + Name: opts.Name, + LowerName: strings.ToLower(opts.Name), + Description: opts.Description, + IsPrivate: opts.IsPrivate, + IsFsckEnabled: true, + CloseIssuesViaCommitInAnyBranch: setting.Repository.CloseIssuesViaCommitsInAnyBranch, } sess := x.NewSession() From 98b92a1ecc9c6d6216a540913c4c115b35d508c5 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 9 Feb 2019 12:43:37 +0100 Subject: [PATCH 06/10] allow repo admin toggle feature via UI --- modules/auth/repo_form.go | 5 +++-- options/locale/locale_en-US.ini | 1 + routers/repo/setting.go | 16 +++++++++++----- templates/repo/settings/options.tmpl | 4 ++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 3f5078171a830..38a99077b575e 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -14,7 +14,7 @@ import ( "github.com/Unknwon/com" "github.com/go-macaron/binding" - "gopkg.in/macaron.v1" + macaron "gopkg.in/macaron.v1" ) // _______________________________________ _________.______________________ _______________.___. @@ -120,7 +120,8 @@ type RepoSettingForm struct { IsArchived bool // Admin settings - EnableHealthCheck bool + EnableHealthCheck bool + EnableCloseIssuesViaCommitInAnyBranch bool } // Validate validates the fields diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 5001247e6cb20..e0d5b64cfa859 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1035,6 +1035,7 @@ settings.pulls.allow_rebase_merge_commit = Enable Rebasing with explicit merge c settings.pulls.allow_squash_commits = Enable Squashing to Merge Commits settings.admin_settings = Administrator Settings settings.admin_enable_health_check = Enable Repository Health Checks (git fsck) +settings.admin_enable_close_issues_via_commit_in_any_branch = Close an issue via a commit made in a non default branch settings.danger_zone = Danger Zone settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name. settings.convert = Convert to Regular Repository diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 4fb74f6cfa71e..5b5eaeb288f90 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -250,13 +250,19 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { if repo.IsFsckEnabled != form.EnableHealthCheck { repo.IsFsckEnabled = form.EnableHealthCheck - if err := models.UpdateRepository(repo, false); err != nil { - ctx.ServerError("UpdateRepository", err) - return - } - log.Trace("Repository admin settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name) } + if repo.CloseIssuesViaCommitInAnyBranch != form.EnableCloseIssuesViaCommitInAnyBranch { + repo.CloseIssuesViaCommitInAnyBranch = form.EnableCloseIssuesViaCommitInAnyBranch + } + + if err := models.UpdateRepository(repo, false); err != nil { + ctx.ServerError("UpdateRepository", err) + return + } + + log.Trace("Repository admin settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name) + ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) ctx.Redirect(ctx.Repo.RepoLink + "/settings") diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index e5a3ce0752a03..432f20e74f08b 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -263,6 +263,10 @@ +
+ + +
From 7cb33981209625a5874a9e097d8dfb3601d8b6b4 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 9 Feb 2019 13:06:00 +0100 Subject: [PATCH 07/10] fix typo and improve testcase --- models/action_test.go | 1 + models/migrations/migrations.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/models/action_test.go b/models/action_test.go index 21ab4b85e0f52..96d6ddb6dde0d 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -281,6 +281,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) { Type: CommentTypeCommitRef, CommitSHA: "abcdef1", PosterID: user.ID, + IssueID: 7, } issueBean := &Issue{RepoID: repo.ID, Index: 2, ID: 7} diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index a81536d851fae..174e7b51566f8 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -211,7 +211,7 @@ var migrations = []Migration{ // v78 -> v79 NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty), // v79 -> v80 - NewMigration("add ca close issues via commit in any branch", addCanCloseIssuesViaCommitInAnyBranch), + NewMigration("add can close issues via commit in any branch", addCanCloseIssuesViaCommitInAnyBranch), } // Migrate database to current version From 03c8808dfdc075ac2c4b489e2c3a25c7409b84e3 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 9 Feb 2019 13:14:11 +0100 Subject: [PATCH 08/10] fix fixtures --- models/fixtures/repository.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index a815ba7b668c1..f415761650557 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -17,7 +17,7 @@ lower_name: repo2 name: repo2 is_private: true - num_issues: 1 + num_issues: 2 num_closed_issues: 1 num_pulls: 0 num_closed_pulls: 0 From 8620f5faea7fced18ea2d151469c71a131657590 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sun, 10 Feb 2019 15:07:05 +0100 Subject: [PATCH 09/10] add DEFAULT prefix to config value --- custom/conf/app.ini.sample | 2 +- .../doc/advanced/config-cheat-sheet.en-us.md | 2 +- models/migrations/v79.go | 2 +- models/repo.go | 2 +- modules/setting/setting.go | 44 +++++++++---------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 85f22d675cf33..2f4386dc7dd75 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -37,7 +37,7 @@ ACCESS_CONTROL_ALLOW_ORIGIN = ; Force ssh:// clone url instead of scp-style uri when default SSH port is used USE_COMPAT_SSH_URI = false ; Close issues as long as a commit on any branch marks it as fixed -CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false +DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false [repository.editor] ; List of file extensions for which lines should be wrapped in the CodeMirror editor diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 76cf388ffc4b3..aa3a491d2e11d 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -65,7 +65,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `ACCESS_CONTROL_ALLOW_ORIGIN`: **\**: Value for Access-Control-Allow-Origin header, default is not to present. **WARNING**: This maybe harmful to you website if you do not give it a right value. -- `CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH`: **false**: Close an issue if a commit on a non default branch marks it as closed. +- `DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH`: **false**: Close an issue if a commit on a non default branch marks it as closed. ### Repository - Pull Request (`repository.pull-request`) - `WORK_IN_PROGRESS_PREFIXES`: **WIP:,\[WIP\]**: List of prefixes used in Pull Request diff --git a/models/migrations/v79.go b/models/migrations/v79.go index 77922825a1ca7..e246393957b60 100644 --- a/models/migrations/v79.go +++ b/models/migrations/v79.go @@ -22,6 +22,6 @@ func addCanCloseIssuesViaCommitInAnyBranch(x *xorm.Engine) error { } _, err := x.Exec("UPDATE repository SET close_issues_via_commit_in_any_branch = ?", - setting.Repository.CloseIssuesViaCommitsInAnyBranch) + setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch) return err } diff --git a/models/repo.go b/models/repo.go index b9f84f49e4fbd..848a76fe883b4 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1381,7 +1381,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err Description: opts.Description, IsPrivate: opts.IsPrivate, IsFsckEnabled: !opts.IsMirror, - CloseIssuesViaCommitInAnyBranch: setting.Repository.CloseIssuesViaCommitsInAnyBranch, + CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch, } sess := x.NewSession() diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 4471d740f423e..d3b45ec29d3d9 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -190,17 +190,17 @@ var ( // Repository settings Repository = struct { - AnsiCharset string - ForcePrivate bool - DefaultPrivate string - MaxCreationLimit int - MirrorQueueLength int - PullRequestQueueLength int - PreferredLicenses []string - DisableHTTPGit bool - AccessControlAllowOrigin string - UseCompatSSHURI bool - CloseIssuesViaCommitsInAnyBranch bool + AnsiCharset string + ForcePrivate bool + DefaultPrivate string + MaxCreationLimit int + MirrorQueueLength int + PullRequestQueueLength int + PreferredLicenses []string + DisableHTTPGit bool + AccessControlAllowOrigin string + UseCompatSSHURI bool + DefaultCloseIssuesViaCommitsInAnyBranch bool // Repository editor settings Editor struct { @@ -228,17 +228,17 @@ var ( WorkInProgressPrefixes []string } `ini:"repository.pull-request"` }{ - AnsiCharset: "", - ForcePrivate: false, - DefaultPrivate: RepoCreatingLastUserVisibility, - MaxCreationLimit: -1, - MirrorQueueLength: 1000, - PullRequestQueueLength: 1000, - PreferredLicenses: []string{"Apache License 2.0,MIT License"}, - DisableHTTPGit: false, - AccessControlAllowOrigin: "", - UseCompatSSHURI: false, - CloseIssuesViaCommitsInAnyBranch: false, + AnsiCharset: "", + ForcePrivate: false, + DefaultPrivate: RepoCreatingLastUserVisibility, + MaxCreationLimit: -1, + MirrorQueueLength: 1000, + PullRequestQueueLength: 1000, + PreferredLicenses: []string{"Apache License 2.0,MIT License"}, + DisableHTTPGit: false, + AccessControlAllowOrigin: "", + UseCompatSSHURI: false, + DefaultCloseIssuesViaCommitsInAnyBranch: false, // Repository editor settings Editor: struct { From acad54e734c02f4c7a2968bcbfe788a00b8d9946 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sun, 10 Feb 2019 18:16:43 +0100 Subject: [PATCH 10/10] fix test --- models/issue_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue_test.go b/models/issue_test.go index 3bda3304c367d..cec7e8b4785ce 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -275,7 +275,7 @@ func TestGetUserIssueStats(t *testing.T) { YourRepositoriesCount: 2, AssignCount: 0, CreateCount: 2, - OpenCount: 1, + OpenCount: 2, ClosedCount: 2, }, },