aboutsummaryrefslogtreecommitdiffstats
path: root/models/release.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-06-17 10:58:10 +0200
committerGitHub <noreply@github.com>2021-06-17 10:58:10 +0200
commit6ad5d0a3062966515730aa1f8d62db5d2a7704ee (patch)
tree711b5814e4eb096e88b6f2ccbe597b0b00029275 /models/release.go
parentc9d053f0caa14e6fec4d04c009c79c9a0940c450 (diff)
downloadgitea-6ad5d0a3062966515730aa1f8d62db5d2a7704ee.tar.gz
gitea-6ad5d0a3062966515730aa1f8d62db5d2a7704ee.zip
[API] ListReleases add filter for draft and pre-releases (#16175)
* invent ctx.QueryOptionalBool * [API] ListReleases add draft and pre-release filter * Add X-Total-Count header * Add a release to fixtures * Add TEST for API ListReleases
Diffstat (limited to 'models/release.go')
-rw-r--r--models/release.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/models/release.go b/models/release.go
index 13b8f17218..1ce88a8210 100644
--- a/models/release.go
+++ b/models/release.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
@@ -173,6 +174,8 @@ type FindReleasesOptions struct {
ListOptions
IncludeDrafts bool
IncludeTags bool
+ IsPreRelease util.OptionalBool
+ IsDraft util.OptionalBool
TagNames []string
}
@@ -189,6 +192,12 @@ func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
if len(opts.TagNames) > 0 {
cond = cond.And(builder.In("tag_name", opts.TagNames))
}
+ if !opts.IsPreRelease.IsNone() {
+ cond = cond.And(builder.Eq{"is_prerelease": opts.IsPreRelease.IsTrue()})
+ }
+ if !opts.IsDraft.IsNone() {
+ cond = cond.And(builder.Eq{"is_draft": opts.IsDraft.IsTrue()})
+ }
return cond
}
@@ -206,6 +215,11 @@ func GetReleasesByRepoID(repoID int64, opts FindReleasesOptions) ([]*Release, er
return rels, sess.Find(&rels)
}
+// CountReleasesByRepoID returns a number of releases matching FindReleaseOptions and RepoID.
+func CountReleasesByRepoID(repoID int64, opts FindReleasesOptions) (int64, error) {
+ return x.Where(opts.toConds(repoID)).Count(new(Release))
+}
+
// GetLatestReleaseByRepoID returns the latest release for a repository
func GetLatestReleaseByRepoID(repoID int64) (*Release, error) {
cond := builder.NewCond().