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.

v54.go 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2017 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 addPullRequestOptions(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. if _, ok := unit.Config["IgnoreWhitespaceConflicts"]; !ok {
  34. unit.Config["IgnoreWhitespaceConflicts"] = false
  35. }
  36. if _, ok := unit.Config["AllowMerge"]; !ok {
  37. unit.Config["AllowMerge"] = true
  38. }
  39. if _, ok := unit.Config["AllowRebase"]; !ok {
  40. unit.Config["AllowRebase"] = true
  41. }
  42. if _, ok := unit.Config["AllowSquash"]; !ok {
  43. unit.Config["AllowSquash"] = true
  44. }
  45. if _, err := sess.ID(unit.ID).Cols("config").Update(unit); err != nil {
  46. return err
  47. }
  48. }
  49. return sess.Commit()
  50. }