remove RepoBase by moving RepositoryUrls construction into Context

This commit is contained in:
Herr Ritschwumm
2016-02-11 23:23:13 +01:00
parent ee7220ebd2
commit 24b9a9a12c
10 changed files with 35 additions and 41 deletions

View File

@@ -3,6 +3,7 @@ package gitbucket.core.controller
import gitbucket.core.api.ApiError import gitbucket.core.api.ApiError
import gitbucket.core.model.Account import gitbucket.core.model.Account
import gitbucket.core.service.{AccountService, SystemSettingsService} import gitbucket.core.service.{AccountService, SystemSettingsService}
import gitbucket.core.service.RepositoryService.{RepositoryInfo, RepositoryUrls}
import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.ControlUtil._
import gitbucket.core.util.Directory._ import gitbucket.core.util.Directory._
import gitbucket.core.util.Implicits._ import gitbucket.core.util.Implicits._
@@ -184,7 +185,8 @@ case class Context(settings: SystemSettingsService.SystemSettings, loginAccount:
val currentPath = request.getRequestURI.substring(request.getContextPath.length) val currentPath = request.getRequestURI.substring(request.getContextPath.length)
val baseUrl = settings.baseUrl(request) val baseUrl = settings.baseUrl(request)
val host = new java.net.URL(baseUrl).getHost val host = new java.net.URL(baseUrl).getHost
val repoBase = RepoBase(baseUrl, settings.sshAddress) 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 { val platform = request.getHeader("User-Agent") match {
case null => null case null => null
case agent if agent.contains("Mac") => "mac" case agent if agent.contains("Mac") => "mac"

View File

@@ -1,8 +1,9 @@
package gitbucket.core.service package gitbucket.core.service
import gitbucket.core.service.SystemSettingsService.SshAddress
import gitbucket.core.model.{Collaborator, Repository, Account} import gitbucket.core.model.{Collaborator, Repository, Account}
import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile._
import gitbucket.core.util.{JGitUtil, RepoBase} import gitbucket.core.util.JGitUtil
import profile.simple._ import profile.simple._
trait RepositoryService { self: AccountService => trait RepositoryService { self: AccountService =>
@@ -391,8 +392,6 @@ object RepositoryService {
issueCount: Int, pullCount: Int, commitCount: Int, forkedCount: Int, issueCount: Int, pullCount: Int, commitCount: Int, forkedCount: Int,
branchList: Seq[String], tags: Seq[JGitUtil.TagInfo], managers: Seq[String]) { branchList: Seq[String], tags: Seq[JGitUtil.TagInfo], managers: Seq[String]) {
def urls(repoBase:RepoBase):RepositoryUrls = new RepositoryUrls(repoBase, owner, name)
/** /**
* Creates instance with issue count and pull request count. * Creates instance with issue count and pull request count.
*/ */
@@ -412,13 +411,13 @@ object RepositoryService {
repo.commitCount, forkedCount, repo.branchList, repo.tags, managers) repo.commitCount, forkedCount, repo.branchList, repo.tags, managers)
} }
final class RepositoryUrls(repoBase:RepoBase, owner:String, name:String) { final class RepositoryUrls(baseUrl:String, sshAddress:Option[SshAddress], owner:String, name:String) {
def httpUrl:String = def httpUrl:String =
s"${repoBase.baseUrl}/git/${owner}/${name}.git" s"${baseUrl}/git/${owner}/${name}.git"
// BETTER make this return an Option and use it in the gui // BETTER make this return an Option and use it in the gui
def sshUrl(userName: String):String = def sshUrl(userName: String):String =
repoBase.sshAddress.fold("")(adr => s"ssh://${userName}@${adr.host}:${adr.port}/${owner}/${name}.git") sshAddress.fold("")(adr => s"ssh://${userName}@${adr.host}:${adr.port}/${owner}/${name}.git")
def sshOpenRepoUrl(platform: String, userName: String) = def sshOpenRepoUrl(platform: String, userName: String) =
openRepoUrl(platform, sshUrl(userName)) openRepoUrl(platform, sshUrl(userName))

View File

@@ -1,6 +1,7 @@
package gitbucket.core.service package gitbucket.core.service
import java.util.Date import java.util.Date
import gitbucket.core.service.SystemSettingsService.SshAddress
import gitbucket.core.model.Account import gitbucket.core.model.Account
import gitbucket.core.util._ import gitbucket.core.util._
import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.ControlUtil._
@@ -38,9 +39,6 @@ object WikiService {
* @param date the commit date * @param date the commit date
*/ */
case class WikiPageHistoryInfo(name: String, committer: String, message: String, date: Date) case class WikiPageHistoryInfo(name: String, committer: String, message: String, date: Date)
def urls(repoBase:RepoBase, repository: RepositoryInfo):RepositoryUrls =
new RepositoryUrls(repoBase, repository.owner, repository.name + ".wiki")
} }
trait WikiService { trait WikiService {

View File

@@ -1,5 +0,0 @@
package gitbucket.core.util
import gitbucket.core.service.SystemSettingsService.SshAddress
case class RepoBase(baseUrl:String, sshAddress:Option[SshAddress])

View File

@@ -60,7 +60,7 @@ object Markdown {
pages: List[String]) pages: List[String])
(implicit val context: Context) extends Renderer(options) with LinkConverter with RequestCache { (implicit val context: Context) extends Renderer(options) with LinkConverter with RequestCache {
private val repositoryUrls = repository.urls(context.repoBase) private val repositoryUrls = context.urls(repository)
override def heading(text: String, level: Int, raw: String): String = { override def heading(text: String, level: Int, raw: String): String = {
val id = generateAnchorName(text) val id = generateAnchorName(text)

View File

@@ -37,7 +37,7 @@
<script src="@assets/vendors/jquery-hotkeys/jquery.hotkeys.js"></script> <script src="@assets/vendors/jquery-hotkeys/jquery.hotkeys.js"></script>
@repository.map { repository => @repository.map { repository =>
@if(!repository.repository.isPrivate){ @if(!repository.repository.isPrivate){
<meta name="go-import" content="@context.baseUrl.replaceFirst("^https?://", "")/@repository.owner/@repository.name git @repository.urls(repoBase).httpUrl" /> <meta name="go-import" content="@context.baseUrl.replaceFirst("^https?://", "")/@repository.owner/@repository.name git @context.urls(repository).httpUrl" />
} }
} }
</head> </head>

View File

@@ -80,8 +80,8 @@
<div class="small"> <div class="small">
<strong id="repository-url-proto">HTTP</strong> <span class="mute">clone URL</span> <strong id="repository-url-proto">HTTP</strong> <span class="mute">clone URL</span>
</div> </div>
@helper.html.copy("repository-url-copy", repository.urls(repoBase).httpUrl){ @helper.html.copy("repository-url-copy", context.urls(repository).httpUrl){
<input type="text" value="@repository.urls(repoBase).httpUrl" id="repository-url" class="form-control input-sm" readonly> <input type="text" value="@context.urls(repository).httpUrl" id="repository-url" class="form-control input-sm" readonly>
} }
@if(settings.ssh && loginAccount.isDefined){ @if(settings.ssh && loginAccount.isDefined){
<div class="small"> <div class="small">
@@ -91,7 +91,7 @@
@id.map { id => @id.map { id =>
@if(context.platform != "linux" && context.platform != null){ @if(context.platform != "linux" && context.platform != null){
<div style="margin-top: 10px;"> <div style="margin-top: 10px;">
<a href="@repository.urls(repoBase).httpOpenRepoUrl(context.platform)" id="repository-clone-url" class="btn btn-sm btn-default btn-block"><i class="octicon octicon-desktop-download"></i>&nbsp;&nbsp;Clone in Desktop</a> <a href="@context.urls(repository).httpOpenRepoUrl(context.platform)" id="repository-clone-url" class="btn btn-sm btn-default btn-block"><i class="octicon octicon-desktop-download"></i>&nbsp;&nbsp;Clone in Desktop</a>
</div> </div>
} }
<div style="margin-top: 10px;"> <div style="margin-top: 10px;">
@@ -184,15 +184,15 @@ $(function(){
@if(settings.ssh && loginAccount.isDefined){ @if(settings.ssh && loginAccount.isDefined){
$('#repository-url-http').click(function(){ $('#repository-url-http').click(function(){
$('#repository-url-proto').text('HTTP'); $('#repository-url-proto').text('HTTP');
$('#repository-url').val('@repository.urls(repoBase).httpUrl'); $('#repository-url').val('@context.urls(repository).httpUrl');
$('#repository-clone-url').attr('href', '@repository.urls(repoBase).httpOpenRepoUrl(context.platform)') $('#repository-clone-url').attr('href', '@context.urls(repository).httpOpenRepoUrl(context.platform)')
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
}); });
$('#repository-url-ssh').click(function(){ $('#repository-url-ssh').click(function(){
$('#repository-url-proto').text('SSH'); $('#repository-url-proto').text('SSH');
$('#repository-url').val('@repository.urls(repoBase).sshUrl(loginAccount.get.userName)'); $('#repository-url').val('@context.urls(repository).sshUrl(loginAccount.get.userName)');
$('#repository-clone-url').attr('href', '@repository.urls(repoBase).sshOpenRepoUrl(context.platform, loginAccount.get.userName)'); $('#repository-clone-url').attr('href', '@context.urls(repository).sshOpenRepoUrl(context.platform, loginAccount.get.userName)');
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
}); });
} }

View File

@@ -100,21 +100,21 @@
you can perform a manual merge on the command line. you can perform a manual merge on the command line.
</p> </p>
} }
@helper.html.copy("repository-url-copy", forkedRepository.urls(repoBase).httpUrl, true){ @helper.html.copy("repository-url-copy", context.urls(forkedRepository).httpUrl, true){
<div class="btn-group" data-toggle="buttons-radio"> <div class="btn-group" data-toggle="buttons-radio">
<button class="btn btn-small active" type="button" id="repository-url-http">HTTP</button> <button class="btn btn-small active" type="button" id="repository-url-http">HTTP</button>
@if(settings.ssh && loginAccount.isDefined){ @if(settings.ssh && loginAccount.isDefined){
<button class="btn btn-small" type="button" id="repository-url-ssh" style="border-radius: 0px;">SSH</button> <button class="btn btn-small" type="button" id="repository-url-ssh" style="border-radius: 0px;">SSH</button>
} }
</div> </div>
<input type="text" style="width: 500px;" value="@forkedRepository.urls(repoBase).httpUrl" id="repository-url" readonly /> <input type="text" style="width: 500px;" value="@context.urls(forkedRepository).httpUrl" id="repository-url" readonly />
} }
<div> <div>
<p> <p>
<span class="strong">Step 1:</span> From your project repository, check out a new branch and test the changes. <span class="strong">Step 1:</span> From your project repository, check out a new branch and test the changes.
</p> </p>
@defining(s"git checkout -b ${pullreq.requestUserName}-${pullreq.requestBranch} ${pullreq.branch}\n" + @defining(s"git checkout -b ${pullreq.requestUserName}-${pullreq.requestBranch} ${pullreq.branch}\n" +
s"git pull ${forkedRepository.urls(repoBase).httpUrl} ${pullreq.requestBranch}"){ command => s"git pull ${context.urls(forkedRepository).httpUrl} ${pullreq.requestBranch}"){ command =>
@helper.html.copy("merge-command-copy-1", command){ @helper.html.copy("merge-command-copy-1", command){
<pre style="width: 600px; float: left; font-size: 12px; border-radius: 3px 0px 3px 3px;" id="merge-command">@Html(command)</pre> <pre style="width: 600px; float: left; font-size: 12px; border-radius: 3px 0px 3px 3px;" id="merge-command">@Html(command)</pre>
} }
@@ -174,24 +174,24 @@ $(function(){
@if(settings.ssh && loginAccount.isDefined){ @if(settings.ssh && loginAccount.isDefined){
$('#repository-url-http').click(function(){ $('#repository-url-http').click(function(){
// Update URL box // Update URL box
$('#repository-url').val('@forkedRepository.urls(repoBase).httpUrl'); $('#repository-url').val('@context.urls(forkedRepository).httpUrl');
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
// Update command guidance // Update command guidance
$('#merge-command').text($('#merge-command').text().replace( $('#merge-command').text($('#merge-command').text().replace(
'@forkedRepository.urls(repoBase).sshUrl(loginAccount.get.userName)', '@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)',
'@forkedRepository.urls(repoBase).httpUrl' '@context.urls(forkedRepository).httpUrl'
)); ));
$('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text()); $('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text());
}); });
$('#repository-url-ssh').click(function(){ $('#repository-url-ssh').click(function(){
// Update URL box // Update URL box
$('#repository-url').val('@forkedRepository.urls(repoBase).sshUrl(loginAccount.get.userName)'); $('#repository-url').val('@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)');
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
// Update command guidance // Update command guidance
$('#merge-command').text($('#merge-command').text().replace( $('#merge-command').text($('#merge-command').text().replace(
'@forkedRepository.urls(repoBase).httpUrl', '@context.urls(forkedRepository).httpUrl',
'@forkedRepository.urls(repoBase).sshUrl(loginAccount.get.userName)' '@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)'
)); ));
$('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text()); $('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text());
}); });

View File

@@ -10,10 +10,10 @@
} else { } else {
<h3><strong>Quick setup</strong> — if you've done this kind of thing before</h3> <h3><strong>Quick setup</strong> — if you've done this kind of thing before</h3>
<div class="empty-repo-options"> <div class="empty-repo-options">
via <a href="@repository.urls(repoBase).httpUrl" class="git-protocol-selector">HTTP</a> via <a href="@context.urls(repository).httpUrl" class="git-protocol-selector">HTTP</a>
@if(settings.ssh && loginAccount.isDefined){ @if(settings.ssh && loginAccount.isDefined){
or or
<a href="@repository.urls(repoBase).sshUrl(loginAccount.get.userName)" class="git-protocol-selector">SSH</a> <a href="@context.urls(repository).sshUrl(loginAccount.get.userName)" class="git-protocol-selector">SSH</a>
} }
</div> </div>
<h3 style="margin-top: 30px;">Create a new repository on the command line</h3> <h3 style="margin-top: 30px;">Create a new repository on the command line</h3>
@@ -22,12 +22,12 @@
git init git init
git add README.md git add README.md
git commit -m "first commit" git commit -m "first commit"
git remote add origin <span class="live-clone-url">@repository.urls(repoBase).httpUrl</span> git remote add origin <span class="live-clone-url">@context.urls(repository).httpUrl</span>
git push -u origin master git push -u origin master
} }
<h3 style="margin-top: 30px;">Push an existing repository from the command line</h3> <h3 style="margin-top: 30px;">Push an existing repository from the command line</h3>
@pre { @pre {
git remote add origin <span class="live-clone-url">@repository.urls(repoBase).httpUrl</span> git remote add origin <span class="live-clone-url">@context.urls(repository).httpUrl</span>
git push -u origin master git push -u origin master
} }
<script> <script>

View File

@@ -67,8 +67,8 @@
<div class="small"> <div class="small">
<strong>Clone this wiki locally</strong> <strong>Clone this wiki locally</strong>
</div> </div>
@helper.html.copy("repository-url-copy", urls(repoBase, repository).httpUrl){ @helper.html.copy("repository-url-copy", context.wikiUrls(repository).httpUrl){
<input type="text" value="@urls(repoBase, repository).httpUrl" id="repository-url" class="form-control input-sm" readonly> <input type="text" value="@context.wikiUrls(repository).httpUrl" id="repository-url" class="form-control input-sm" readonly>
} }
@if(settings.ssh && loginAccount.isDefined){ @if(settings.ssh && loginAccount.isDefined){
<div class="small"> <div class="small">
@@ -133,11 +133,11 @@ $(function(){
@if(settings.ssh && loginAccount.isDefined){ @if(settings.ssh && loginAccount.isDefined){
$('#repository-url-http').click(function(){ $('#repository-url-http').click(function(){
$('#repository-url').val('@urls(repoBase, repository).httpUrl'); $('#repository-url').val('@context.wikiUrls(repository).httpUrl');
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
}); });
$('#repository-url-ssh').click(function(){ $('#repository-url-ssh').click(function(){
$('#repository-url').val('@urls(repoBase, repository).sshUrl(loginAccount.get.userName)'); $('#repository-url').val('@context.wikiUrls(repository).sshUrl(loginAccount.get.userName)');
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
}); });
} }