aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/fixtures/release.yml1
-rw-r--r--models/release.go48
2 files changed, 27 insertions, 22 deletions
diff --git a/models/fixtures/release.yml b/models/fixtures/release.yml
new file mode 100644
index 0000000000..ca780a73aa
--- /dev/null
+++ b/models/fixtures/release.yml
@@ -0,0 +1 @@
+[] # empty
diff --git a/models/release.go b/models/release.go
index 783f1f0475..f12fc06840 100644
--- a/models/release.go
+++ b/models/release.go
@@ -233,40 +233,44 @@ func GetReleaseByID(id int64) (*Release, error) {
return rel, nil
}
-// GetReleasesByRepoID returns a list of releases of repository.
-func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err error) {
- if page <= 0 {
- page = 1
- }
- err = x.
- Desc("created_unix").
- Limit(pageSize, (page-1)*pageSize).
- Find(&rels, Release{RepoID: repoID})
- return rels, err
+// FindReleasesOptions describes the conditions to Find releases
+type FindReleasesOptions struct {
+ IncludeDrafts bool
+ TagNames []string
}
-// GetReleaseCountByRepoID returns the count of releases of repository
-func GetReleaseCountByRepoID(repoID int64, includeDrafts bool) (int64, error) {
+func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
var cond = builder.NewCond()
cond = cond.And(builder.Eq{"repo_id": repoID})
- if includeDrafts {
- return x.Where(cond).Count(&Release{})
+ if !opts.IncludeDrafts {
+ cond = cond.And(builder.Eq{"is_draft": false})
}
-
- cond = cond.And(builder.Eq{"is_draft": false})
- return x.Where(cond).Count(&Release{})
+ if len(opts.TagNames) > 0 {
+ cond = cond.And(builder.In("tag_name", opts.TagNames))
+ }
+ return cond
}
-// GetReleasesByRepoIDAndNames returns a list of releases of repository according repoID and tagNames.
-func GetReleasesByRepoIDAndNames(repoID int64, tagNames []string) (rels []*Release, err error) {
+// GetReleasesByRepoID returns a list of releases of repository.
+func GetReleasesByRepoID(repoID int64, opts FindReleasesOptions, page, pageSize int) (rels []*Release, err error) {
+ if page <= 0 {
+ page = 1
+ }
+
err = x.
- Desc("created_unix").
- In("tag_name", tagNames).
- Find(&rels, Release{RepoID: repoID})
+ Desc("created_unix", "id").
+ Limit(pageSize, (page-1)*pageSize).
+ Where(opts.toConds(repoID)).
+ Find(&rels)
return rels, err
}
+// GetReleaseCountByRepoID returns the count of releases of repository
+func GetReleaseCountByRepoID(repoID int64, opts FindReleasesOptions) (int64, error) {
+ return x.Where(opts.toConds(repoID)).Count(&Release{})
+}
+
type releaseMetaSearch struct {
ID []int64
Rel []*Release