aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--integrations/api_repo_test.go22
-rw-r--r--models/repo.go5
-rw-r--r--modules/context/repo.go3
-rw-r--r--templates/repo/header.tmpl2
4 files changed, 25 insertions, 7 deletions
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go
index ff59fac5cb..d57e5daaf3 100644
--- a/integrations/api_repo_test.go
+++ b/integrations/api_repo_test.go
@@ -209,13 +209,31 @@ func getRepo(t *testing.T, repoID int64) *models.Repository {
func TestAPIViewRepo(t *testing.T) {
defer prepareTestEnv(t)()
+ var repo api.Repository
+
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1")
resp := MakeRequest(t, req, http.StatusOK)
-
- var repo api.Repository
DecodeJSON(t, resp, &repo)
assert.EqualValues(t, 1, repo.ID)
assert.EqualValues(t, "repo1", repo.Name)
+ assert.EqualValues(t, 1, repo.Releases)
+ assert.EqualValues(t, 1, repo.OpenIssues)
+ assert.EqualValues(t, 3, repo.OpenPulls)
+
+ req = NewRequest(t, "GET", "/api/v1/repos/user12/repo10")
+ resp = MakeRequest(t, req, http.StatusOK)
+ DecodeJSON(t, resp, &repo)
+ assert.EqualValues(t, 10, repo.ID)
+ assert.EqualValues(t, "repo10", repo.Name)
+ assert.EqualValues(t, 1, repo.OpenPulls)
+ assert.EqualValues(t, 1, repo.Forks)
+
+ req = NewRequest(t, "GET", "/api/v1/repos/user5/repo4")
+ resp = MakeRequest(t, req, http.StatusOK)
+ DecodeJSON(t, resp, &repo)
+ assert.EqualValues(t, 4, repo.ID)
+ assert.EqualValues(t, "repo4", repo.Name)
+ assert.EqualValues(t, 1, repo.Stars)
}
func TestAPIOrgRepos(t *testing.T) {
diff --git a/models/repo.go b/models/repo.go
index 8f0736ef82..a901c3476b 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -166,7 +166,6 @@ type Repository struct {
NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumOpenMilestones int `xorm:"-"`
- NumReleases int `xorm:"-"`
IsPrivate bool `xorm:"INDEX"`
IsEmpty bool `xorm:"INDEX"`
@@ -353,6 +352,8 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
repo.mustOwner(e)
+ numReleases, _ := GetReleaseCountByRepoID(repo.ID, FindReleasesOptions{IncludeDrafts: false, IncludeTags: true})
+
return &api.Repository{
ID: repo.ID,
Owner: repo.Owner.APIFormat(),
@@ -376,7 +377,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
Watchers: repo.NumWatches,
OpenIssues: repo.NumOpenIssues,
OpenPulls: repo.NumOpenPulls,
- Releases: repo.NumReleases,
+ Releases: int(numReleases),
DefaultBranch: repo.DefaultBranch,
Created: repo.CreatedUnix.AsTime(),
Updated: repo.UpdatedUnix.AsTime(),
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 1f6e5037cc..841dcd960e 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -439,7 +439,7 @@ func RepoAssignment() macaron.Handler {
ctx.Data["RepoExternalIssuesLink"] = unit.ExternalTrackerConfig().ExternalTrackerURL
}
- count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
+ ctx.Data["NumReleases"], err = models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
IncludeDrafts: false,
IncludeTags: true,
})
@@ -447,7 +447,6 @@ func RepoAssignment() macaron.Handler {
ctx.ServerError("GetReleaseCountByRepoID", err)
return
}
- ctx.Repo.Repository.NumReleases = int(count)
ctx.Data["Title"] = owner.Name + "/" + repo.Name
ctx.Data["Repository"] = repo
diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl
index 1fc298bcba..f4edc74396 100644
--- a/templates/repo/header.tmpl
+++ b/templates/repo/header.tmpl
@@ -117,7 +117,7 @@
{{if and (.Permission.CanRead $.UnitTypeReleases) (not .IsEmptyRepo) }}
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
- {{svg "octicon-tag" 16}} {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .Repository.NumReleases}}gray{{else}}blue{{end}} small label">{{.Repository.NumReleases}}</span>
+ {{svg "octicon-tag" 16}} {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .NumReleases}}gray{{else}}blue{{end}} small label">{{.NumReleases}}</span>
</a>
{{end}}