diff options
author | Julian <julian.toelle97@gmail.com> | 2018-12-27 11:27:08 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-12-27 12:27:08 +0200 |
commit | 4a685f8b872a3d4c101c5e8165fa99e696c8fb45 (patch) | |
tree | 7ad36ee9bf87cec61ee0967a50037d9331d2ab58 /models/migrations | |
parent | 58bdff53cd98e33791f91584d02887864aabc5c4 (diff) | |
download | gitea-4a685f8b872a3d4c101c5e8165fa99e696c8fb45.tar.gz gitea-4a685f8b872a3d4c101c5e8165fa99e696c8fb45.zip |
Add rebase with merge commit merge style (#3844) (#4052)
Signed-off-by: Julian Tölle <julian.toelle97@gmail.com>
Diffstat (limited to 'models/migrations')
-rw-r--r-- | models/migrations/migrations.go | 2 | ||||
-rw-r--r-- | models/migrations/v76.go | 63 |
2 files changed, 65 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 5a9c80a829..1fa94c42aa 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -204,6 +204,8 @@ var migrations = []Migration{ NewMigration("add approval whitelists to protected branches", addApprovalWhitelistsToProtectedBranches), // v75 -> v76 NewMigration("clear nonused data which not deleted when user was deleted", clearNonusedData), + // v76 -> v77 + NewMigration("add pull request rebase with merge commit", addPullRequestRebaseWithMerge), } // Migrate database to current version diff --git a/models/migrations/v76.go b/models/migrations/v76.go new file mode 100644 index 0000000000..efab7e0cf0 --- /dev/null +++ b/models/migrations/v76.go @@ -0,0 +1,63 @@ +// Copyright 2018 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 addPullRequestRebaseWithMerge(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{}) + } + // Allow the new merge style if all other merge styles are allowed + allowMergeRebase := true + + if allowMerge, ok := unit.Config["AllowMerge"]; ok { + allowMergeRebase = allowMergeRebase && allowMerge.(bool) + } + + if allowRebase, ok := unit.Config["AllowRebase"]; ok { + allowMergeRebase = allowMergeRebase && allowRebase.(bool) + } + + if allowSquash, ok := unit.Config["AllowSquash"]; ok { + allowMergeRebase = allowMergeRebase && allowSquash.(bool) + } + + if _, ok := unit.Config["AllowRebaseMerge"]; !ok { + unit.Config["AllowRebaseMerge"] = allowMergeRebase + } + if _, err := sess.ID(unit.ID).Cols("config").Update(unit); err != nil { + return err + } + } + return sess.Commit() +} |