mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-02-23 06:50:59 +01:00
(refs #1831) Add default merge strategy setting
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
<changeSet>
|
||||
<addColumn tableName="REPOSITORY">
|
||||
<column name="MERGE_OPTIONS" type="varchar(200)" nullable="false" defaultValue="merge-commit,squash,rebase"/>
|
||||
<column name="DEFAULT_MERGE_OPTION" type="varchar(100)" nullable="false" defaultValue="merge-commit"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
@@ -40,7 +40,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
wikiOption: String,
|
||||
externalWikiUrl: Option[String],
|
||||
allowFork: Boolean,
|
||||
mergeOptions: Seq[String]
|
||||
mergeOptions: Seq[String],
|
||||
defaultMergeOption: String
|
||||
)
|
||||
|
||||
val optionsForm = mapping(
|
||||
@@ -52,15 +53,13 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
"wikiOption" -> trim(label("Wiki Option" , text(required, featureOption))),
|
||||
"externalWikiUrl" -> trim(label("External Wiki URL" , optional(text(maxlength(200))))),
|
||||
"allowFork" -> trim(label("Allow Forking" , boolean())),
|
||||
"mergeOptions" -> new ValueType[Seq[String]]{
|
||||
override def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[String] =
|
||||
params.get("mergeOptions").getOrElse(Nil)
|
||||
override def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] =
|
||||
if(params.get("mergeOptions").getOrElse(Nil).isEmpty) Seq("mergeOptions" -> "At least one option must be enabled.") else Nil
|
||||
},
|
||||
)(OptionsForm.apply)
|
||||
|
||||
|
||||
"mergeOptions" -> mergeOptions,
|
||||
"defaultMergeOption" -> trim(label("Default merge strategy", text(required)))
|
||||
)(OptionsForm.apply).verifying { form =>
|
||||
if(!form.mergeOptions.contains(form.defaultMergeOption)){
|
||||
Seq("defaultMergeOption" -> s"This merge strategy isn't enabled.")
|
||||
} else Nil
|
||||
}
|
||||
|
||||
// for default branch
|
||||
case class DefaultBranchForm(defaultBranch: String)
|
||||
@@ -128,7 +127,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
form.wikiOption,
|
||||
form.externalWikiUrl,
|
||||
form.allowFork,
|
||||
form.mergeOptions
|
||||
form.mergeOptions,
|
||||
form.defaultMergeOption
|
||||
)
|
||||
// Change repository name
|
||||
if(repository.name != form.repositoryName){
|
||||
@@ -509,4 +509,21 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def mergeOptions = new ValueType[Seq[String]]{
|
||||
override def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[String] = {
|
||||
params.get("mergeOptions").getOrElse(Nil)
|
||||
}
|
||||
override def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] = {
|
||||
val mergeOptions = params.get("mergeOptions").getOrElse(Nil)
|
||||
if(mergeOptions.isEmpty){
|
||||
Seq("mergeOptions" -> "At least one option must be enabled.")
|
||||
} else if(!mergeOptions.forall(x => Seq("merge-commit", "squash", "rebase").contains(x))){
|
||||
Seq("mergeOptions" -> "mergeOptions are invalid.")
|
||||
} else {
|
||||
Nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,11 +23,12 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
||||
val externalWikiUrl = column[String]("EXTERNAL_WIKI_URL")
|
||||
val allowFork = column[Boolean]("ALLOW_FORK")
|
||||
val mergeOptions = column[String]("MERGE_OPTIONS")
|
||||
val defaultMergeOption = column[String]("DEFAULT_MERGE_OPTION")
|
||||
|
||||
def * = (
|
||||
(userName, repositoryName, isPrivate, description.?, defaultBranch,
|
||||
registeredDate, updatedDate, lastActivityDate, originUserName.?, originRepositoryName.?, parentUserName.?, parentRepositoryName.?),
|
||||
(issuesOption, externalIssuesUrl.?, wikiOption, externalWikiUrl.?, allowFork, mergeOptions)
|
||||
(issuesOption, externalIssuesUrl.?, wikiOption, externalWikiUrl.?, allowFork, mergeOptions, defaultMergeOption)
|
||||
).shaped <> (
|
||||
{ case (repository, options) =>
|
||||
Repository(
|
||||
@@ -90,5 +91,6 @@ case class RepositoryOptions(
|
||||
wikiOption: String,
|
||||
externalWikiUrl: Option[String],
|
||||
allowFork: Boolean,
|
||||
mergeOptions: String
|
||||
mergeOptions: String,
|
||||
defaultMergeOption: String
|
||||
)
|
||||
|
||||
@@ -47,7 +47,8 @@ trait RepositoryService { self: AccountService =>
|
||||
wikiOption = "PUBLIC", // TODO DISABLE for the forked repository?
|
||||
externalWikiUrl = None,
|
||||
allowFork = true,
|
||||
mergeOptions = "merge-commit,squash,rebase"
|
||||
mergeOptions = "merge-commit,squash,rebase",
|
||||
defaultMergeOption = "merge-commit"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -365,7 +366,7 @@ trait RepositoryService { self: AccountService =>
|
||||
*/
|
||||
def saveRepositoryOptions(userName: String, repositoryName: String, description: Option[String], isPrivate: Boolean,
|
||||
issuesOption: String, externalIssuesUrl: Option[String], wikiOption: String, externalWikiUrl: Option[String],
|
||||
allowFork: Boolean, mergeOptions: Seq[String])(implicit s: Session): Unit = {
|
||||
allowFork: Boolean, mergeOptions: Seq[String], defaultMergeOption: String)(implicit s: Session): Unit = {
|
||||
|
||||
Repositories.filter(_.byRepository(userName, repositoryName))
|
||||
.map { r => (
|
||||
@@ -377,6 +378,7 @@ trait RepositoryService { self: AccountService =>
|
||||
r.externalWikiUrl.?,
|
||||
r.allowFork,
|
||||
r.mergeOptions,
|
||||
r.defaultMergeOption,
|
||||
r.updatedDate
|
||||
) }
|
||||
.update (
|
||||
@@ -388,6 +390,7 @@ trait RepositoryService { self: AccountService =>
|
||||
externalWikiUrl,
|
||||
allowFork,
|
||||
mergeOptions.mkString(","),
|
||||
defaultMergeOption,
|
||||
currentDate
|
||||
)
|
||||
}
|
||||
|
||||
@@ -143,48 +143,48 @@
|
||||
<span id="error-message" class="error"></span>
|
||||
<textarea name="message" style="height: 80px; margin-top: 8px; margin-bottom: 8px;" class="form-control">@issue.title</textarea>
|
||||
<div>
|
||||
@defining(originRepository.repository.options.mergeOptions.split(",")){ mergeOptions =>
|
||||
<div class="btn-group">
|
||||
<button id="merge-strategy-btn" class="dropdown-toggle btn btn-default" data-toggle="dropdown">
|
||||
<span class="strong">
|
||||
@(if(mergeOptions.contains("merge-commit")) "Merge commit"
|
||||
else if(mergeOptions.contains("squash")) "Squash"
|
||||
else if(mergeOptions.contains("rebase")) "Rebase")
|
||||
@(Map(
|
||||
"merge-commit" -> "Merge commit",
|
||||
"squash" -> "Squash",
|
||||
"rebase" -> "Rebase"
|
||||
)(originRepository.repository.options.defaultMergeOption))
|
||||
</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
@if(mergeOptions.contains("merge-commit")){
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="merge-strategy" data-value="merge-commit">
|
||||
<strong>Merge commit</strong><br>These commits will be added to the base branch via a merge commit.
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
@if(mergeOptions.contains("squash")){
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="merge-strategy" data-value="squash">
|
||||
<strong>Squash</strong><br>These commits will be combined into one commit in the base branch.
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
@if(mergeOptions.contains("rebase")){
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="merge-strategy" data-value="rebase">
|
||||
<strong>Rebase</strong><br>These commits will be rebased and added to the base branch.
|
||||
</a>
|
||||
</li>
|
||||
@defining(originRepository.repository.options.mergeOptions.split(",")){ mergeOptions =>
|
||||
@if(mergeOptions.contains("merge-commit")){
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="merge-strategy" data-value="merge-commit">
|
||||
<strong>Merge commit</strong><br>These commits will be added to the base branch via a merge commit.
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
@if(mergeOptions.contains("squash")){
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="merge-strategy" data-value="squash">
|
||||
<strong>Squash</strong><br>These commits will be combined into one commit in the base branch.
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
@if(mergeOptions.contains("rebase")){
|
||||
<li>
|
||||
<a href="javascript:void(0);" class="merge-strategy" data-value="rebase">
|
||||
<strong>Rebase</strong><br>These commits will be rebased and added to the base branch.
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<input type="button" class="btn btn-default" value="Cancel" id="cancel-merge-pull-request"/>
|
||||
<input type="submit" class="btn btn-success" value="Confirm merge"/>
|
||||
<input type="hidden" name="strategy" value="@(if(mergeOptions.contains("merge-commit")) "merge-commit"
|
||||
else if(mergeOptions.contains("squash")) "squash"
|
||||
else if(mergeOptions.contains("rebase")) "rebase")"/>
|
||||
<input type="hidden" name="strategy" value="@originRepository.repository.options.defaultMergeOption"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -117,30 +117,39 @@
|
||||
<div class="panel-body">
|
||||
Select pull request merge strategies which are available in this repository. At least one option must be enabled.
|
||||
<fieldset class="form-group">
|
||||
@defining(repository.repository.options.mergeOptions.split(",")){ mergeOptions =>
|
||||
<div class="checkbox">
|
||||
<label for="mergeOptions_MergeCommit">
|
||||
<input type="checkbox" name="mergeOptions" id="mergeOptions_MergeCommit" value="merge-commit" @if(mergeOptions.contains("merge-commit")){checked}>
|
||||
<span class="strong">Merge commit</span>
|
||||
<div class="normal muted">Commits will be added to the base branch via a merge commit.</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label for="mergeOptions_Squash">
|
||||
<input type="checkbox" name="mergeOptions" id="mergeOptions_Squash" value="squash" @if(mergeOptions.contains("squash")){checked}>
|
||||
<span class="strong">Squash</span>
|
||||
<div class="normal muted">Commits will be combined into one commit in the base branch.</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label for="mergeOptions_Rebase">
|
||||
<input type="checkbox" name="mergeOptions" id="mergeOptions_Rebase" value="rebase" @if(mergeOptions.contains("rebase")){checked}>
|
||||
<span class="strong">Rebase</span>
|
||||
<div class="normal muted">Commits will be rebased and added to the base branch.</div>
|
||||
</label>
|
||||
</div>
|
||||
<span id="error-mergeOptions" class="error"></span>
|
||||
}
|
||||
@defining(repository.repository.options.mergeOptions.split(",")){ mergeOptions =>
|
||||
<div class="checkbox">
|
||||
<label for="mergeOptions_MergeCommit">
|
||||
<input type="checkbox" name="mergeOptions" id="mergeOptions_MergeCommit" value="merge-commit" @if(mergeOptions.contains("merge-commit")){checked}>
|
||||
<span class="strong">Merge commit</span>
|
||||
<div class="normal muted">Commits will be added to the base branch via a merge commit.</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label for="mergeOptions_Squash">
|
||||
<input type="checkbox" name="mergeOptions" id="mergeOptions_Squash" value="squash" @if(mergeOptions.contains("squash")){checked}>
|
||||
<span class="strong">Squash</span>
|
||||
<div class="normal muted">Commits will be combined into one commit in the base branch.</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label for="mergeOptions_Rebase">
|
||||
<input type="checkbox" name="mergeOptions" id="mergeOptions_Rebase" value="rebase" @if(mergeOptions.contains("rebase")){checked}>
|
||||
<span class="strong">Rebase</span>
|
||||
<div class="normal muted">Commits will be rebased and added to the base branch.</div>
|
||||
</label>
|
||||
</div>
|
||||
<span id="error-mergeOptions" class="error"></span>
|
||||
}
|
||||
<fieldset class="form-group">
|
||||
<label for="defaultMergeOption">Default merge strategy</label>
|
||||
<select name="defaultMergeOption" id="defaultMergeOption">
|
||||
<option value="merge-commit">Merge commit</option>
|
||||
<option value="squash">Squash</option>
|
||||
<option value="rebase">Rebase</option>
|
||||
</select>
|
||||
<span id="error-defaultMergeOption" class="error"></span>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user