aboutsummaryrefslogtreecommitdiffstats
path: root/models/migrations
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2018-01-05 20:56:50 +0200
committerGitHub <noreply@github.com>2018-01-05 20:56:50 +0200
commit8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9 (patch)
treecf9b661996134da3e39aa6ddd2af4e13f7dbf30f /models/migrations
parenta192f3052ed9b59d1404fdcebf2b5c156d6d6969 (diff)
downloadgitea-8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9.tar.gz
gitea-8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9.zip
Add Pull Request merge options - Ignore white-space for conflict checking, Rebase, Squash merge (#3188)
* Pull request options migration and UI in settings * Add ignore whitespace functionality * Fix settings if pull requests are disabled * Fix migration transaction * Merge with Rebase functionality * UI changes and related functionality for pull request merging button * Implement squash functionality * Fix rebase merging * Fix pull request merge tests * Add squash and rebase tests * Fix API method to reuse default message functions * Some refactoring and small fixes * Remove more hardcoded values from tests * Remove unneeded check from API method * Fix variable name and comment typo * Fix reset commit count after PR merge
Diffstat (limited to 'models/migrations')
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v54.go57
2 files changed, 59 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index cbd09afabf..90f286056f 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -160,6 +160,8 @@ var migrations = []Migration{
NewMigration("add lfs lock table", addLFSLock),
// v53 -> v54
NewMigration("add reactions", addReactions),
+ // v54 -> v55
+ NewMigration("add pull request options", addPullRequestOptions),
}
// Migrate database to current version
diff --git a/models/migrations/v54.go b/models/migrations/v54.go
new file mode 100644
index 0000000000..96c26739c6
--- /dev/null
+++ b/models/migrations/v54.go
@@ -0,0 +1,57 @@
+// Copyright 2017 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 (
+ "fmt"
+
+ "code.gitea.io/gitea/modules/util"
+
+ "github.com/go-xorm/xorm"
+)
+
+func addPullRequestOptions(x *xorm.Engine) error {
+ // RepoUnit describes all units of a repository
+ type RepoUnit struct {
+ ID int64
+ RepoID int64 `xorm:"INDEX(s)"`
+ Type int `xorm:"INDEX(s)"`
+ Config map[string]interface{} `xorm:"JSON"`
+ CreatedUnix util.TimeStamp `xorm:"INDEX CREATED"`
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ //Updating existing issue units
+ units := make([]*RepoUnit, 0, 100)
+ if err := sess.Where("`type` = ?", V16UnitTypePRs).Find(&units); err != nil {
+ return fmt.Errorf("Query repo units: %v", err)
+ }
+ for _, unit := range units {
+ if unit.Config == nil {
+ unit.Config = make(map[string]interface{})
+ }
+ if _, ok := unit.Config["IgnoreWhitespaceConflicts"]; !ok {
+ unit.Config["IgnoreWhitespaceConflicts"] = false
+ }
+ if _, ok := unit.Config["AllowMerge"]; !ok {
+ unit.Config["AllowMerge"] = true
+ }
+ if _, ok := unit.Config["AllowRebase"]; !ok {
+ unit.Config["AllowRebase"] = true
+ }
+ if _, ok := unit.Config["AllowSquash"]; !ok {
+ unit.Config["AllowSquash"] = true
+ }
+ if _, err := sess.ID(unit.ID).Cols("config").Update(unit); err != nil {
+ return err
+ }
+ }
+ return sess.Commit()
+}