2018-12-27 05:27:08 -05:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2018-12-27 05:27:08 -05:00
|
|
|
|
2022-12-08 03:21:37 -05:00
|
|
|
package v1_8 //nolint
|
2018-12-27 05:27:08 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-08-15 10:46:21 -04:00
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
2018-12-27 05:27:08 -05:00
|
|
|
|
2019-10-17 05:26:49 -04:00
|
|
|
"xorm.io/xorm"
|
2018-12-27 05:27:08 -05:00
|
|
|
)
|
|
|
|
|
2022-11-02 04:54:36 -04:00
|
|
|
func AddPullRequestRebaseWithMerge(x *xorm.Engine) error {
|
2018-12-27 05:27:08 -05:00
|
|
|
// RepoUnit describes all units of a repository
|
|
|
|
type RepoUnit struct {
|
|
|
|
ID int64
|
2023-07-04 23:41:32 -04:00
|
|
|
RepoID int64 `xorm:"INDEX(s)"`
|
|
|
|
Type int `xorm:"INDEX(s)"`
|
|
|
|
Config map[string]any `xorm:"JSON"`
|
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
|
2018-12-27 05:27:08 -05:00
|
|
|
}
|
|
|
|
|
2020-01-31 08:42:45 -05:00
|
|
|
const (
|
|
|
|
v16UnitTypeCode = iota + 1 // 1 code
|
|
|
|
v16UnitTypeIssues // 2 issues
|
|
|
|
v16UnitTypePRs // 3 PRs
|
|
|
|
v16UnitTypeCommits // 4 Commits
|
|
|
|
v16UnitTypeReleases // 5 Releases
|
|
|
|
v16UnitTypeWiki // 6 Wiki
|
|
|
|
v16UnitTypeSettings // 7 Settings
|
|
|
|
v16UnitTypeExternalWiki // 8 ExternalWiki
|
|
|
|
v16UnitTypeExternalTracker // 9 ExternalTracker
|
|
|
|
)
|
|
|
|
|
2018-12-27 05:27:08 -05:00
|
|
|
sess := x.NewSession()
|
|
|
|
defer sess.Close()
|
|
|
|
if err := sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-14 14:52:12 -04:00
|
|
|
// Updating existing issue units
|
2018-12-27 05:27:08 -05:00
|
|
|
units := make([]*RepoUnit, 0, 100)
|
2020-01-31 08:42:45 -05:00
|
|
|
if err := sess.Where("`type` = ?", v16UnitTypePRs).Find(&units); err != nil {
|
2022-10-24 15:29:17 -04:00
|
|
|
return fmt.Errorf("Query repo units: %w", err)
|
2018-12-27 05:27:08 -05:00
|
|
|
}
|
|
|
|
for _, unit := range units {
|
|
|
|
if unit.Config == nil {
|
2023-07-04 23:41:32 -04:00
|
|
|
unit.Config = make(map[string]any)
|
2018-12-27 05:27:08 -05:00
|
|
|
}
|
|
|
|
// 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()
|
|
|
|
}
|