diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala index 344969e..d118fa4 100644 --- a/src/main/scala/gitbucket/core/controller/ApiController.scala +++ b/src/main/scala/gitbucket/core/controller/ApiController.scala @@ -133,9 +133,12 @@ val largeFile = params.get("large_file").exists(s => s.equals("true")) val content = getContentFromId(git, f.id, largeFile) request.getHeader("Accept") match { - case "application/vnd.github.v3.raw" => + case "application/vnd.github.v3.raw" => { + contentType = "application/vnd.github.v3.raw" content - case "application/vnd.github.v3.html" if isRenderable(f.name) => + } + case "application/vnd.github.v3.html" if isRenderable(f.name) => { + contentType = "application/vnd.github.v3.html" content.map(c => List( "
", "
", @@ -143,7 +146,9 @@ "
", "
" ).mkString ) - case "application/vnd.github.v3.html" => + } + case "application/vnd.github.v3.html" => { + contentType = "application/vnd.github.v3.html" content.map(c => List( "
", "
", "
",
@@ -151,6 +156,7 @@
                   "
", "
", "
" ).mkString ) + } case _ => Some(JsonFormat(ApiContents(f, content))) } @@ -278,6 +284,19 @@ } /** + * https://developer.github.com/v3/issues/#get-a-single-issue + */ + get("/api/v3/repos/:owner/:repository/issues/:id")(referrersOnly { repository => + (for{ + issueId <- params("id").toIntOpt + issue <- getIssue(repository.owner, repository.name, issueId.toString) + openedUser <- getAccountByUserName(issue.openedUserName) + } yield { + JsonFormat(ApiIssue(issue, RepositoryName(repository), ApiUser(openedUser))) + }) getOrElse NotFound() + }) + + /** * https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue */ get("/api/v3/repos/:owner/:repository/issues/:id/comments")(referrersOnly { repository => diff --git a/src/main/scala/gitbucket/core/controller/DashboardController.scala b/src/main/scala/gitbucket/core/controller/DashboardController.scala index 9aec00f..81e3085 100644 --- a/src/main/scala/gitbucket/core/controller/DashboardController.scala +++ b/src/main/scala/gitbucket/core/controller/DashboardController.scala @@ -76,7 +76,7 @@ }, filter, getGroupNames(userName), - getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true), + Nil, getUserRepositories(userName, withoutPhysicalInfo = true)) } @@ -101,7 +101,7 @@ }, filter, getGroupNames(userName), - getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true), + Nil, getUserRepositories(userName, withoutPhysicalInfo = true)) } diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index 2ef0490..6b4db67 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -131,13 +131,8 @@ }) // TODO Move to RepositoryViwerController? - post("/search", searchForm){ form => - redirect(s"/${form.owner}/${form.repository}/search?q=${StringUtil.urlEncode(form.query)}") - } - - // TODO Move to RepositoryViwerController? get("/:owner/:repository/search")(referrersOnly { repository => - defining(params("q").trim, params.getOrElse("type", "code")){ case (query, target) => + defining(params.getOrElse("q", "").trim, params.getOrElse("type", "code")){ case (query, target) => val page = try { val i = params.getOrElse("page", "1").toInt if(i <= 0) 1 else i @@ -160,4 +155,18 @@ } } }) + + get("/search"){ + val query = params.getOrElse("query", "").trim.toLowerCase + val visibleRepositories = getVisibleRepositories(context.loginAccount, None) + val repositories = visibleRepositories.filter { repository => + repository.name.toLowerCase.indexOf(query) >= 0 || repository.owner.toLowerCase.indexOf(query) >= 0 + } + context.loginAccount.map { account => + gitbucket.core.search.html.repositories(query, repositories, Nil, getUserRepositories(account.userName, withoutPhysicalInfo = true)) + }.getOrElse { + gitbucket.core.search.html.repositories(query, repositories, visibleRepositories, Nil) + } + } + } diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala index be35a20..b0b30f5 100644 --- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala @@ -238,7 +238,7 @@ val dummyWebHookInfo = WebHook(repository.owner, repository.name, url, ctype, token) val dummyPayload = { val ownerAccount = getAccountByUserName(repository.owner).get - val commits = if(repository.commitCount == 0) List.empty else git.log + val commits = if(JGitUtil.isEmpty(git)) List.empty else git.log .add(git.getRepository.resolve(repository.repository.defaultBranch)) .setMaxCount(4) .call.iterator.asScala.map(new CommitInfo(_)).toList diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 701a66c..8bcd5ad 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -546,10 +546,10 @@ * @return HTML of the file list */ private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = { - if(repository.commitCount == 0){ - html.guide(repository, hasDeveloperRole(repository.owner, repository.name, context.loginAccount)) - } else { - using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git => + using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git => + if(JGitUtil.isEmpty(git)){ + html.guide(repository, hasDeveloperRole(repository.owner, repository.name, context.loginAccount)) + } else { // get specified commit JGitUtil.getDefaultBranch(git, repository, revstr).map { case (objectId, revision) => defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit => @@ -569,9 +569,14 @@ html.files(revision, repository, if(path == ".") Nil else path.split("/").toList, // current path new JGitUtil.CommitInfo(lastModifiedCommit), // last modified commit - files, readme, hasDeveloperRole(repository.owner, repository.name, context.loginAccount), + JGitUtil.getCommitCount(repository.owner, repository.name, revision), + files, + readme, + hasDeveloperRole(repository.owner, repository.name, context.loginAccount), getPullRequestFromBranch(repository.owner, repository.name, revstr, repository.repository.defaultBranch), - flash.get("info"), flash.get("error")) + flash.get("info"), + flash.get("error") + ) } } getOrElse NotFound() } diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 67ebf72..30b4d5c 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -421,26 +421,20 @@ object RepositoryService { case class RepositoryInfo(owner: String, name: String, repository: Repository, - issueCount: Int, pullCount: Int, commitCount: Int, forkedCount: Int, + issueCount: Int, pullCount: Int, forkedCount: Int, branchList: Seq[String], tags: Seq[JGitUtil.TagInfo], managers: Seq[String]) { /** * 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, model, - issueCount, pullCount, repo.commitCount, forkedCount, - repo.branchList, repo.tags, managers) + this(repo.owner, repo.name, model, issueCount, pullCount, 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, model, - 0, 0, repo.commitCount, forkedCount, - repo.branchList, repo.tags, managers) + this(repo.owner, repo.name, model, 0, 0, forkedCount, repo.branchList, repo.tags, managers) def httpUrl(implicit context: Context): String = RepositoryService.httpUrl(owner, name) def sshUrl(implicit context: Context): Option[String] = RepositoryService.sshUrl(owner, name) @@ -454,7 +448,6 @@ (id, path.substring(id.length).stripPrefix("/")) } - } def httpUrl(owner: String, name: String)(implicit context: Context): String = s"${context.baseUrl}/git/${owner}/${name}.git" diff --git a/src/main/scala/gitbucket/core/util/JGitUtil.scala b/src/main/scala/gitbucket/core/util/JGitUtil.scala index 7d240d6..94063ac 100644 --- a/src/main/scala/gitbucket/core/util/JGitUtil.scala +++ b/src/main/scala/gitbucket/core/util/JGitUtil.scala @@ -32,14 +32,11 @@ * * @param owner the user name of the repository owner * @param name the repository name - * @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, commitCount: Int, branchList: List[String], tags: List[TagInfo]){ - def this(owner: String, name: String) = { - this(owner, name, 0, Nil, Nil) - } + case class RepositoryInfo(owner: String, name: String, branchList: List[String], tags: List[TagInfo]){ + def this(owner: String, name: String) = this(owner, name, Nil, Nil) } /** @@ -169,6 +166,18 @@ revWalk.dispose revCommit } + + /** + * Returns the number of commits in the specified branch or commit. + * If the specified branch has over 10000 commits, this method returns 100001. + */ + def getCommitCount(owner: String, repository: String, branch: String): Int = { + using(Git.open(getRepositoryDir(owner, repository))){ git => + val commitId = git.getRepository.resolve(branch) + val commitCount = git.log.add(commitId).call.iterator.asScala.take(10001).size + commitCount + } + } /** * Returns the repository information. It contains branch names and tag names. @@ -176,13 +185,7 @@ 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, - // commit count - commitCount, + RepositoryInfo(owner, repository, // branches git.branchList.call.asScala.map { ref => ref.getName.stripPrefix("refs/heads/") @@ -195,9 +198,7 @@ ) } catch { // not initialized - case e: NoHeadException => RepositoryInfo( - owner, repository, 0, Nil, Nil) - + case e: NoHeadException => RepositoryInfo(owner, repository, Nil, Nil) } } } @@ -212,7 +213,7 @@ */ def getFileList(git: Git, revision: String, path: String = "."): List[FileInfo] = { using(new RevWalk(git.getRepository)){ revWalk => - val objectId = git.getRepository.resolve(revision) + val objectId = git.getRepository.resolve(revision) if(objectId == null) return Nil val revCommit = revWalk.parseCommit(objectId) diff --git a/src/main/twirl/gitbucket/core/dashboard/sidebar.scala.html b/src/main/twirl/gitbucket/core/dashboard/sidebar.scala.html index f6db4a0..faf5d5a 100644 --- a/src/main/twirl/gitbucket/core/dashboard/sidebar.scala.html +++ b/src/main/twirl/gitbucket/core/dashboard/sidebar.scala.html @@ -12,21 +12,15 @@ @if(userRepositories.isEmpty){
  • No repositories
  • } else { - @defining(10){ max => - @userRepositories.zipWithIndex.map { case (repository, i) => -
  • + @userRepositories.zipWithIndex.map { case (repository, i) => + - } - @if(userRepositories.size > max){ -
  • - Show @{userRepositories.size - max} more repositories... -
  • - } + } } } else { @@ -34,17 +28,11 @@ @if(recentRepositories.isEmpty){
  • No repositories
  • } else { - @defining(10){ max => - @recentRepositories.zipWithIndex.map { case (repository, i) => - - } - @if(recentRepositories.size > max){ -
  • - Show @{recentRepositories.size - max} more repositories... -
  • - } +
  • + @recentRepositories.zipWithIndex.map { case (repository, i) => + } } } @@ -58,9 +46,21 @@ diff --git a/src/main/twirl/gitbucket/core/issues/list.scala.html b/src/main/twirl/gitbucket/core/issues/list.scala.html index 300f113..70d2f39 100644 --- a/src/main/twirl/gitbucket/core/issues/list.scala.html +++ b/src/main/twirl/gitbucket/core/issues/list.scala.html @@ -21,15 +21,22 @@ Closed @closedCount -
    - @if(isEditable){ - @if(target == "issues"){ - New issue + +
    + + + + + +
    + @if(isEditable){ + @if(target == "issues"){ + New issue + } + @if(target == "pulls"){ + New pull request + } } - @if(target == "pulls"){ - New pull request - } - }
    @gitbucket.core.issues.html.listparts(target, issues, page, openCount, closedCount, condition, collaborators, milestones, labels, Some(repository), isManageable) @if(isManageable){ diff --git a/src/main/twirl/gitbucket/core/main.scala.html b/src/main/twirl/gitbucket/core/main.scala.html index 5f78e73..9abc816 100644 --- a/src/main/twirl/gitbucket/core/main.scala.html +++ b/src/main/twirl/gitbucket/core/main.scala.html @@ -53,15 +53,11 @@ Toggle navigation } - @repository.map { repository => - - } +