Skip to content

Commit caa0a0a

Browse files
committed
(refs #10)Display ssh url
1 parent ecc8a39 commit caa0a0a

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

src/main/scala/gitbucket/gist/controller/GistController.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ trait GistControllerBase extends ControllerBase {
205205
}
206206
}
207207
val gist = getGist(userName, repoName).get
208-
html.revisions("revision", gist, repositoryUrl(gist, baseUrl), isEditable(userName), commits)
208+
html.revisions(
209+
"revision",
210+
gist,
211+
GistRepositoryURL(gist, baseUrl, context.settings),
212+
isEditable(userName),
213+
commits
214+
)
209215
}
210216
case Left(_) => NotFound
211217
}
@@ -317,7 +323,14 @@ trait GistControllerBase extends ControllerBase {
317323
val files: Seq[(String, String)] = JGitUtil.getFileList(git, revision, ".").map { file =>
318324
file.name -> StringUtil.convertFromByteArray(JGitUtil.getContentFromId(git, file.id, true).get)
319325
}
320-
html.detail("code", gist, repositoryUrl(gist, baseUrl), revision, files, isEditable(userName))
326+
html.detail(
327+
"code",
328+
gist,
329+
GistRepositoryURL(gist, baseUrl, context.settings),
330+
revision,
331+
files,
332+
isEditable(userName)
333+
)
321334
} else Unauthorized
322335
}
323336
} else NotFound

src/main/scala/gitbucket/gist/util/GistUtils.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package gitbucket.gist.util
22

33
import gitbucket.core.controller.Context
44
import gitbucket.core.model.Account
5+
import gitbucket.core.service.SystemSettingsService
6+
import gitbucket.core.service.SystemSettingsService.SystemSettings
57
import gitbucket.core.util.JGitUtil
68
import gitbucket.gist.model.Gist
79
import org.eclipse.jgit.api.Git
@@ -40,6 +42,15 @@ object GistUtils {
4042

4143
def getTitle(fileName: String, repoName: String): String = if(isGistFile(fileName)) repoName else fileName
4244

43-
def repositoryUrl(gist: Gist, baseUrl: String) = s"${baseUrl}/git/gist/${gist.userName}/${gist.repositoryName}.git"
45+
case class GistRepositoryURL(gist: Gist, baseUrl: String, settings: SystemSettings){
46+
47+
def httpUrl: String = s"${baseUrl}/git/gist/${gist.userName}/${gist.repositoryName}.git"
48+
49+
def sshUrl(loginUser: String): String = {
50+
val host = """^https?://(.+?)(:\d+)?/""".r.findFirstMatchIn(httpUrl).get.group(1)
51+
s"ssh://${loginUser}@${host}:${settings.sshPort.getOrElse(SystemSettingsService.DefaultSshPort)}/gist/${gist.userName}/${gist.repositoryName}.git"
52+
}
53+
54+
}
4455

4556
}

src/main/twirl/gitbucket/gist/detail.scala.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@(active: String,
22
gist: gitbucket.gist.model.Gist,
3-
repositoryUrl: String,
3+
repositoryUrl: gitbucket.gist.util.GistUtils.GistRepositoryURL,
44
revision: String,
55
files: Seq[(String, String)],
66
editable: Boolean)(implicit context: gitbucket.core.controller.Context)

src/main/twirl/gitbucket/gist/menu.scala.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@(active: String,
22
gist: gitbucket.gist.model.Gist,
3-
repositoryUrl: String)(implicit context: gitbucket.core.controller.Context)
3+
repositoryUrl: gitbucket.gist.util.GistUtils.GistRepositoryURL)(implicit context: gitbucket.core.controller.Context)
44
@import context._
55
@import gitbucket.core.helper
66
@import gitbucket.core.view.helpers._
@@ -44,8 +44,8 @@
4444
<div class="small">
4545
<strong id="repository-url-proto">HTTP</strong> <span class="mute">clone URL</span>
4646
</div>
47-
@helper.html.copy("repository-url-copy", repositoryUrl){
48-
<input type="text" value="@repositoryUrl" id="repository-url" readonly>
47+
@helper.html.copy("repository-url-copy", repositoryUrl.httpUrl){
48+
<input type="text" value="@repositoryUrl.httpUrl" id="repository-url" readonly>
4949
}
5050
@if(settings.ssh && loginAccount.isDefined){
5151
<div class="small">
@@ -61,3 +61,17 @@
6161
class="btn btn-small" style="width: 147px;"><i class="icon-download-alt"></i>Download TAR.GZ</a>
6262
</div>
6363
</div>
64+
@if(settings.ssh && loginAccount.isDefined){
65+
<script>
66+
$(function(){
67+
$('#repository-url-http').click(function(){
68+
$('#repository-url').val('@repositoryUrl.httpUrl');
69+
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
70+
});
71+
$('#repository-url-ssh').click(function(){
72+
$('#repository-url').val('@repositoryUrl.sshUrl(loginAccount.get.userName)');
73+
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
74+
});
75+
});
76+
</script>
77+
}

src/main/twirl/gitbucket/gist/revisions.scala.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@(active: String,
22
gist: gitbucket.gist.model.Gist,
3-
repositoryUrl: String,
3+
repositoryUrl: gitbucket.gist.util.GistUtils.GistRepositoryURL,
44
editable: Boolean,
55
revisions: List[(gitbucket.core.util.JGitUtil.CommitInfo, List[gitbucket.core.util.JGitUtil.DiffInfo])])(implicit context: gitbucket.core.controller.Context)
66
@import context._

0 commit comments

Comments
 (0)