mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add Pull Request merge options - Ignore white-space for conflict checking, Rebase, Squash merge (#3188)
* Pull request options migration and UI in settings * Add ignore whitespace functionality * Fix settings if pull requests are disabled * Fix migration transaction * Merge with Rebase functionality * UI changes and related functionality for pull request merging button * Implement squash functionality * Fix rebase merging * Fix pull request merge tests * Add squash and rebase tests * Fix API method to reuse default message functions * Some refactoring and small fixes * Remove more hardcoded values from tests * Remove unneeded check from API method * Fix variable name and comment typo * Fix reset commit count after PR merge
This commit is contained in:
@@ -85,18 +85,44 @@ func (cfg *IssuesConfig) ToDB() ([]byte, error) {
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
// PullRequestsConfig describes pull requests config
|
||||
type PullRequestsConfig struct {
|
||||
IgnoreWhitespaceConflicts bool
|
||||
AllowMerge bool
|
||||
AllowRebase bool
|
||||
AllowSquash bool
|
||||
}
|
||||
|
||||
// FromDB fills up a PullRequestsConfig from serialized format.
|
||||
func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a PullRequestsConfig to a serialized format.
|
||||
func (cfg *PullRequestsConfig) ToDB() ([]byte, error) {
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
// IsMergeStyleAllowed returns if merge style is allowed
|
||||
func (cfg *PullRequestsConfig) IsMergeStyleAllowed(mergeStyle MergeStyle) bool {
|
||||
return mergeStyle == MergeStyleMerge && cfg.AllowMerge ||
|
||||
mergeStyle == MergeStyleRebase && cfg.AllowRebase ||
|
||||
mergeStyle == MergeStyleSquash && cfg.AllowSquash
|
||||
}
|
||||
|
||||
// BeforeSet is invoked from XORM before setting the value of a field of this object.
|
||||
func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
|
||||
switch colName {
|
||||
case "type":
|
||||
switch UnitType(Cell2Int64(val)) {
|
||||
case UnitTypeCode, UnitTypePullRequests, UnitTypeReleases,
|
||||
UnitTypeWiki:
|
||||
case UnitTypeCode, UnitTypeReleases, UnitTypeWiki:
|
||||
r.Config = new(UnitConfig)
|
||||
case UnitTypeExternalWiki:
|
||||
r.Config = new(ExternalWikiConfig)
|
||||
case UnitTypeExternalTracker:
|
||||
r.Config = new(ExternalTrackerConfig)
|
||||
case UnitTypePullRequests:
|
||||
r.Config = new(PullRequestsConfig)
|
||||
case UnitTypeIssues:
|
||||
r.Config = new(IssuesConfig)
|
||||
default:
|
||||
@@ -116,8 +142,8 @@ func (r *RepoUnit) CodeConfig() *UnitConfig {
|
||||
}
|
||||
|
||||
// PullRequestsConfig returns config for UnitTypePullRequests
|
||||
func (r *RepoUnit) PullRequestsConfig() *UnitConfig {
|
||||
return r.Config.(*UnitConfig)
|
||||
func (r *RepoUnit) PullRequestsConfig() *PullRequestsConfig {
|
||||
return r.Config.(*PullRequestsConfig)
|
||||
}
|
||||
|
||||
// ReleasesConfig returns config for UnitTypeReleases
|
||||
|
Reference in New Issue
Block a user