You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v76.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/modules/timeutil"
  8. "xorm.io/xorm"
  9. )
  10. func addPullRequestRebaseWithMerge(x *xorm.Engine) error {
  11. // RepoUnit describes all units of a repository
  12. type RepoUnit struct {
  13. ID int64
  14. RepoID int64 `xorm:"INDEX(s)"`
  15. Type int `xorm:"INDEX(s)"`
  16. Config map[string]interface{} `xorm:"JSON"`
  17. CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
  18. }
  19. sess := x.NewSession()
  20. defer sess.Close()
  21. if err := sess.Begin(); err != nil {
  22. return err
  23. }
  24. //Updating existing issue units
  25. units := make([]*RepoUnit, 0, 100)
  26. if err := sess.Where("`type` = ?", V16UnitTypePRs).Find(&units); err != nil {
  27. return fmt.Errorf("Query repo units: %v", err)
  28. }
  29. for _, unit := range units {
  30. if unit.Config == nil {
  31. unit.Config = make(map[string]interface{})
  32. }
  33. // Allow the new merge style if all other merge styles are allowed
  34. allowMergeRebase := true
  35. if allowMerge, ok := unit.Config["AllowMerge"]; ok {
  36. allowMergeRebase = allowMergeRebase && allowMerge.(bool)
  37. }
  38. if allowRebase, ok := unit.Config["AllowRebase"]; ok {
  39. allowMergeRebase = allowMergeRebase && allowRebase.(bool)
  40. }
  41. if allowSquash, ok := unit.Config["AllowSquash"]; ok {
  42. allowMergeRebase = allowMergeRebase && allowSquash.(bool)
  43. }
  44. if _, ok := unit.Config["AllowRebaseMerge"]; !ok {
  45. unit.Config["AllowRebaseMerge"] = allowMergeRebase
  46. }
  47. if _, err := sess.ID(unit.ID).Cols("config").Update(unit); err != nil {
  48. return err
  49. }
  50. }
  51. return sess.Commit()
  52. }