mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 23:15:49 +01:00
remove RepoBase by moving RepositoryUrls construction into Context
This commit is contained in:
@@ -3,6 +3,7 @@ package gitbucket.core.controller
|
||||
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._
|
||||
@@ -184,7 +185,8 @@ case class Context(settings: SystemSettingsService.SystemSettings, loginAccount:
|
||||
val currentPath = request.getRequestURI.substring(request.getContextPath.length)
|
||||
val baseUrl = settings.baseUrl(request)
|
||||
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 {
|
||||
case null => null
|
||||
case agent if agent.contains("Mac") => "mac"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.service.SystemSettingsService.SshAddress
|
||||
import gitbucket.core.model.{Collaborator, Repository, Account}
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.util.{JGitUtil, RepoBase}
|
||||
import gitbucket.core.util.JGitUtil
|
||||
import profile.simple._
|
||||
|
||||
trait RepositoryService { self: AccountService =>
|
||||
@@ -391,8 +392,6 @@ object RepositoryService {
|
||||
issueCount: Int, pullCount: Int, commitCount: Int, forkedCount: Int,
|
||||
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.
|
||||
*/
|
||||
@@ -412,13 +411,13 @@ object RepositoryService {
|
||||
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 =
|
||||
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
|
||||
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) =
|
||||
openRepoUrl(platform, sshUrl(userName))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import java.util.Date
|
||||
import gitbucket.core.service.SystemSettingsService.SshAddress
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
@@ -38,9 +39,6 @@ object WikiService {
|
||||
* @param date the commit 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 {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import gitbucket.core.service.SystemSettingsService.SshAddress
|
||||
|
||||
case class RepoBase(baseUrl:String, sshAddress:Option[SshAddress])
|
||||
@@ -60,7 +60,7 @@ object Markdown {
|
||||
pages: List[String])
|
||||
(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 = {
|
||||
val id = generateAnchorName(text)
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<script src="@assets/vendors/jquery-hotkeys/jquery.hotkeys.js"></script>
|
||||
@repository.map { repository =>
|
||||
@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>
|
||||
|
||||
@@ -80,8 +80,8 @@
|
||||
<div class="small">
|
||||
<strong id="repository-url-proto">HTTP</strong> <span class="mute">clone URL</span>
|
||||
</div>
|
||||
@helper.html.copy("repository-url-copy", repository.urls(repoBase).httpUrl){
|
||||
<input type="text" value="@repository.urls(repoBase).httpUrl" id="repository-url" class="form-control input-sm" readonly>
|
||||
@helper.html.copy("repository-url-copy", context.urls(repository).httpUrl){
|
||||
<input type="text" value="@context.urls(repository).httpUrl" id="repository-url" class="form-control input-sm" readonly>
|
||||
}
|
||||
@if(settings.ssh && loginAccount.isDefined){
|
||||
<div class="small">
|
||||
@@ -91,7 +91,7 @@
|
||||
@id.map { id =>
|
||||
@if(context.platform != "linux" && context.platform != null){
|
||||
<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> 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> Clone in Desktop</a>
|
||||
</div>
|
||||
}
|
||||
<div style="margin-top: 10px;">
|
||||
@@ -184,15 +184,15 @@ $(function(){
|
||||
@if(settings.ssh && loginAccount.isDefined){
|
||||
$('#repository-url-http').click(function(){
|
||||
$('#repository-url-proto').text('HTTP');
|
||||
$('#repository-url').val('@repository.urls(repoBase).httpUrl');
|
||||
$('#repository-clone-url').attr('href', '@repository.urls(repoBase).httpOpenRepoUrl(context.platform)')
|
||||
$('#repository-url').val('@context.urls(repository).httpUrl');
|
||||
$('#repository-clone-url').attr('href', '@context.urls(repository).httpOpenRepoUrl(context.platform)')
|
||||
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
|
||||
});
|
||||
|
||||
$('#repository-url-ssh').click(function(){
|
||||
$('#repository-url-proto').text('SSH');
|
||||
$('#repository-url').val('@repository.urls(repoBase).sshUrl(loginAccount.get.userName)');
|
||||
$('#repository-clone-url').attr('href', '@repository.urls(repoBase).sshOpenRepoUrl(context.platform, loginAccount.get.userName)');
|
||||
$('#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-copy').attr('data-clipboard-text', $('#repository-url').val());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,21 +100,21 @@
|
||||
you can perform a manual merge on the command line.
|
||||
</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">
|
||||
<button class="btn btn-small active" type="button" id="repository-url-http">HTTP</button>
|
||||
@if(settings.ssh && loginAccount.isDefined){
|
||||
<button class="btn btn-small" type="button" id="repository-url-ssh" style="border-radius: 0px;">SSH</button>
|
||||
}
|
||||
</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>
|
||||
<p>
|
||||
<span class="strong">Step 1:</span> From your project repository, check out a new branch and test the changes.
|
||||
</p>
|
||||
@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){
|
||||
<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){
|
||||
$('#repository-url-http').click(function(){
|
||||
// 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());
|
||||
// Update command guidance
|
||||
$('#merge-command').text($('#merge-command').text().replace(
|
||||
'@forkedRepository.urls(repoBase).sshUrl(loginAccount.get.userName)',
|
||||
'@forkedRepository.urls(repoBase).httpUrl'
|
||||
'@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)',
|
||||
'@context.urls(forkedRepository).httpUrl'
|
||||
));
|
||||
$('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text());
|
||||
});
|
||||
|
||||
$('#repository-url-ssh').click(function(){
|
||||
// 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());
|
||||
// Update command guidance
|
||||
$('#merge-command').text($('#merge-command').text().replace(
|
||||
'@forkedRepository.urls(repoBase).httpUrl',
|
||||
'@forkedRepository.urls(repoBase).sshUrl(loginAccount.get.userName)'
|
||||
'@context.urls(forkedRepository).httpUrl',
|
||||
'@context.urls(forkedRepository).sshUrl(loginAccount.get.userName)'
|
||||
));
|
||||
$('#merge-command-copy-1').attr('data-clipboard-text', $('#merge-command').text());
|
||||
});
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
} else {
|
||||
<h3><strong>Quick setup</strong> — if you've done this kind of thing before</h3>
|
||||
<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){
|
||||
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>
|
||||
<h3 style="margin-top: 30px;">Create a new repository on the command line</h3>
|
||||
@@ -22,12 +22,12 @@
|
||||
git init
|
||||
git add README.md
|
||||
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
|
||||
}
|
||||
<h3 style="margin-top: 30px;">Push an existing repository from the command line</h3>
|
||||
@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
|
||||
}
|
||||
<script>
|
||||
|
||||
@@ -67,8 +67,8 @@
|
||||
<div class="small">
|
||||
<strong>Clone this wiki locally</strong>
|
||||
</div>
|
||||
@helper.html.copy("repository-url-copy", urls(repoBase, repository).httpUrl){
|
||||
<input type="text" value="@urls(repoBase, repository).httpUrl" id="repository-url" class="form-control input-sm" readonly>
|
||||
@helper.html.copy("repository-url-copy", context.wikiUrls(repository).httpUrl){
|
||||
<input type="text" value="@context.wikiUrls(repository).httpUrl" id="repository-url" class="form-control input-sm" readonly>
|
||||
}
|
||||
@if(settings.ssh && loginAccount.isDefined){
|
||||
<div class="small">
|
||||
@@ -133,11 +133,11 @@ $(function(){
|
||||
|
||||
@if(settings.ssh && loginAccount.isDefined){
|
||||
$('#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-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());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user