Skip to content

Commit

Permalink
Show the number of milestones on the sidebar menu (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
SIkebe committed Aug 2, 2020
1 parent 72e40a0 commit 36643bc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
31 changes: 28 additions & 3 deletions src/main/scala/gitbucket/core/service/RepositoryService.scala
Expand Up @@ -342,6 +342,10 @@ trait RepositoryService {
repository.originUserName.getOrElse(repository.userName),
repository.originRepositoryName.getOrElse(repository.repositoryName)
),
getOpenMilestones(
repository.originUserName.getOrElse(repository.userName),
repository.originRepositoryName.getOrElse(repository.repositoryName)
),
getRepositoryManagers(repository.userName, repository.repositoryName)
)
}
Expand Down Expand Up @@ -697,6 +701,14 @@ trait RepositoryService {
(t.originUserName === userName.bind) && (t.originRepositoryName === repositoryName.bind)
}.length).first

private def getOpenMilestones(userName: String, repositoryName: String)(implicit s: Session): Int =
Query(
Milestones
.filter(_.byRepository(userName, repositoryName))
.filter(_.closedDate.isEmpty)
.length
).first

def getForkedRepositories(userName: String, repositoryName: String)(implicit s: Session): List[Repository] =
Repositories
.filter { t =>
Expand Down Expand Up @@ -749,6 +761,7 @@ object RepositoryService {
issueCount: Int,
pullCount: Int,
forkedCount: Int,
milestoneCount: Int,
branchList: Seq[String],
tags: Seq[JGitUtil.TagInfo],
managers: Seq[String]
Expand All @@ -763,15 +776,27 @@ object RepositoryService {
issueCount: Int,
pullCount: Int,
forkedCount: Int,
milestoneCount: Int,
managers: Seq[String]
) =
this(repo.owner, repo.name, model, issueCount, pullCount, forkedCount, repo.branchList, repo.tags, managers)
this(
repo.owner,
repo.name,
model,
issueCount,
pullCount,
forkedCount,
milestoneCount,
repo.branchList,
repo.tags,
managers
)

/**
* Creates instance without issue and pull request count.
* Creates instance without issue, pull request, and milestone count.
*/
def this(repo: JGitUtil.RepositoryInfo, model: Repository, forkedCount: Int, managers: Seq[String]) =
this(repo.owner, repo.name, model, 0, 0, forkedCount, repo.branchList, repo.tags, managers)
this(repo.owner, repo.name, model, 0, 0, forkedCount, 0, 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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/twirl/gitbucket/core/menu.scala.html
Expand Up @@ -40,7 +40,7 @@
@menuitem("/pulls", "pulls", "Pull requests", "git-pull-request", repository.pullCount)
@menuitem("/issues/labels", "labels", "Labels", "tag")
@menuitem("/issues/priorities", "priorities", "Priorities", "flame")
@menuitem("/issues/milestones", "milestones", "Milestones", "milestone")
@menuitem("/issues/milestones", "milestones", "Milestones", "milestone", repository.milestoneCount)
} else {
@repository.repository.options.externalIssuesUrl.map { externalIssuesUrl =>
@menuitem(externalIssuesUrl, "issues", "Issues", "issue-opened")
Expand Down
1 change: 1 addition & 0 deletions src/test/scala/gitbucket/core/api/ApiSpecModels.scala
Expand Up @@ -79,6 +79,7 @@ object ApiSpecModels {
issueCount = 1,
pullCount = 1,
forkedCount = 1,
milestoneCount = 1,
branchList = Seq("master", "develop"),
tags = Seq(
TagInfo(name = "v1.0", time = date("2015-05-05T23:40:27Z"), id = "id1", message = "1.0 released"),
Expand Down

0 comments on commit 36643bc

Please sign in to comment.