(refs #1823) Link submodule to the online repository viewer

Supports following services:
- GitBucket (need to set the base url at the system settings)
- GitHub
- BitBucket
- GitLab.com
If a repository url doesn't match above services, generate a link to the git repository as before.
This commit is contained in:
Naoki Takezoe
2018-01-07 04:36:11 +09:00
parent 5e88f3f787
commit bbc817d86d
4 changed files with 46 additions and 19 deletions

View File

@@ -63,4 +63,24 @@ class StringUtilSpec extends FunSpec {
assert(StringUtil.extractCloseId("(refs #123)").toSeq == Nil)
}
}
describe("getRepositoryViewerUrl") {
val baseUrl = Some("http://localhost:8080")
it("should convert GitBucket repository url"){
assert(StringUtil.getRepositoryViewerUrl("http://localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket")
assert(StringUtil.getRepositoryViewerUrl("http://root@localhost:8080/git/root/gitbucket.git", baseUrl) == "http://localhost:8080/root/gitbucket")
}
it("should convert GitHub repository url"){
assert(StringUtil.getRepositoryViewerUrl("https://github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket")
assert(StringUtil.getRepositoryViewerUrl("https://root@github.com/root/gitbucket.git", baseUrl) == "https://github.com/root/gitbucket")
}
it("should convert BitBucket repository url"){
assert(StringUtil.getRepositoryViewerUrl("https://bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket")
assert(StringUtil.getRepositoryViewerUrl("https://root@bitbucket.org/root/gitbucket.git", baseUrl) == "https://bitbucket.org/root/gitbucket")
}
it("should convert GitLab repository url"){
assert(StringUtil.getRepositoryViewerUrl("https://gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket")
assert(StringUtil.getRepositoryViewerUrl("https://root@gitlab.com/root/gitbucket.git", baseUrl) == "https://gitlab.com/root/gitbucket")
}
}
}