From 58078989f81a4369ecb83817fe63ba660d674fd3 Mon Sep 17 00:00:00 2001
From: Naoki Takezoe
Date: Sun, 17 Jan 2016 00:21:32 +0900
Subject: [PATCH] Small fix about code style
---
.../RepositorySettingsController.scala | 8 ++--
.../core/service/CommitStatusService.scala | 47 ++++++++++---------
.../gitbucket/core/service/MergeService.scala | 12 ++---
.../service/ProtectedBrancheService.scala | 11 +++--
.../core/servlet/GitRepositoryServlet.scala | 3 +-
.../core/settings/branches.scala.html | 16 ++++---
.../core/settings/branchprotection.scala.html | 12 ++---
7 files changed, 58 insertions(+), 51 deletions(-)
diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala
index 1db2f5d03..ac6bd8265 100644
--- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala
+++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala
@@ -116,7 +116,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
post("/:owner/:repository/settings/update_default_branch", defaultBranchForm)(ownerOnly { (form, repository) =>
if(repository.branchList.find(_ == form.defaultBranch).isEmpty){
redirect(s"/${repository.owner}/${repository.name}/settings/options")
- }else{
+ } else {
saveRepositoryDefaultBranch(repository.owner, repository.name, form.defaultBranch)
// Change repository HEAD
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
@@ -133,13 +133,13 @@ trait RepositorySettingsControllerBase extends ControllerBase {
val branch = params("branch")
if(repository.branchList.find(_ == branch).isEmpty){
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
- }else{
+ } else {
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))
val lastWeeks = getRecentStatuesContexts(repository.owner, repository.name, org.joda.time.LocalDateTime.now.minusWeeks(1).toDate).toSet
val knownContexts = (lastWeeks ++ protection.status.contexts).toSeq.sortBy(identity)
html.branchprotection(repository, branch, protection, knownContexts, flash.get("info"))
}
- });
+ })
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
patch("/api/v3/repos/:owner/:repo/branches/:branch")(ownerOnly { repository =>
@@ -150,7 +150,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
} yield {
if(protection.enabled){
enableBranchProtection(repository.owner, repository.name, branch, protection.status.enforcement_level == ApiBranchProtection.Everyone, protection.status.contexts)
- }else{
+ } else {
disableBranchProtection(repository.owner, repository.name, branch)
}
JsonFormat(ApiBranch(branch, protection)(RepositoryName(repository)))
diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala
index 411aeea18..ae613ffbb 100644
--- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala
+++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala
@@ -12,33 +12,35 @@ import gitbucket.core.model.Profile.dateColumnType
trait CommitStatusService {
/** insert or update */
- def createCommitStatus(userName: String, repositoryName: String, sha:String, context:String, state:CommitState, targetUrl:Option[String], description:Option[String], now:java.util.Date, creator:Account)(implicit s: Session): Int =
- CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context===context.bind )
+ def createCommitStatus(userName: String, repositoryName: String, sha: String, context: String, state: CommitState,
+ targetUrl: Option[String], description: Option[String], now: java.util.Date, creator: Account)(implicit s: Session): Int =
+ CommitStatuses
+ .filter(t => t.byCommit(userName, repositoryName, sha) && t.context === context.bind )
.map(_.commitStatusId).firstOption match {
- case Some(id:Int) => {
- CommitStatuses.filter(_.byPrimaryKey(id)).map{
- t => (t.state , t.targetUrl , t.updatedDate , t.creator, t.description)
- }.update( (state, targetUrl, now, creator.userName, description) )
- id
- }
- case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) += CommitStatus(
- userName = userName,
- repositoryName = repositoryName,
- commitId = sha,
- context = context,
- state = state,
- targetUrl = targetUrl,
- description = description,
- creator = creator.userName,
- registeredDate = now,
- updatedDate = now)
+ case Some(id: Int) => {
+ CommitStatuses.filter(_.byPrimaryKey(id)).map { t =>
+ (t.state , t.targetUrl , t.updatedDate , t.creator, t.description)
+ }.update((state, targetUrl, now, creator.userName, description))
+ id
+ }
+ case None => (CommitStatuses returning CommitStatuses.map(_.commitStatusId)) += CommitStatus(
+ userName = userName,
+ repositoryName = repositoryName,
+ commitId = sha,
+ context = context,
+ state = state,
+ targetUrl = targetUrl,
+ description = description,
+ creator = creator.userName,
+ registeredDate = now,
+ updatedDate = now)
}
def getCommitStatus(userName: String, repositoryName: String, id: Int)(implicit s: Session) :Option[CommitStatus] =
CommitStatuses.filter(t => t.byPrimaryKey(id) && t.byRepository(userName, repositoryName)).firstOption
def getCommitStatus(userName: String, repositoryName: String, sha: String, context: String)(implicit s: Session) :Option[CommitStatus] =
- CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context===context.bind ).firstOption
+ CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) && t.context === context.bind).firstOption
def getCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) :List[CommitStatus] =
byCommitStatues(userName, repositoryName, sha).list
@@ -47,10 +49,9 @@ trait CommitStatusService {
CommitStatuses.filter(t => t.byRepository(userName, repositoryName)).filter(t => t.updatedDate > time.bind).groupBy(_.context).map(_._1).list
def getCommitStatuesWithCreator(userName: String, repositoryName: String, sha: String)(implicit s: Session) :List[(CommitStatus, Account)] =
- byCommitStatues(userName, repositoryName, sha).innerJoin(Accounts)
- .filter{ case (t,a) => t.creator === a.userName }.list
+ byCommitStatues(userName, repositoryName, sha).innerJoin(Accounts).filter { case (t, a) => t.creator === a.userName }.list
protected def byCommitStatues(userName: String, repositoryName: String, sha: String)(implicit s: Session) =
- CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha) ).sortBy(_.updatedDate desc)
+ CommitStatuses.filter(t => t.byCommit(userName, repositoryName, sha)).sortBy(_.updatedDate desc)
}
\ No newline at end of file
diff --git a/src/main/scala/gitbucket/core/service/MergeService.scala b/src/main/scala/gitbucket/core/service/MergeService.scala
index f09211c8f..d427d1714 100644
--- a/src/main/scala/gitbucket/core/service/MergeService.scala
+++ b/src/main/scala/gitbucket/core/service/MergeService.scala
@@ -70,7 +70,7 @@ trait MergeService {
try {
if(merger.merge(mergeBaseTip, mergeTip)){
Some((merger.getResultTreeId, mergeBaseTip, mergeTip))
- }else{
+ } else {
None
}
} catch {
@@ -139,17 +139,17 @@ object MergeService{
lazy val mergeTip = repository.resolve(s"refs/pull/${issueId}/head")
def checkConflictCache(): Option[Boolean] = {
Option(repository.resolve(mergedBranchName)).flatMap{ merged =>
- if(parseCommit( merged ).getParents().toSet == Set( mergeBaseTip, mergeTip )){
+ if(parseCommit(merged).getParents().toSet == Set( mergeBaseTip, mergeTip )){
// merged branch exists
Some(false)
- }else{
+ } else {
None
}
}.orElse(Option(repository.resolve(conflictedBranchName)).flatMap{ conflicted =>
- if(parseCommit( conflicted ).getParents().toSet == Set( mergeBaseTip, mergeTip )){
+ if(parseCommit(conflicted).getParents().toSet == Set( mergeBaseTip, mergeTip )){
// conflict branch exists
Some(true)
- }else{
+ } else {
None
}
})
@@ -174,7 +174,7 @@ object MergeService{
if(!conflicted){
updateBranch(merger.getResultTreeId, s"Merge ${mergeTip.name} into ${mergeBaseTip.name}", mergedBranchName)
git.branchDelete().setForce(true).setBranchNames(conflictedBranchName).call()
- }else{
+ } else {
updateBranch(mergeTipCommit.getTree().getId(), s"can't merge ${mergeTip.name} into ${mergeBaseTip.name}", conflictedBranchName)
git.branchDelete().setForce(true).setBranchNames(mergedBranchName).call()
}
diff --git a/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala b/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala
index cfbe9e321..97652aeae 100644
--- a/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala
+++ b/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala
@@ -31,7 +31,8 @@ trait ProtectedBrancheService {
def getProtectedBranchList(owner: String, repository: String)(implicit session: Session): List[String] =
ProtectedBranches.filter(_.byRepository(owner, repository)).map(_.branch).list
- def enableBranchProtection(owner: String, repository: String, branch:String, includeAdministrators: Boolean, contexts: Seq[String])(implicit session: Session): Unit = {
+ def enableBranchProtection(owner: String, repository: String, branch:String, includeAdministrators: Boolean, contexts: Seq[String])
+ (implicit session: Session): Unit = {
disableBranchProtection(owner, repository, branch)
ProtectedBranches.insert(new ProtectedBranch(owner, repository, branch, includeAdministrators && contexts.nonEmpty))
contexts.map{ context =>
@@ -42,11 +43,12 @@ trait ProtectedBrancheService {
def disableBranchProtection(owner: String, repository: String, branch:String)(implicit session: Session): Unit =
ProtectedBranches.filter(_.byPrimaryKey(owner, repository, branch)).delete
- def getBranchProtectedReason(owner: String, repository: String, isAllowNonFastForwards: Boolean, command: ReceiveCommand, pusher: String)(implicit session: Session): Option[String] = {
+ def getBranchProtectedReason(owner: String, repository: String, isAllowNonFastForwards: Boolean, command: ReceiveCommand, pusher: String)
+ (implicit session: Session): Option[String] = {
val branch = command.getRefName.stripPrefix("refs/heads/")
if(branch != command.getRefName){
getProtectedBranchInfo(owner, repository, branch).getStopReason(isAllowNonFastForwards, command, pusher)
- }else{
+ } else {
None
}
}
@@ -69,7 +71,8 @@ object ProtectedBrancheService {
*/
includeAdministrators: Boolean) extends AccountService with CommitStatusService {
- def isAdministrator(pusher: String)(implicit session: Session): Boolean = pusher == owner || getGroupMembers(owner).filter(gm => gm.userName == pusher && gm.isManager).nonEmpty
+ def isAdministrator(pusher: String)(implicit session: Session): Boolean =
+ pusher == owner || getGroupMembers(owner).filter(gm => gm.userName == pusher && gm.isManager).nonEmpty
/**
* Can't be force pushed
diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala
index f92207c50..eb9a26349 100644
--- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala
+++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala
@@ -119,7 +119,8 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
def onPreReceive(receivePack: ReceivePack, commands: java.util.Collection[ReceiveCommand]): Unit = {
try {
commands.asScala.foreach { command =>
- getBranchProtectedReason(owner, repository, receivePack.isAllowNonFastForwards, command, pusher).map{ reason =>
+
+ getBranchProtectedReason(owner, repository, receivePack.isAllowNonFastForwards, command, pusher).map { reason =>
command.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, reason)
}
}
diff --git a/src/main/twirl/gitbucket/core/settings/branches.scala.html b/src/main/twirl/gitbucket/core/settings/branches.scala.html
index eb4df5157..ba6e77d18 100644
--- a/src/main/twirl/gitbucket/core/settings/branches.scala.html
+++ b/src/main/twirl/gitbucket/core/settings/branches.scala.html
@@ -49,13 +49,15 @@
- @protectedBranchList.map{ branch =>
- |
- @branch
-
- Edit
-
- |
+ @protectedBranchList.map { branch =>
+
+ |
+ @branch
+
+ Edit
+
+ |
+
}
diff --git a/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html b/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html
index 853b575f4..41855ee95 100644
--- a/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html
+++ b/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html
@@ -45,11 +45,11 @@
Status checks found in the last week for this repository
-
+
@@ -70,7 +70,7 @@ function getValue(){
$("input[type=checkbox]:checked").each(function(){
if(this.name === 'contexts'){
contexts.push(this.value);
- }else{
+ } else {
v[this.name] = true;
}
});
@@ -82,7 +82,7 @@ function getValue(){
contexts: v.has_required_statuses ? contexts : []
}
};
- }else{
+ } else {
return {
enabled: false,
required_status_checks: {