summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-07-28 13:30:40 +0200
committerGitHub <noreply@github.com>2020-07-28 12:30:40 +0100
commit8bdc9795d8a5aa51bc1295dd1cf57006a5873343 (patch)
tree81ebd17da66318ca7909284021319be10a552e5c /routers
parent78cbd0ca72619a25849edc3460ec0c492b838a59 (diff)
downloadgitea-8bdc9795d8a5aa51bc1295dd1cf57006a5873343.tar.gz
gitea-8bdc9795d8a5aa51bc1295dd1cf57006a5873343.zip
Add name filter to API for GetMilestoneList (#12336)
Adds a name filter to the API for GetMilestoneList Includes a small refactor: merge GetMilestones and GetMilestonesByRepoID Close #12260 Needed for https://gitea.com/gitea/go-sdk/issues/383 and https://gitea.com/gitea/tea/pulls/149
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/milestone.go13
-rw-r--r--routers/repo/issue.go17
-rw-r--r--routers/repo/milestone.go14
3 files changed, 37 insertions, 7 deletions
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index adb9deaee4..f6f6b29465 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -39,6 +39,10 @@ func ListMilestones(ctx *context.APIContext) {
// in: query
// description: Milestone state, Recognised values are open, closed and all. Defaults to "open"
// type: string
+ // - name: name
+ // in: query
+ // description: filter by milestone name
+ // type: string
// - name: page
// in: query
// description: page number of results to return (1-based)
@@ -51,9 +55,14 @@ func ListMilestones(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/MilestoneList"
- milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")), utils.GetListOptions(ctx))
+ milestones, err := models.GetMilestones(models.GetMilestonesOption{
+ ListOptions: utils.GetListOptions(ctx),
+ RepoID: ctx.Repo.Repository.ID,
+ State: api.StateType(ctx.Query("state")),
+ Name: ctx.Query("name"),
+ })
if err != nil {
- ctx.Error(http.StatusInternalServerError, "GetMilestonesByRepoID", err)
+ ctx.Error(http.StatusInternalServerError, "GetMilestones", err)
return
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index e3ba5692c4..b3af6705ca 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -360,8 +360,11 @@ func Issues(ctx *context.Context) {
issues(ctx, ctx.QueryInt64("milestone"), util.OptionalBoolOf(isPullList))
var err error
- // Get milestones.
- ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")), models.ListOptions{})
+ // Get milestones
+ ctx.Data["Milestones"], err = models.GetMilestones(models.GetMilestonesOption{
+ RepoID: ctx.Repo.Repository.ID,
+ State: api.StateType(ctx.Query("state")),
+ })
if err != nil {
ctx.ServerError("GetAllRepoMilestones", err)
return
@@ -375,12 +378,18 @@ func Issues(ctx *context.Context) {
// RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
var err error
- ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "")
+ ctx.Data["OpenMilestones"], err = models.GetMilestones(models.GetMilestonesOption{
+ RepoID: repo.ID,
+ State: api.StateOpen,
+ })
if err != nil {
ctx.ServerError("GetMilestones", err)
return
}
- ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "")
+ ctx.Data["ClosedMilestones"], err = models.GetMilestones(models.GetMilestonesOption{
+ RepoID: repo.ID,
+ State: api.StateClosed,
+ })
if err != nil {
ctx.ServerError("GetMilestones", err)
return
diff --git a/routers/repo/milestone.go b/routers/repo/milestone.go
index 9d8f34268d..0bd7344878 100644
--- a/routers/repo/milestone.go
+++ b/routers/repo/milestone.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
@@ -47,13 +48,24 @@ func Milestones(ctx *context.Context) {
}
var total int
+ var state structs.StateType
if !isShowClosed {
total = int(stats.OpenCount)
+ state = structs.StateOpen
} else {
total = int(stats.ClosedCount)
+ state = structs.StateClosed
}
- miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType)
+ miles, err := models.GetMilestones(models.GetMilestonesOption{
+ ListOptions: models.ListOptions{
+ Page: page,
+ PageSize: setting.UI.IssuePagingNum,
+ },
+ RepoID: ctx.Repo.Repository.ID,
+ State: state,
+ SortType: sortType,
+ })
if err != nil {
ctx.ServerError("GetMilestones", err)
return