diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala index e51b475..dca1b6b 100644 --- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala @@ -108,7 +108,8 @@ /** branch settings */ get("/:owner/:repository/settings/branches")(ownerOnly { repository => - html.branches(repository, flash.get("info")) + val protecteions = getProtectedBranchList(repository.owner, repository.name) + html.branches(repository, protecteions, flash.get("info")) }); /** Update default branch */ @@ -134,7 +135,7 @@ redirect(s"/${repository.owner}/${repository.name}/settings/branches") }else{ val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch)) - val lastWeeks = getRecentCommitStatues(repository.owner, repository.name, org.joda.time.LocalDateTime.now.minusWeeks(1).toDate).map(_.context).toSet + 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.brancheprotection(repository, branch, protection, knownContexts, flash.get("info")) } diff --git a/src/main/scala/gitbucket/core/service/CommitStatusService.scala b/src/main/scala/gitbucket/core/service/CommitStatusService.scala index 0e9a427..1aeac13 100644 --- a/src/main/scala/gitbucket/core/service/CommitStatusService.scala +++ b/src/main/scala/gitbucket/core/service/CommitStatusService.scala @@ -43,8 +43,8 @@ byCommitStatues(userName, repositoryName, sha).list implicit val date2SqlDate = MappedColumnType.base[java.util.Date, java.sql.Timestamp]( d => new java.sql.Timestamp(d.getTime), d => new java.util.Date(d.getTime) ) - def getRecentCommitStatues(userName: String, repositoryName: String, time: java.util.Date)(implicit s: Session) :List[CommitStatus] = - CommitStatuses.filter(t => t.byRepository(userName, repositoryName)).filter(t => t.updatedDate > time.bind).list + def getRecentStatuesContexts(userName: String, repositoryName: String, time: java.util.Date)(implicit s: Session) :List[String] = + 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) diff --git a/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala b/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala index 4029801..6fb9bde 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBrancheService.scala @@ -22,6 +22,13 @@ new ProtectedBranchInfo(owner, repository, requireStatusChecksToPass, includeAdministrators) } } + def getProtectedBranchList(owner: String, repository: String)(implicit session: Session): List[String] = { + // TODO: mock + MockDB.data.filter{ + case ((owner, repository, _), _) => true + case _ => false + }.map{ case ((_, _, branch), _) => branch }.toList + } def enableBranchProtection(owner: String, repository: String, branch:String, includeAdministrators: Boolean, requireStatusChecksToPass: Seq[String])(implicit session: Session): Unit = { // TODO: mock MockDB.data.put((owner, repository, branch), includeAdministrators -> requireStatusChecksToPass) diff --git a/src/main/twirl/gitbucket/core/settings/branches.scala.html b/src/main/twirl/gitbucket/core/settings/branches.scala.html index 1bb2b32..deca340 100644 --- a/src/main/twirl/gitbucket/core/settings/branches.scala.html +++ b/src/main/twirl/gitbucket/core/settings/branches.scala.html @@ -1,4 +1,5 @@ @(repository: gitbucket.core.service.RepositoryService.RepositoryInfo, + protectedBranchList: Seq[String], info: Option[Any])(implicit context: gitbucket.core.controller.Context) @import context._ @import gitbucket.core.view.helpers._ @@ -32,7 +33,7 @@
Protected branches
-
+

Protect branches to disable force pushing, prevent branches from being deleted, and optionally require status checks before merging. New to protected branches?

+ + + @protectedBranchList.map{ branch => + + } +
+ @branch + + Edit + +