summaryrefslogtreecommitdiffstats
path: root/models/repo_unit.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2018-01-05 20:56:50 +0200
committerGitHub <noreply@github.com>2018-01-05 20:56:50 +0200
commit8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9 (patch)
treecf9b661996134da3e39aa6ddd2af4e13f7dbf30f /models/repo_unit.go
parenta192f3052ed9b59d1404fdcebf2b5c156d6d6969 (diff)
downloadgitea-8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9.tar.gz
gitea-8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9.zip
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
Diffstat (limited to 'models/repo_unit.go')
-rw-r--r--models/repo_unit.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/models/repo_unit.go b/models/repo_unit.go
index 5100ca1ce2..49b62ec9cd 100644
--- a/models/repo_unit.go
+++ b/models/repo_unit.go
@@ -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