diff --git a/src/main/scala/app/RepositoryViewerServlet.scala b/src/main/scala/app/RepositoryViewerServlet.scala index dd44cdc..f9b4c81 100644 --- a/src/main/scala/app/RepositoryViewerServlet.scala +++ b/src/main/scala/app/RepositoryViewerServlet.scala @@ -20,6 +20,9 @@ */ class RepositoryViewerServlet extends ScalatraServlet with ServletBase { + /** + * Shows user information. + */ get("/:owner") { val owner = params("owner") html.user.render(owner, getRepositories(owner).map(getRepositoryInfo(owner, _))) @@ -109,7 +112,13 @@ CommitInfo(latestRev.getName, latestRev.getCommitterIdent.getWhen, latestRev.getCommitterIdent.getName, latestRev.getShortMessage)) } - def getRepositoryInfo(owner: String, repository: String) = { + /** + * Returns the repository information. It contains branch names and tag names. + * + * @param owner the repository owner + * @param repository the repository name + */ + def getRepositoryInfo(owner: String, repository: String): RepositoryInfo = { val git = Git.open(getRepositoryDir(owner, repository)) RepositoryInfo( owner, repository, "http://localhost:8080/git/%s/%s.git".format(owner, repository), @@ -127,8 +136,13 @@ /** * Setup all branches for the repository viewer. * This method copies the repository and checkout branches. + * + * TODO Should it be a repository update hook? + * + * @param owner the repository owner + * @param repository the repository name */ - def updateAllBranches(owner: String, repository: String) = { + def updateAllBranches(owner: String, repository: String): Unit = { val dir = getRepositoryDir(owner, repository) val git = Git.open(dir) @@ -154,7 +168,13 @@ } /** - * Provides the file list of the specified branch and path. + * Provides HTML of the file list. + * + * @param owner the repository owner + * @param repository the repository name + * @param branch the branch name (optional) + * @param path the directory path (optional) + * @return HTML of the file list */ def fileList(owner: String, repository: String, branch: String = "", path: String = ".") = { val branchName = if(branch.isEmpty){ diff --git a/src/main/scala/util/Directory.scala b/src/main/scala/util/Directory.scala index 5f80f72..8a90349 100644 --- a/src/main/scala/util/Directory.scala +++ b/src/main/scala/util/Directory.scala @@ -2,20 +2,37 @@ import java.io.File +/** + * Provides directories used by GitBucket. + */ object Directory { val GitBucketHome = new File(System.getProperty("user.home"), "gitbucket").getAbsolutePath - + + /** + * Repository names of the specified user. + */ def getRepositories(owner: String): List[String] = new File("%s/repositories/%s".format(GitBucketHome, owner)) .listFiles.filter(_.isDirectory).map(_.getName.replaceFirst("\\.git$", "")).toList - + + /** + * Substance directory of the repository. + */ def getRepositoryDir(owner: String, repository: String): File = new File("%s/repositories/%s/%s.git".format(GitBucketHome, owner, repository)) + /** + * Temporary directory which is used in the repository viewer. + */ def getBranchDir(owner: String, repository: String, branch: String): File = new File("%s/tmp/%s/branches/%s/%s".format(GitBucketHome, owner, repository, branch)) + /** + * Temporary directory which is used in the repository creation. + * GiyBucket generates initial repository contents in this directory and push them. + * This directory is removed after the repository creation. + */ def getInitRepositoryDir(owner: String, repository: String): File = new File("%s/tmp/%s/init-%s".format(GitBucketHome, owner, repository)) diff --git a/src/main/scala/util/Implicits.scala b/src/main/scala/util/Implicits.scala index dbf60d9..2d044e6 100644 --- a/src/main/scala/util/Implicits.scala +++ b/src/main/scala/util/Implicits.scala @@ -1,6 +1,10 @@ package util +/** + * Provides some usable implicit conversions. + */ object Implicits { + implicit def extendsSeq[A](seq: Seq[A]) = new { def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition)