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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. const (
  20. v16UnitTypeCode = iota + 1 // 1 code
  21. v16UnitTypeIssues // 2 issues
  22. v16UnitTypePRs // 3 PRs
  23. v16UnitTypeCommits // 4 Commits
  24. v16UnitTypeReleases // 5 Releases
  25. v16UnitTypeWiki // 6 Wiki
  26. v16UnitTypeSettings // 7 Settings
  27. v16UnitTypeExternalWiki // 8 ExternalWiki
  28. v16UnitTypeExternalTracker // 9 ExternalTracker
  29. )
  30. sess := x.NewSession()
  31. defer sess.Close()
  32. if err := sess.Begin(); err != nil {
  33. return err
  34. }
  35. //Updating existing issue units
  36. units := make([]*RepoUnit, 0, 100)
  37. if err := sess.Where("`type` = ?", v16UnitTypePRs).Find(&units); err != nil {
  38. return fmt.Errorf("Query repo units: %v", err)
  39. }
  40. for _, unit := range units {
  41. if unit.Config == nil {
  42. unit.Config = make(map[string]interface{})
  43. }
  44. // Allow the new merge style if all other merge styles are allowed
  45. allowMergeRebase := true
  46. if allowMerge, ok := unit.Config["AllowMerge"]; ok {
  47. allowMergeRebase = allowMergeRebase && allowMerge.(bool)
  48. }
  49. if allowRebase, ok := unit.Config["AllowRebase"]; ok {
  50. allowMergeRebase = allowMergeRebase && allowRebase.(bool)
  51. }
  52. if allowSquash, ok := unit.Config["AllowSquash"]; ok {
  53. allowMergeRebase = allowMergeRebase && allowSquash.(bool)
  54. }
  55. if _, ok := unit.Config["AllowRebaseMerge"]; !ok {
  56. unit.Config["AllowRebaseMerge"] = allowMergeRebase
  57. }
  58. if _, err := sess.ID(unit.ID).Cols("config").Update(unit); err != nil {
  59. return err
  60. }
  61. }
  62. return sess.Commit()
  63. }