Skip to content

Commit 371926c

Browse files
committed
[API] ListReleases add draft and pre-release filter
1 parent 9995475 commit 371926c

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

models/release.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/setting"
1515
"code.gitea.io/gitea/modules/structs"
1616
"code.gitea.io/gitea/modules/timeutil"
17+
"code.gitea.io/gitea/modules/util"
1718

1819
"xorm.io/builder"
1920
)
@@ -173,6 +174,8 @@ type FindReleasesOptions struct {
173174
ListOptions
174175
IncludeDrafts bool
175176
IncludeTags bool
177+
IsPreRelease util.OptionalBool
178+
IsDraft util.OptionalBool
176179
TagNames []string
177180
}
178181

@@ -189,6 +192,12 @@ func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
189192
if len(opts.TagNames) > 0 {
190193
cond = cond.And(builder.In("tag_name", opts.TagNames))
191194
}
195+
if !opts.IsPreRelease.IsNone() {
196+
cond = cond.And(builder.Eq{"is_prerelease": opts.IsPreRelease.IsTrue()})
197+
}
198+
if !opts.IsDraft.IsNone() {
199+
cond = cond.And(builder.Eq{"is_draft": opts.IsDraft.IsTrue()})
200+
}
192201
return cond
193202
}
194203

routers/api/v1/repo/release.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ func ListReleases(ctx *context.APIContext) {
8383
// description: name of the repo
8484
// type: string
8585
// required: true
86+
// - name: draft
87+
// in: query
88+
// description: filter (exclude / include) drafts, if you dont have repo write access none will show
89+
// type: boolean
90+
// - name: pre-release
91+
// in: query
92+
// description: filter (exclude / include) pre-releases
93+
// type: boolean
8694
// - name: per_page
8795
// in: query
8896
// description: page size of results, deprecated - use limit
@@ -100,14 +108,16 @@ func ListReleases(ctx *context.APIContext) {
100108
// "200":
101109
// "$ref": "#/responses/ReleaseList"
102110
listOptions := utils.GetListOptions(ctx)
103-
if ctx.QueryInt("per_page") != 0 {
111+
if listOptions.PageSize == 0 && ctx.QueryInt("per_page") != 0 {
104112
listOptions.PageSize = ctx.QueryInt("per_page")
105113
}
106114

107115
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
108116
ListOptions: listOptions,
109117
IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite,
110118
IncludeTags: false,
119+
IsDraft: ctx.QueryOptionalBool("draft"),
120+
IsPreRelease: ctx.QueryOptionalBool("pre-release"),
111121
})
112122
if err != nil {
113123
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)

templates/swagger/v1_json.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8006,6 +8006,18 @@
80068006
"in": "path",
80078007
"required": true
80088008
},
8009+
{
8010+
"type": "boolean",
8011+
"description": "filter (exclude / include) drafts, if you dont have repo write access none will show",
8012+
"name": "draft",
8013+
"in": "query"
8014+
},
8015+
{
8016+
"type": "boolean",
8017+
"description": "filter (exclude / include) pre-releases",
8018+
"name": "pre-release",
8019+
"in": "query"
8020+
},
80098021
{
80108022
"type": "integer",
80118023
"description": "page size of results, deprecated - use limit",

0 commit comments

Comments
 (0)