diff --git a/src/main/scala/gitbucket/core/controller/ControllerBase.scala b/src/main/scala/gitbucket/core/controller/ControllerBase.scala index c8dabcc..a336509 100644 --- a/src/main/scala/gitbucket/core/controller/ControllerBase.scala +++ b/src/main/scala/gitbucket/core/controller/ControllerBase.scala @@ -3,7 +3,6 @@ import gitbucket.core.api.ApiError import gitbucket.core.model.Account import gitbucket.core.service.{AccountService, SystemSettingsService} -import gitbucket.core.service.RepositoryService.{RepositoryInfo, RepositoryUrls} import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ @@ -185,8 +184,6 @@ val currentPath = request.getRequestURI.substring(request.getContextPath.length) val baseUrl = settings.baseUrl(request) val host = new java.net.URL(baseUrl).getHost - val urls = (repositoryInfo:RepositoryInfo) => new RepositoryUrls(baseUrl, settings.sshAddress, repositoryInfo.owner, repositoryInfo.name) - val wikiUrls = (repositoryInfo:RepositoryInfo) => new RepositoryUrls(baseUrl, settings.sshAddress, repositoryInfo.owner, repositoryInfo.name + ".wiki") val platform = request.getHeader("User-Agent") match { case null => null case agent if agent.contains("Mac") => "mac" diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 2544876..408c9b6 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -1,6 +1,6 @@ package gitbucket.core.service -import gitbucket.core.service.SystemSettingsService.SshAddress +import gitbucket.core.controller.Context import gitbucket.core.model.{Collaborator, Repository, Account} import gitbucket.core.model.Profile._ import gitbucket.core.util.JGitUtil @@ -398,8 +398,8 @@ def this(repo: JGitUtil.RepositoryInfo, model: Repository, issueCount: Int, pullCount: Int, forkedCount: Int, managers: Seq[String]) = this( repo.owner, repo.name, model, - issueCount, pullCount, - repo.commitCount, forkedCount, repo.branchList, repo.tags, managers) + issueCount, pullCount, repo.commitCount, forkedCount, + repo.branchList, repo.tags, managers) /** * Creates instance without issue count and pull request count. @@ -407,27 +407,20 @@ def this(repo: JGitUtil.RepositoryInfo, model: Repository, forkedCount: Int, managers: Seq[String]) = this( repo.owner, repo.name, model, - 0, 0, - repo.commitCount, forkedCount, repo.branchList, repo.tags, managers) + 0, 0, repo.commitCount, forkedCount, + repo.branchList, repo.tags, managers) + + def httpUrl(implicit context: Context): String = RepositoryService.httpUrl(owner, name) + def sshUrl(implicit context: Context): Option[String] = RepositoryService.sshUrl(owner, name) } - final class RepositoryUrls(baseUrl:String, sshAddress:Option[SshAddress], owner:String, name:String) { - def httpUrl:String = - s"${baseUrl}/git/${owner}/${name}.git" + def httpUrl(owner: String, name: String)(implicit context: Context): String = s"${context.baseUrl}/git/${owner}/${name}.git" + def sshUrl(owner: String, name: String)(implicit context: Context): Option[String] = + if(context.settings.ssh){ + context.loginAccount.flatMap { loginAccount => + context.settings.sshAddress.map { x => s"ssh://${loginAccount.userName}@${x.host}:${x.port}/${owner}/${name}.git" } + } + } else None + def openRepoUrl(openUrl: String)(implicit context: Context): String = s"github-${context.platform}://openRepo/${openUrl}" - // BETTER make this return an Option and use it in the gui - def sshUrl(userName: String):String = - sshAddress.fold("")(adr => s"ssh://${userName}@${adr.host}:${adr.port}/${owner}/${name}.git") - - def sshOpenRepoUrl(platform: String, userName: String) = - openRepoUrl(platform, sshUrl(userName)) - - def httpOpenRepoUrl(platform: String) = - openRepoUrl(platform, httpUrl) - - private def openRepoUrl(platform: String, openUrl: String) = - s"github-${platform}://openRepo/${openUrl}" - } - - case class RepositoryTreeNode(owner: String, name: String, children: List[RepositoryTreeNode]) } diff --git a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala index e5096ba..b1f0f5c 100644 --- a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala +++ b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala @@ -139,8 +139,7 @@ def sshAddress:Option[SshAddress] = for { - host <- sshHost - if ssh + host <- sshHost if ssh } yield SshAddress(host, sshPort.getOrElse(DefaultSshPort)) } @@ -228,7 +227,4 @@ else value } -// // TODO temporary flag -// val enablePluginSystem = Option(System.getProperty("enable.plugin")).getOrElse("false").toBoolean - } diff --git a/src/main/scala/gitbucket/core/service/WikiService.scala b/src/main/scala/gitbucket/core/service/WikiService.scala index f1d7749..1bff5dc 100644 --- a/src/main/scala/gitbucket/core/service/WikiService.scala +++ b/src/main/scala/gitbucket/core/service/WikiService.scala @@ -1,8 +1,9 @@ package gitbucket.core.service import java.util.Date -import gitbucket.core.service.SystemSettingsService.SshAddress +import gitbucket.core.controller.Context import gitbucket.core.model.Account +import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.util._ import gitbucket.core.util.ControlUtil._ import org.eclipse.jgit.api.Git @@ -14,8 +15,6 @@ import org.eclipse.jgit.patch._ import org.eclipse.jgit.api.errors.PatchFormatException import scala.collection.JavaConverters._ -import RepositoryService.RepositoryInfo -import RepositoryService.RepositoryUrls object WikiService { @@ -39,6 +38,14 @@ * @param date the commit date */ case class WikiPageHistoryInfo(name: String, committer: String, message: String, date: Date) + + + def wikiHttpUrl(repositoryInfo: RepositoryInfo)(implicit context: Context): String + = RepositoryService.httpUrl(repositoryInfo.owner, repositoryInfo.name + ".wiki") + + def wikiSshUrl(repositoryInfo: RepositoryInfo)(implicit context: Context): Option[String] + = RepositoryService.sshUrl(repositoryInfo.owner, repositoryInfo.name + ".wiki") + } trait WikiService { diff --git a/src/main/scala/gitbucket/core/view/Markdown.scala b/src/main/scala/gitbucket/core/view/Markdown.scala index 449a47b..2d57d1c 100644 --- a/src/main/scala/gitbucket/core/view/Markdown.scala +++ b/src/main/scala/gitbucket/core/view/Markdown.scala @@ -60,8 +60,6 @@ pages: List[String]) (implicit val context: Context) extends Renderer(options) with LinkConverter with RequestCache { - private val repositoryUrls = context.urls(repository) - override def heading(text: String, level: Int, raw: String): String = { val id = generateAnchorName(text) val out = new StringBuilder() @@ -137,7 +135,7 @@ (link, link) } - val url = repositoryUrls.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/wiki/" + StringUtil.urlEncode(page) + val url = repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/wiki/" + StringUtil.urlEncode(page) if(pages.contains(page)){ "" + escape(label) + "" } else { @@ -159,14 +157,14 @@ } else if(context.currentPath.contains("/tree/")){ val paths = context.currentPath.split("/") val branch = if(paths.length > 3) paths.drop(4).mkString("/") else repository.repository.defaultBranch - repositoryUrls.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + branch + "/" + url + (if(isImage) "?raw=true" else "") + repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + branch + "/" + url + (if(isImage) "?raw=true" else "") } else { val paths = context.currentPath.split("/") val branch = if(paths.length > 3) paths.last else repository.repository.defaultBranch - repositoryUrls.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + branch + "/" + url + (if(isImage) "?raw=true" else "") + repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + branch + "/" + url + (if(isImage) "?raw=true" else "") } } else { - repositoryUrls.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/wiki/_blob/" + url + repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/wiki/_blob/" + url } } diff --git a/src/main/twirl/gitbucket/core/admin/system.scala.html b/src/main/twirl/gitbucket/core/admin/system.scala.html index 3f07d07..5139e70 100644 --- a/src/main/twirl/gitbucket/core/admin/system.scala.html +++ b/src/main/twirl/gitbucket/core/admin/system.scala.html @@ -128,7 +128,7 @@

