aboutsummaryrefslogtreecommitdiffstats
path: root/models
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
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')
-rw-r--r--models/fixtures/release.yml27
-rw-r--r--models/release.go14
2 files changed, 33 insertions, 8 deletions
diff --git a/models/fixtures/release.yml b/models/fixtures/release.yml
index 5e577d3fdd..1703f959d2 100644
--- a/models/fixtures/release.yml
+++ b/models/fixtures/release.yml
@@ -1,5 +1,4 @@
--
- id: 1
+- id: 1
repo_id: 1
publisher_id: 2
tag_name: "v1.1"
@@ -13,8 +12,7 @@
is_tag: false
created_unix: 946684800
--
- id: 2
+- id: 2
repo_id: 40
publisher_id: 2
tag_name: "v1.1"
@@ -28,8 +26,7 @@
is_tag: false
created_unix: 946684800
--
- id: 3
+- id: 3
repo_id: 1
publisher_id: 2
tag_name: "delete-tag"
@@ -43,8 +40,7 @@
is_tag: true
created_unix: 946684800
--
- id: 4
+- id: 4
repo_id: 1
publisher_id: 2
tag_name: "draft-release"
@@ -55,3 +51,18 @@
is_prerelease: false
is_tag: false
created_unix: 1619524806
+
+- id: 5
+ repo_id: 1
+ publisher_id: 2
+ tag_name: "v1.0"
+ lower_tag_name: "v1.0"
+ target: "master"
+ title: "pre-release"
+ note: "some text for a pre release"
+ sha1: "65f1bf27bc3bf70f64657658635e66094edbcb4d"
+ num_commits: 1
+ is_draft: false
+ is_prerelease: true
+ is_tag: false
+ created_unix: 946684800
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().