diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala index 1db2f5d..ac6bd82 100644 --- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala @@ -116,7 +116,7 @@ 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 @@ 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 @@ } 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 411aeea..ae613ff 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -12,33 +12,35 @@ 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 @@ 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 f09211c..d427d17 100644 --- a/src/main/scala/gitbucket/core/service/MergeService.scala +++ b/src/main/scala/gitbucket/core/service/MergeService.scala @@ -70,7 +70,7 @@ try { if(merger.merge(mergeBaseTip, mergeTip)){ Some((merger.getResultTreeId, mergeBaseTip, mergeTip)) - }else{ + } else { None } } catch { @@ -139,17 +139,17 @@ 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 @@ 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 cfbe9e3..97652ae 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala @@ -31,7 +31,8 @@ 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 @@ 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 @@ */ 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 f92207c..eb9a263 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -119,7 +119,8 @@ 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 eb4df51..ba6e77d 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 => - + @protectedBranchList.map { branch => + + + }
- @branch - - Edit - -
+ @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 853b575..41855ee 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
- @knownContexts.map{ br => + @knownContexts.map { context =>
} @@ -57,7 +57,7 @@
- + @@ -70,7 +70,7 @@ $("input[type=checkbox]:checked").each(function(){ if(this.name === 'contexts'){ contexts.push(this.value); - }else{ + } else { v[this.name] = true; } }); @@ -82,7 +82,7 @@ contexts: v.has_required_statuses ? contexts : [] } }; - }else{ + } else { return { enabled: false, required_status_checks: {