cleanup: jgit repo info does not have to know about urls in the gui

This commit is contained in:
Herr Ritschwumm
2016-01-29 01:34:59 +01:00
parent 518f0bfc28
commit 86163f66ce
2 changed files with 37 additions and 21 deletions

View File

@@ -205,8 +205,9 @@ trait RepositoryService { self: AccountService =>
}.map(_.pullRequest).list
new RepositoryInfo(
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl),
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName),
repository,
baseUrl,
issues.count(_ == false),
issues.count(_ == true),
getForkedCount(
@@ -242,11 +243,12 @@ trait RepositoryService { self: AccountService =>
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
new RepositoryInfo(
if(withoutPhysicalInfo){
new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName)
} else {
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName)
},
repository,
baseUrl,
getForkedCount(
repository.originUserName.getOrElse(repository.userName),
repository.originRepositoryName.getOrElse(repository.repositoryName)
@@ -284,11 +286,12 @@ trait RepositoryService { self: AccountService =>
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
new RepositoryInfo(
if(withoutPhysicalInfo){
new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName)
} else {
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl)
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName)
},
repository,
baseUrl,
getForkedCount(
repository.originUserName.getOrElse(repository.userName),
repository.originRepositoryName.getOrElse(repository.repositoryName)
@@ -389,14 +392,18 @@ trait RepositoryService { self: AccountService =>
object RepositoryService {
case class RepositoryInfo(owner: String, name: String, httpUrl: String, repository: Repository,
object RepositoryInfo {
def httpUrl(baseUrl:String, owner:String, name:String):String = s"${baseUrl}/git/${owner}/${name}.git"
def sshUrl(baseUrl:String, owner:String, name:String)(port: Int, userName: String):String = {
val host = """^https?://(.+?)(:\d+)?/""".r.findFirstMatchIn(baseUrl).get.group(1)
s"ssh://${userName}@${host}:${port}/${owner}/${name}.git"
}
}
case class RepositoryInfo(owner: String, name: String, repository: Repository,
httpUrl: String, sshUrl:(Int, String)=>String,
issueCount: Int, pullCount: Int, commitCount: Int, forkedCount: Int,
branchList: Seq[String], tags: Seq[JGitUtil.TagInfo], managers: Seq[String]){
lazy val host = """^https?://(.+?)(:\d+)?/""".r.findFirstMatchIn(httpUrl).get.group(1)
def sshUrl(port: Int, userName: String) = s"ssh://${userName}@${host}:${port}/${owner}/${name}.git"
def sshOpenRepoUrl(platform: String, port: Int, userName: String) = openRepoUrl(platform, sshUrl(port, userName))
def httpOpenRepoUrl(platform: String) = openRepoUrl(platform, httpUrl)
@@ -406,14 +413,24 @@ object RepositoryService {
/**
* Creates instance with issue count and pull request count.
*/
def this(repo: JGitUtil.RepositoryInfo, model: Repository, issueCount: Int, pullCount: Int, forkedCount: Int, managers: Seq[String]) =
this(repo.owner, repo.name, repo.url, model, issueCount, pullCount, repo.commitCount, forkedCount, repo.branchList, repo.tags, managers)
def this(repo: JGitUtil.RepositoryInfo, model: Repository, baseUrl:String, issueCount: Int, pullCount: Int, forkedCount: Int, managers: Seq[String]) =
this(
repo.owner, repo.name, model,
RepositoryInfo.httpUrl(baseUrl, repo.owner, repo.name),
RepositoryInfo.sshUrl(baseUrl, repo.owner, repo.name),
issueCount, pullCount,
repo.commitCount, forkedCount, repo.branchList, repo.tags, managers)
/**
* Creates instance without issue count and pull request count.
*/
def this(repo: JGitUtil.RepositoryInfo, model: Repository, forkedCount: Int, managers: Seq[String]) =
this(repo.owner, repo.name, repo.url, model, 0, 0, repo.commitCount, forkedCount, repo.branchList, repo.tags, managers)
def this(repo: JGitUtil.RepositoryInfo, model: Repository, baseUrl:String, forkedCount: Int, managers: Seq[String]) =
this(
repo.owner, repo.name, model,
RepositoryInfo.httpUrl(baseUrl, repo.owner, repo.name),
RepositoryInfo.sshUrl(baseUrl, repo.owner, repo.name),
0, 0,
repo.commitCount, forkedCount, repo.branchList, repo.tags, managers)
}
case class RepositoryTreeNode(owner: String, name: String, children: List[RepositoryTreeNode])

View File

@@ -32,14 +32,13 @@ object JGitUtil {
*
* @param owner the user name of the repository owner
* @param name the repository name
* @param url the repository URL
* @param commitCount the commit count. If the repository has over 1000 commits then this property is 1001.
* @param branchList the list of branch names
* @param tags the list of tags
*/
case class RepositoryInfo(owner: String, name: String, url: String, commitCount: Int, branchList: List[String], tags: List[TagInfo]){
def this(owner: String, name: String, baseUrl: String) = {
this(owner, name, s"${baseUrl}/git/${owner}/${name}.git", 0, Nil, Nil)
case class RepositoryInfo(owner: String, name: String, commitCount: Int, branchList: List[String], tags: List[TagInfo]){
def this(owner: String, name: String) = {
this(owner, name, 0, Nil, Nil)
}
}
@@ -174,14 +173,14 @@ object JGitUtil {
/**
* Returns the repository information. It contains branch names and tag names.
*/
def getRepositoryInfo(owner: String, repository: String, baseUrl: String): RepositoryInfo = {
def getRepositoryInfo(owner: String, repository: String): RepositoryInfo = {
using(Git.open(getRepositoryDir(owner, repository))){ git =>
try {
// get commit count
val commitCount = git.log.all.call.iterator.asScala.map(_ => 1).take(10001).sum
RepositoryInfo(
owner, repository, s"${baseUrl}/git/${owner}/${repository}.git",
owner, repository,
// commit count
commitCount,
// branches
@@ -197,7 +196,7 @@ object JGitUtil {
} catch {
// not initialized
case e: NoHeadException => RepositoryInfo(
owner, repository, s"${baseUrl}/git/${owner}/${repository}.git", 0, Nil, Nil)
owner, repository, 0, Nil, Nil)
}
}