Added Scaladoc.

This commit is contained in:
takezoe
2013-04-13 04:29:03 +09:00
parent 47182ec57f
commit 0d5657f248
3 changed files with 46 additions and 5 deletions

View File

@@ -20,6 +20,9 @@ case class CommitInfo(id: String, time: Date, committer: String, message: String
*/ */
class RepositoryViewerServlet extends ScalatraServlet with ServletBase { class RepositoryViewerServlet extends ScalatraServlet with ServletBase {
/**
* Shows user information.
*/
get("/:owner") { get("/:owner") {
val owner = params("owner") val owner = params("owner")
html.user.render(owner, getRepositories(owner).map(getRepositoryInfo(owner, _))) html.user.render(owner, getRepositories(owner).map(getRepositoryInfo(owner, _)))
@@ -109,7 +112,13 @@ class RepositoryViewerServlet extends ScalatraServlet with ServletBase {
CommitInfo(latestRev.getName, latestRev.getCommitterIdent.getWhen, latestRev.getCommitterIdent.getName, latestRev.getShortMessage)) 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)) val git = Git.open(getRepositoryDir(owner, repository))
RepositoryInfo( RepositoryInfo(
owner, repository, "http://localhost:8080/git/%s/%s.git".format(owner, repository), owner, repository, "http://localhost:8080/git/%s/%s.git".format(owner, repository),
@@ -127,8 +136,13 @@ class RepositoryViewerServlet extends ScalatraServlet with ServletBase {
/** /**
* Setup all branches for the repository viewer. * Setup all branches for the repository viewer.
* This method copies the repository and checkout branches. * 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 dir = getRepositoryDir(owner, repository)
val git = Git.open(dir) val git = Git.open(dir)
@@ -154,7 +168,13 @@ class RepositoryViewerServlet extends ScalatraServlet with ServletBase {
} }
/** /**
* 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 = ".") = { def fileList(owner: String, repository: String, branch: String = "", path: String = ".") = {
val branchName = if(branch.isEmpty){ val branchName = if(branch.isEmpty){

View File

@@ -2,20 +2,37 @@ package util
import java.io.File import java.io.File
/**
* Provides directories used by GitBucket.
*/
object Directory { object Directory {
val GitBucketHome = new File(System.getProperty("user.home"), "gitbucket").getAbsolutePath val GitBucketHome = new File(System.getProperty("user.home"), "gitbucket").getAbsolutePath
/**
* Repository names of the specified user.
*/
def getRepositories(owner: String): List[String] = def getRepositories(owner: String): List[String] =
new File("%s/repositories/%s".format(GitBucketHome, owner)) new File("%s/repositories/%s".format(GitBucketHome, owner))
.listFiles.filter(_.isDirectory).map(_.getName.replaceFirst("\\.git$", "")).toList .listFiles.filter(_.isDirectory).map(_.getName.replaceFirst("\\.git$", "")).toList
/**
* Substance directory of the repository.
*/
def getRepositoryDir(owner: String, repository: String): File = def getRepositoryDir(owner: String, repository: String): File =
new File("%s/repositories/%s/%s.git".format(GitBucketHome, owner, repository)) 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 = def getBranchDir(owner: String, repository: String, branch: String): File =
new File("%s/tmp/%s/branches/%s/%s".format(GitBucketHome, owner, repository, branch)) 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 = def getInitRepositoryDir(owner: String, repository: String): File =
new File("%s/tmp/%s/init-%s".format(GitBucketHome, owner, repository)) new File("%s/tmp/%s/init-%s".format(GitBucketHome, owner, repository))

View File

@@ -1,6 +1,10 @@
package util package util
/**
* Provides some usable implicit conversions.
*/
object Implicits { object Implicits {
implicit def extendsSeq[A](seq: Seq[A]) = new { implicit def extendsSeq[A](seq: Seq[A]) = new {
def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition) def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition)