[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
This commit is contained in:
parent
c9d053f0ca
commit
6ad5d0a306
9 changed files with 158 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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().
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue