diff --git a/src/main/scala/gitbucket/core/controller/AccountController.scala b/src/main/scala/gitbucket/core/controller/AccountController.scala index 65212e3..54bdc58 100644 --- a/src/main/scala/gitbucket/core/controller/AccountController.scala +++ b/src/main/scala/gitbucket/core/controller/AccountController.scala @@ -133,7 +133,7 @@ val members = getGroupMembers(account.userName) gitbucket.core.account.html.repositories(account, if(account.isGroupAccount) Nil else getGroupsByUserName(userName), - getVisibleRepositories(context.loginAccount, context.baseUrl, Some(userName)), + getVisibleRepositories(context.loginAccount, Some(userName)), context.loginAccount.exists(x => members.exists { member => member.userName == x.userName && member.isManager })) } } @@ -366,7 +366,7 @@ */ post("/new", newRepositoryForm)(usersOnly { form => LockUtil.lock(s"${form.owner}/${form.name}"){ - if(getRepository(form.owner, form.name, context.baseUrl).isEmpty){ + if(getRepository(form.owner, form.name).isEmpty){ createRepository(form.owner, form.name, form.description, form.isPrivate, form.createReadme) } @@ -385,9 +385,9 @@ data <- extractFromJsonBody[CreateARepository] if data.isValid } yield { LockUtil.lock(s"${owner}/${data.name}") { - if(getRepository(owner, data.name, context.baseUrl).isEmpty){ + if(getRepository(owner, data.name).isEmpty){ createRepository(owner, data.name, data.description, data.`private`, data.auto_init) - val repository = getRepository(owner, data.name, context.baseUrl).get + val repository = getRepository(owner, data.name).get JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(owner).get))) } else { ApiError( @@ -409,9 +409,9 @@ data <- extractFromJsonBody[CreateARepository] if data.isValid } yield { LockUtil.lock(s"${groupName}/${data.name}") { - if(getRepository(groupName, data.name, context.baseUrl).isEmpty){ + if(getRepository(groupName, data.name).isEmpty){ createRepository(groupName, data.name, data.description, data.`private`, data.auto_init) - val repository = getRepository(groupName, data.name, context.baseUrl).get + val repository = getRepository(groupName, data.name).get JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(groupName).get))) } else { ApiError( @@ -447,7 +447,7 @@ val accountName = form.accountName LockUtil.lock(s"${accountName}/${repository.name}"){ - if(getRepository(accountName, repository.name, baseUrl).isDefined || + if(getRepository(accountName, repository.name).isDefined || (accountName != loginUserName && !getGroupsByUserName(loginUserName).contains(accountName))){ // redirect to the repository if repository already exists redirect(s"/${accountName}/${repository.name}") diff --git a/src/main/scala/gitbucket/core/controller/DashboardController.scala b/src/main/scala/gitbucket/core/controller/DashboardController.scala index 713e9c0..1516c0f 100644 --- a/src/main/scala/gitbucket/core/controller/DashboardController.scala +++ b/src/main/scala/gitbucket/core/controller/DashboardController.scala @@ -94,7 +94,7 @@ val userName = context.loginAccount.get.userName val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName) - val userRepos = getUserRepositories(userName, context.baseUrl, true).map(repo => repo.owner -> repo.name) + val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name) val page = IssueSearchCondition.page(request) html.issues( diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index f264131..6a804f8 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -29,8 +29,8 @@ val loginAccount = context.loginAccount if(loginAccount.isEmpty) { html.index(getRecentActivities(), - getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true), - loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil) + getVisibleRepositories(loginAccount, withoutPhysicalInfo = true), + loginAccount.map{ account => getUserRepositories(account.userName, withoutPhysicalInfo = true) }.getOrElse(Nil) ) } else { val loginUserName = loginAccount.get.userName @@ -40,8 +40,8 @@ visibleOwnerSet ++= loginUserGroups html.index(getRecentActivitiesByOwners(visibleOwnerSet), - getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true), - loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil) + getVisibleRepositories(loginAccount, withoutPhysicalInfo = true), + loginAccount.map{ account => getUserRepositories(account.userName, withoutPhysicalInfo = true) }.getOrElse(Nil) ) } } diff --git a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala index 7a95c42..11141ff 100644 --- a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala +++ b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala @@ -137,7 +137,7 @@ baseOwner <- users.get(repository.owner) headOwner <- users.get(pullRequest.requestUserName) issueUser <- users.get(issue.openedUserName) - headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl) + headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) } yield { JsonFormat(ApiPullRequest( issue, @@ -196,7 +196,7 @@ issue, pullreq, repository, - getRepository(pullreq.requestUserName, pullreq.requestRepositoryName, context.baseUrl).get) + getRepository(pullreq.requestUserName, pullreq.requestRepositoryName).get) } } getOrElse NotFound }) @@ -229,7 +229,7 @@ if(branchProtection.needStatusCheck(loginAccount.userName)){ flash += "error" -> s"branch ${pullreq.requestBranch} is protected need status check." } else { - val repository = getRepository(owner, name, context.baseUrl).get + val repository = getRepository(owner, name).get LockUtil.lock(s"${owner}/${name}"){ val alias = if(pullreq.repositoryName == pullreq.requestRepositoryName && pullreq.userName == pullreq.requestUserName){ pullreq.branch @@ -310,7 +310,7 @@ pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.commitIdTo) // close issue by content of pull request - val defaultBranch = getRepository(owner, name, context.baseUrl).get.repository.defaultBranch + val defaultBranch = getRepository(owner, name).get.repository.defaultBranch if(pullreq.branch == defaultBranch){ commits.flatten.foreach { commit => closeIssuesFromMessage(commit.fullMessage, loginAccount.userName, owner, name) @@ -343,7 +343,7 @@ val headBranch:Option[String] = params.get("head") (forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match { case (Some(originUserName), Some(originRepositoryName)) => { - getRepository(originUserName, originRepositoryName, context.baseUrl).map { originRepository => + getRepository(originUserName, originRepositoryName).map { originRepository => using( Git.open(getRepositoryDir(originUserName, originRepositoryName)), Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name)) @@ -384,12 +384,12 @@ forkedRepository.repository.originRepositoryName } else { // Sibling repository - getUserRepositories(originOwner, context.baseUrl).find { x => + getUserRepositories(originOwner).find { x => x.repository.originUserName == forkedRepository.repository.originUserName && x.repository.originRepositoryName == forkedRepository.repository.originRepositoryName }.map(_.repository.repositoryName) }; - originRepository <- getRepository(originOwner, originRepositoryName, context.baseUrl) + originRepository <- getRepository(originOwner, originRepositoryName) ) yield { using( Git.open(getRepositoryDir(originRepository.owner, originRepository.name)), @@ -457,7 +457,7 @@ getForkedRepositories(forkedRepository.owner, forkedRepository.name).find(_._1 == originOwner).map(_._2) } }; - originRepository <- getRepository(originOwner, originRepositoryName, context.baseUrl) + originRepository <- getRepository(originOwner, originRepositoryName) ) yield { using( Git.open(getRepositoryDir(originRepository.owner, originRepository.name)), diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 4abf09c..372e002 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -560,8 +560,7 @@ html.forked( getRepository( repository.repository.originUserName.getOrElse(repository.owner), - repository.repository.originRepositoryName.getOrElse(repository.name), - context.baseUrl), + repository.repository.originRepositoryName.getOrElse(repository.name)), getForkedRepositories( repository.repository.originUserName.getOrElse(repository.owner), repository.repository.originRepositoryName.getOrElse(repository.name)), diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 1d68345..edcbb3a 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -194,10 +194,9 @@ * * @param userName the user name of the repository owner * @param repositoryName the repository name - * @param baseUrl the base url of this application * @return the repository information */ - def getRepository(userName: String, repositoryName: String, baseUrl: String)(implicit s: Session): Option[RepositoryInfo] = { + def getRepository(userName: String, repositoryName: String)(implicit s: Session): Option[RepositoryInfo] = { (Repositories filter { t => t.byRepository(userName, repositoryName) } firstOption) map { repository => // for getting issue count and pull request count val issues = Issues.filter { t => @@ -207,7 +206,6 @@ new RepositoryInfo( JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName), repository, - baseUrl, issues.count(_ == false), issues.count(_ == true), getForkedCount( @@ -235,7 +233,7 @@ }.list } - def getUserRepositories(userName: String, baseUrl: String, withoutPhysicalInfo: Boolean = false) + def getUserRepositories(userName: String, withoutPhysicalInfo: Boolean = false) (implicit s: Session): List[RepositoryInfo] = { Repositories.filter { t1 => (t1.userName === userName.bind) || @@ -248,7 +246,6 @@ JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName) }, repository, - baseUrl, getForkedCount( repository.originUserName.getOrElse(repository.userName), repository.originRepositoryName.getOrElse(repository.repositoryName) @@ -262,13 +259,12 @@ * If repositoryUserName is given then filters results by repository owner. * * @param loginAccount the logged in account - * @param baseUrl the base url of this application * @param repositoryUserName the repository owner (if None then returns all repositories which are visible for logged in user) * @param withoutPhysicalInfo if true then the result does not include physical repository information such as commit count, * branches and tags * @return the repository information which is sorted in descending order of lastActivityDate. */ - def getVisibleRepositories(loginAccount: Option[Account], baseUrl: String, repositoryUserName: Option[String] = None, + def getVisibleRepositories(loginAccount: Option[Account], repositoryUserName: Option[String] = None, withoutPhysicalInfo: Boolean = false) (implicit s: Session): List[RepositoryInfo] = { (loginAccount match { @@ -291,7 +287,6 @@ JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName) }, repository, - baseUrl, getForkedCount( repository.originUserName.getOrElse(repository.userName), repository.originRepositoryName.getOrElse(repository.repositoryName) @@ -401,7 +396,7 @@ /** * Creates instance with issue count and pull request count. */ - def this(repo: JGitUtil.RepositoryInfo, model: Repository, baseUrl:String, issueCount: Int, pullCount: Int, forkedCount: Int, managers: Seq[String]) = + def this(repo: JGitUtil.RepositoryInfo, model: Repository, issueCount: Int, pullCount: Int, forkedCount: Int, managers: Seq[String]) = this( repo.owner, repo.name, model, issueCount, pullCount, @@ -410,7 +405,7 @@ /** * Creates instance without issue count and pull request count. */ - def this(repo: JGitUtil.RepositoryInfo, model: Repository, baseUrl:String, forkedCount: Int, managers: Seq[String]) = + def this(repo: JGitUtil.RepositoryInfo, model: Repository, forkedCount: Int, managers: Seq[String]) = this( repo.owner, repo.name, model, 0, 0, diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index 059ca5d..d04d90b 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -161,7 +161,7 @@ baseOwner <- users.get(repository.owner) headOwner <- users.get(pullRequest.requestUserName) issueUser <- users.get(issue.openedUserName) - headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl) + headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) } yield { WebHookPullRequestPayload( action = action, @@ -200,7 +200,7 @@ import WebHookService._ for{ ((issue, issueUser, pullRequest, baseOwner, headOwner), webHooks) <- getPullRequestsByRequestForWebhook(requestRepository.owner, requestRepository.name, requestBranch) - baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName, baseUrl) + baseRepo <- getRepository(pullRequest.userName, pullRequest.repositoryName) } yield { val payload = WebHookPullRequestPayload( action = action, @@ -229,7 +229,7 @@ baseOwner <- users.get(repository.owner) headOwner <- users.get(pullRequest.requestUserName) issueUser <- users.get(issue.openedUserName) - headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl) + headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName) } yield { WebHookPullRequestReviewCommentPayload( action = action, diff --git a/src/main/scala/gitbucket/core/servlet/BasicAuthenticationFilter.scala b/src/main/scala/gitbucket/core/servlet/BasicAuthenticationFilter.scala index 421a461..696f5f1 100644 --- a/src/main/scala/gitbucket/core/servlet/BasicAuthenticationFilter.scala +++ b/src/main/scala/gitbucket/core/servlet/BasicAuthenticationFilter.scala @@ -74,7 +74,7 @@ request.paths match { case Array(_, repositoryOwner, repositoryName, _*) => - getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki\\.git$|\\.git$", ""), "") match { + getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki\\.git$|\\.git$", "")) match { case Some(repository) => { if(!isUpdating && !repository.repository.isPrivate && settings.allowAnonymousAccess){ chain.doFilter(request, response) diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala index 1f8347a..0583f61 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -160,7 +160,7 @@ countIssue(IssueSearchCondition(state = "open"), false, owner -> repository) + countIssue(IssueSearchCondition(state = "closed"), false, owner -> repository) - val repositoryInfo = getRepository(owner, repository, baseUrl).get + val repositoryInfo = getRepository(owner, repository).get // Extract new commit and apply issue comment val defaultBranch = repositoryInfo.repository.defaultBranch diff --git a/src/main/scala/gitbucket/core/ssh/GitCommand.scala b/src/main/scala/gitbucket/core/ssh/GitCommand.scala index 4236241..eb12001 100644 --- a/src/main/scala/gitbucket/core/ssh/GitCommand.scala +++ b/src/main/scala/gitbucket/core/ssh/GitCommand.scala @@ -87,11 +87,11 @@ } -class DefaultGitUploadPack(owner: String, repoName: String, baseUrl: String) extends DefaultGitCommand(owner, repoName) +class DefaultGitUploadPack(owner: String, repoName: String) extends DefaultGitCommand(owner, repoName) with RepositoryService with AccountService { override protected def runTask(user: String)(implicit session: Session): Unit = { - getRepository(owner, repoName.replaceFirst("\\.wiki\\Z", ""), baseUrl).foreach { repositoryInfo => + getRepository(owner, repoName.replaceFirst("\\.wiki\\Z", "")).foreach { repositoryInfo => if(!repositoryInfo.repository.isPrivate || isWritableUser(user, repositoryInfo)){ using(Git.open(getRepositoryDir(owner, repoName))) { git => val repository = git.getRepository @@ -107,7 +107,7 @@ with RepositoryService with AccountService { override protected def runTask(user: String)(implicit session: Session): Unit = { - getRepository(owner, repoName.replaceFirst("\\.wiki\\Z", ""), baseUrl).foreach { repositoryInfo => + getRepository(owner, repoName.replaceFirst("\\.wiki\\Z", "")).foreach { repositoryInfo => if(isWritableUser(user, repositoryInfo)){ using(Git.open(getRepositoryDir(owner, repoName))) { git => val repository = git.getRepository @@ -165,7 +165,7 @@ command match { case SimpleCommandRegex ("upload" , repoName) if(pluginRepository(repoName)) => new PluginGitUploadPack (repoName, routing(repoName)) case SimpleCommandRegex ("receive", repoName) if(pluginRepository(repoName)) => new PluginGitReceivePack(repoName, routing(repoName)) - case DefaultCommandRegex("upload" , owner, repoName) => new DefaultGitUploadPack (owner, repoName, baseUrl) + case DefaultCommandRegex("upload" , owner, repoName) => new DefaultGitUploadPack (owner, repoName) case DefaultCommandRegex("receive", owner, repoName) => new DefaultGitReceivePack(owner, repoName, baseUrl) case _ => new UnknownCommand(command) } diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala index 49de665..0035494 100644 --- a/src/main/scala/gitbucket/core/util/Authenticator.scala +++ b/src/main/scala/gitbucket/core/util/Authenticator.scala @@ -36,7 +36,7 @@ private def authenticate(action: (RepositoryInfo) => Any) = { { defining(request.paths){ paths => - getRepository(paths(0), paths(1), baseUrl).map { repository => + getRepository(paths(0), paths(1)).map { repository => context.loginAccount match { case Some(x) if(x.isAdmin) => action(repository) case Some(x) if(repository.owner == x.userName) => action(repository) @@ -95,7 +95,7 @@ private def authenticate(action: (RepositoryInfo) => Any) = { { defining(request.paths){ paths => - getRepository(paths(0), paths(1), baseUrl).map { repository => + getRepository(paths(0), paths(1)).map { repository => context.loginAccount match { case Some(x) if(x.isAdmin) => action(repository) case Some(x) if(paths(0) == x.userName) => action(repository) @@ -118,7 +118,7 @@ private def authenticate(action: (RepositoryInfo) => Any) = { { defining(request.paths){ paths => - getRepository(paths(0), paths(1), baseUrl).map { repository => + getRepository(paths(0), paths(1)).map { repository => if(!repository.repository.isPrivate){ action(repository) } else { @@ -145,7 +145,7 @@ private def authenticate(action: (RepositoryInfo) => Any) = { { defining(request.paths){ paths => - getRepository(paths(0), paths(1), baseUrl).map { repository => + getRepository(paths(0), paths(1)).map { repository => context.loginAccount match { case Some(x) if(x.isAdmin) => action(repository) case Some(x) if(!repository.repository.isPrivate) => action(repository)