mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-07 10:55:22 +02:00
Merge branch 'forgejo' into repocard
This commit is contained in:
commit
a82cd18d9a
119 changed files with 6915 additions and 2391 deletions
|
@ -29,6 +29,15 @@ const (
|
|||
MergeStyleRebaseUpdate MergeStyle = "rebase-update-only"
|
||||
)
|
||||
|
||||
type UpdateStyle string
|
||||
|
||||
const (
|
||||
// UpdateStyleMerge create merge commit to update
|
||||
UpdateStyleMerge UpdateStyle = "merge"
|
||||
// UpdateStyleRebase rebase to update
|
||||
UpdateStyleRebase UpdateStyle = "rebase"
|
||||
)
|
||||
|
||||
// UpdateDefaultBranch updates the default branch
|
||||
func UpdateDefaultBranch(ctx context.Context, repo *Repository) error {
|
||||
_, err := db.GetEngine(ctx).ID(repo.ID).Cols("default_branch").Update(repo)
|
||||
|
|
|
@ -159,6 +159,7 @@ type PullRequestsConfig struct {
|
|||
AllowRebaseUpdate bool
|
||||
DefaultDeleteBranchAfterMerge bool
|
||||
DefaultMergeStyle MergeStyle
|
||||
DefaultUpdateStyle UpdateStyle
|
||||
DefaultAllowMaintainerEdit bool
|
||||
}
|
||||
|
||||
|
@ -197,6 +198,25 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
|
|||
return MergeStyleMerge
|
||||
}
|
||||
|
||||
// IsUpdateStyleAllowed returns if update style is allowed
|
||||
func (cfg *PullRequestsConfig) IsUpdateStyleAllowed(updateStyle UpdateStyle) bool {
|
||||
return updateStyle == UpdateStyleMerge ||
|
||||
updateStyle == UpdateStyleRebase && cfg.AllowRebaseUpdate
|
||||
}
|
||||
|
||||
// GetDefaultUpdateStyle returns the default update style for this pull request
|
||||
func (cfg *PullRequestsConfig) GetDefaultUpdateStyle() UpdateStyle {
|
||||
if len(cfg.DefaultUpdateStyle) != 0 {
|
||||
return cfg.DefaultUpdateStyle
|
||||
}
|
||||
|
||||
if setting.Repository.PullRequest.DefaultUpdateStyle != "" {
|
||||
return UpdateStyle(setting.Repository.PullRequest.DefaultUpdateStyle)
|
||||
}
|
||||
|
||||
return UpdateStyleMerge
|
||||
}
|
||||
|
||||
type ActionsConfig struct {
|
||||
DisabledWorkflows []string
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -37,3 +39,50 @@ func TestRepoUnitAccessMode(t *testing.T) {
|
|||
assert.Equal(t, perm.AccessModeWrite, UnitAccessModeWrite.ToAccessMode(perm.AccessModeAdmin))
|
||||
assert.Equal(t, perm.AccessModeRead, UnitAccessModeUnset.ToAccessMode(perm.AccessModeRead))
|
||||
}
|
||||
|
||||
func TestRepoPRIsUpdateStyleAllowed(t *testing.T) {
|
||||
var cfg PullRequestsConfig
|
||||
cfg = PullRequestsConfig{
|
||||
AllowRebaseUpdate: true,
|
||||
}
|
||||
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleMerge))
|
||||
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleRebase))
|
||||
|
||||
cfg = PullRequestsConfig{
|
||||
AllowRebaseUpdate: false,
|
||||
}
|
||||
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleMerge))
|
||||
assert.False(t, cfg.IsUpdateStyleAllowed(UpdateStyleRebase))
|
||||
}
|
||||
|
||||
func TestRepoPRGetDefaultUpdateStyle(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultUpdateStyle, "merge")()
|
||||
|
||||
var cfg PullRequestsConfig
|
||||
cfg = PullRequestsConfig{
|
||||
DefaultUpdateStyle: "",
|
||||
}
|
||||
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
||||
cfg = PullRequestsConfig{
|
||||
DefaultUpdateStyle: "rebase",
|
||||
}
|
||||
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
||||
cfg = PullRequestsConfig{
|
||||
DefaultUpdateStyle: "merge",
|
||||
}
|
||||
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
||||
|
||||
setting.Repository.PullRequest.DefaultUpdateStyle = "rebase"
|
||||
cfg = PullRequestsConfig{
|
||||
DefaultUpdateStyle: "",
|
||||
}
|
||||
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
||||
cfg = PullRequestsConfig{
|
||||
DefaultUpdateStyle: "rebase",
|
||||
}
|
||||
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
||||
cfg = PullRequestsConfig{
|
||||
DefaultUpdateStyle: "merge",
|
||||
}
|
||||
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue