Merge pull request #1520 from xuwei-k/refactoring

some refactoring
This commit is contained in:
Naoki Takezoe
2017-04-02 16:36:07 +09:00
committed by GitHub
13 changed files with 38 additions and 32 deletions

View File

@@ -19,19 +19,25 @@ public class JettyLauncher {
if(arg.startsWith("--") && arg.contains("=")) {
String[] dim = arg.split("=");
if(dim.length >= 2) {
if(dim[0].equals("--host")) {
host = dim[1];
} else if(dim[0].equals("--port")) {
port = Integer.parseInt(dim[1]);
} else if(dim[0].equals("--prefix")) {
contextPath = dim[1];
if(!contextPath.startsWith("/")){
contextPath = "/" + contextPath;
}
} else if(dim[0].equals("--gitbucket.home")){
System.setProperty("gitbucket.home", dim[1]);
} else if(dim[0].equals("--temp_dir")){
tmpDirPath = dim[1];
switch (dim[0]) {
case "--host":
host = dim[1];
break;
case "--port":
port = Integer.parseInt(dim[1]);
break;
case "--prefix":
contextPath = dim[1];
if (!contextPath.startsWith("/")) {
contextPath = "/" + contextPath;
}
break;
case "--gitbucket.home":
System.setProperty("gitbucket.home", dim[1]);
break;
case "--temp_dir":
tmpDirPath = dim[1];
break;
}
}
}

View File

@@ -19,8 +19,8 @@ case class CreateAStatus(
def isValid: Boolean = {
CommitState.valueOf(state).isDefined &&
// only http
target_url.filterNot(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length<255).isEmpty &&
context.filterNot(f => f.length<255).isEmpty &&
description.filterNot(f => f.length<1000).isEmpty
target_url.forall(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length < 255) &&
context.forall(f => f.length < 255) &&
description.forall(f => f.length < 1000)
}
}

View File

@@ -125,7 +125,7 @@ trait ApiControllerBase extends ControllerBase {
get ("/api/v3/repos/:owner/:repo/branches/:branch")(referrersOnly { repository =>
//import gitbucket.core.api._
(for{
branch <- params.get("branch") if repository.branchList.find(_ == branch).isDefined
branch <- params.get("branch") if repository.branchList.contains(branch)
br <- getBranches(repository.owner, repository.name, repository.repository.defaultBranch, repository.repository.originUserName.isEmpty).find(_.name == branch)
} yield {
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
@@ -287,7 +287,7 @@ trait ApiControllerBase extends ControllerBase {
patch("/api/v3/repos/:owner/:repo/branches/:branch")(ownerOnly { repository =>
import gitbucket.core.api._
(for{
branch <- params.get("branch") if repository.branchList.find(_ == branch).isDefined
branch <- params.get("branch") if repository.branchList.contains(branch)
protection <- extractFromJsonBody[ApiBranchProtection.EnablingAndDisabling].map(_.protection)
br <- getBranches(repository.owner, repository.name, repository.repository.defaultBranch, repository.repository.originUserName.isEmpty).find(_.name == branch)
} yield {

View File

@@ -157,7 +157,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
/** Update default branch */
post("/:owner/:repository/settings/update_default_branch", defaultBranchForm)(ownerOnly { (form, repository) =>
if(repository.branchList.find(_ == form.defaultBranch).isEmpty){
if(!repository.branchList.contains(form.defaultBranch)){
redirect(s"/${repository.owner}/${repository.name}/settings/options")
} else {
saveRepositoryDefaultBranch(repository.owner, repository.name, form.defaultBranch)
@@ -174,7 +174,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
get("/:owner/:repository/settings/branches/:branch")(ownerOnly { repository =>
import gitbucket.core.api._
val branch = params("branch")
if(repository.branchList.find(_ == branch).isEmpty){
if(!repository.branchList.contains(branch)){
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
} else {
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))

View File

@@ -232,7 +232,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
oldFileName = form.oldFileName,
content = appendNewLine(convertLineSeparator(form.content, form.lineSeparator), form.lineSeparator),
charset = form.charset,
message = if(form.oldFileName.exists(_ == form.newFileName)){
message = if(form.oldFileName.contains(form.newFileName)){
form.message.getOrElse(s"Update ${form.newFileName}")
} else {
form.message.getOrElse(s"Rename ${form.oldFileName.get} to ${form.newFileName}")
@@ -614,7 +614,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
val permission = JGitUtil.processTree(git, headTip){ (path, tree) =>
// Add all entries except the editing file
if(!newPath.exists(_ == path) && !oldPath.exists(_ == path)){
if(!newPath.contains(path) && !oldPath.contains(path)){
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
}
// Retrieve permission if file exists to keep it

View File

@@ -83,7 +83,7 @@ class PluginRegistry {
def addRenderer(extension: String, renderer: Renderer): Unit = renderers += ((extension, renderer))
def getRenderer(extension: String): Renderer = renderers.get(extension).getOrElse(DefaultRenderer)
def getRenderer(extension: String): Renderer = renderers.getOrElse(extension, DefaultRenderer)
def renderableExtensions: Seq[String] = renderers.keys.toSeq

View File

@@ -111,7 +111,7 @@ trait IssuesService {
val (_, cs) = status.head
Some(CommitStatusInfo(
count = status.length,
successCount = status.filter(_._2.state == CommitState.SUCCESS).length,
successCount = status.count(_._2.state == CommitState.SUCCESS),
context = (if(status.length == 1) Some(cs.context) else None),
state = (if(status.length == 1) Some(cs.state) else None),
targetUrl = (if(status.length == 1) cs.targetUrl else None),

View File

@@ -76,7 +76,7 @@ object ProtectedBranchService {
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
pusher == owner || getGroupMembers(owner).exists(gm => gm.userName == pusher && gm.isManager)
/**
* Can't be force pushed

View File

@@ -265,7 +265,7 @@ object PullRequestService {
val summary = stateMap.map{ case (keyState, states) => states.size+" "+keyState.name }.mkString(", ")
state -> summary
}
lazy val statusesAndRequired:List[(CommitStatus, Boolean)] = statuses.map{ s => s -> branchProtection.contexts.exists(_==s.context) }
lazy val statusesAndRequired:List[(CommitStatus, Boolean)] = statuses.map{ s => s -> branchProtection.contexts.contains(s.context) }
lazy val isAllSuccess = commitStateSummary._1==CommitState.SUCCESS
}
}

View File

@@ -177,7 +177,7 @@ trait WikiService {
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
JGitUtil.processTree(git, headId){ (path, tree) =>
if(revertInfo.find(x => x.filePath == path).isEmpty){
if(!revertInfo.exists(x => x.filePath == path)){
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
}
}

View File

@@ -105,7 +105,7 @@ abstract class DefaultGitCommand(val owner: String, val repoName: String) extend
}
}
case AuthType.DeployKeyType(key) => {
getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)) match {
getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).contains(key)) match {
case List(_) => true
case _ => false
}
@@ -123,7 +123,7 @@ abstract class DefaultGitCommand(val owner: String, val repoName: String) extend
}
}
case AuthType.DeployKeyType(key) => {
getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)) match {
getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).contains(key)) match {
case List(x) if x.allowWrite => true
case _ => false
}

View File

@@ -68,7 +68,7 @@ class PublicKeyAuthenticator(genericUser: String) extends PublickeyAuthenticator
private def authenticateGenericUser(userName: String, key: PublicKey, session: ServerSession, genericUser: String)(implicit s: Session): Boolean = {
// find all users having the key we got from ssh
val possibleUserNames = getAllKeys().filter { sshKey =>
SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)
SshUtil.str2PublicKey(sshKey.publicKey).contains(key)
}.map(_.userName).distinct
// determine the user - if different accounts share the same key, tough luck
@@ -85,7 +85,7 @@ class PublicKeyAuthenticator(genericUser: String) extends PublickeyAuthenticator
}.getOrElse {
// search deploy keys
val existsDeployKey = getAllDeployKeys().exists { sshKey =>
SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)
SshUtil.str2PublicKey(sshKey.publicKey).contains(key)
}
if(existsDeployKey){
// found deploy key for repository

View File

@@ -952,7 +952,7 @@ object JGitUtil {
* @return the last modified commit of specified path
*/
def getLastModifiedCommit(git: Git, startCommit: RevCommit, path: String): RevCommit = {
return git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next
git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next
}
def getBranches(owner: String, name: String, defaultBranch: String, origin: Boolean): Seq[BranchInfo] = {