- Base URL is required if SSH access is enabled. + Both of SSH host and Base URL are required if SSH access is enabled.

diff --git a/src/main/twirl/gitbucket/core/main.scala.html b/src/main/twirl/gitbucket/core/main.scala.html index 69fcfdc..b1d597a 100644 --- a/src/main/twirl/gitbucket/core/main.scala.html +++ b/src/main/twirl/gitbucket/core/main.scala.html @@ -37,7 +37,7 @@ @repository.map { repository => @if(!repository.repository.isPrivate){ - + } } diff --git a/src/main/twirl/gitbucket/core/menu.scala.html b/src/main/twirl/gitbucket/core/menu.scala.html index 560d16e..465f1ff 100644 --- a/src/main/twirl/gitbucket/core/menu.scala.html +++ b/src/main/twirl/gitbucket/core/menu.scala.html @@ -5,9 +5,9 @@ isNoGroup: Boolean = true, info: Option[Any] = None, error: Option[Any] = None)(body: Html)(implicit context: gitbucket.core.controller.Context) -@import gitbucket.core.service.SystemSettingsService @import context._ @import gitbucket.core.view.helpers._ +@import gitbucket.core.service.RepositoryService._ @sidemenu(path: String, name: String, icon: String, label: String, count: Int = 0) = {
  • @@ -80,10 +80,10 @@
    HTTP clone URL
    - @helper.html.copy("repository-url-copy", context.urls(repository).httpUrl){ - + @helper.html.copy("repository-url-copy", repository.httpUrl){ + } - @if(settings.ssh && loginAccount.isDefined){ + @if(repository.sshUrl.isDefined){
    You can clone HTTP or SSH.
    @@ -91,7 +91,7 @@ @id.map { id => @if(context.platform != "linux" && context.platform != null){
    -   Clone in Desktop +   Clone in Desktop
    }
    @@ -181,18 +181,18 @@ }); } - @if(settings.ssh && loginAccount.isDefined){ + @repository.sshUrl.map { sshUrl => $('#repository-url-http').click(function(){ $('#repository-url-proto').text('HTTP'); - $('#repository-url').val('@context.urls(repository).httpUrl'); - $('#repository-clone-url').attr('href', '@context.urls(repository).httpOpenRepoUrl(context.platform)') + $('#repository-url').val('@repository.httpUrl'); + $('#repository-clone-url').attr('href', '@openRepoUrl(repository.httpUrl)') $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); }); $('#repository-url-ssh').click(function(){ $('#repository-url-proto').text('SSH'); - $('#repository-url').val('@context.urls(repository).sshUrl(loginAccount.get.userName)'); - $('#repository-clone-url').attr('href', '@context.urls(repository).sshOpenRepoUrl(context.platform, loginAccount.get.userName)'); + $('#repository-url').val('@sshUrl'); + $('#repository-clone-url').attr('href', '@openRepoUrl(sshUrl)'); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); }); } diff --git a/src/main/twirl/gitbucket/core/pulls/mergeguide.scala.html b/src/main/twirl/gitbucket/core/pulls/mergeguide.scala.html index c788a7f..77e1f99 100644 --- a/src/main/twirl/gitbucket/core/pulls/mergeguide.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/mergeguide.scala.html @@ -100,21 +100,21 @@ you can perform a manual merge on the command line.

    } - @helper.html.copy("repository-url-copy", context.urls(forkedRepository).httpUrl, true){ + @helper.html.copy("repository-url-copy", forkedRepository.httpUrl, true){
    @if(settings.ssh && loginAccount.isDefined){ }
    - + }

    Step 1: From your project repository, check out a new branch and test the changes.

    @defining(s"git checkout -b ${pullreq.requestUserName}-${pullreq.requestBranch} ${pullreq.branch}\n" + - s"git pull ${context.urls(forkedRepository).httpUrl} ${pullreq.requestBranch}"){ command => + s"git pull ${forkedRepository.httpUrl} ${pullreq.requestBranch}"){ command => @helper.html.copy("merge-command-copy-1", command){
    @Html(command)
    } @@ -171,27 +171,26 @@ $('#confirm-merge-form').show(); }); - @if(settings.ssh && loginAccount.isDefined){ + @* @if(settings.ssh && loginAccount.isDefined){ *@ + @forkedRepository.sshUrl.map { sshUrl => $('#repository-url-http').click(function(){ // Update URL box - $('#repository-url').val('@context.urls(forkedRepository).httpUrl'); + $('#repository-url').val('@forkedRepository.httpUrl'); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); // Update command guidance $('#merge-command').text($('#merge-command').text().replace( - '@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)', - '@context.urls(forkedRepository).httpUrl' + '@sshUrl', '@forkedRepository.httpUrl' )); $('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text()); }); $('#repository-url-ssh').click(function(){ // Update URL box - $('#repository-url').val('@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)'); + $('#repository-url').val('@sshUrl'); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); // Update command guidance $('#merge-command').text($('#merge-command').text().replace( - '@context.urls(forkedRepository).httpUrl', - '@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)' + '@forkedRepository.httpUrl', '@sshUrl' )); $('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text()); }); diff --git a/src/main/twirl/gitbucket/core/repo/guide.scala.html b/src/main/twirl/gitbucket/core/repo/guide.scala.html index 5c064b4..b95546e 100644 --- a/src/main/twirl/gitbucket/core/repo/guide.scala.html +++ b/src/main/twirl/gitbucket/core/repo/guide.scala.html @@ -10,10 +10,10 @@ } else {

    Quick setup — if you've done this kind of thing before

    - via HTTP - @if(settings.ssh && loginAccount.isDefined){ + via HTTP + @repository.sshUrl.map { sshUrl => or - SSH + SSH }

    Create a new repository on the command line

    @@ -22,12 +22,12 @@ git init git add README.md git commit -m "first commit" - git remote add origin @context.urls(repository).httpUrl + git remote add origin @repository.httpUrl git push -u origin master }

    Push an existing repository from the command line

    @pre { - git remote add origin @context.urls(repository).httpUrl + git remote add origin @repository.httpUrl git push -u origin master }