Skip to content

Commit 8ec7c9b

Browse files
authored
Merge branch 'main' into api_listReleases_add_filter_draft_and_pre-releases
2 parents 559f1d4 + c9d053f commit 8ec7c9b

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

integrations/api_issue_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ func TestAPISearchIssues(t *testing.T) {
222222
resp = session.MakeRequest(t, req, http.StatusOK)
223223
DecodeJSON(t, resp, &apiIssues)
224224
assert.Len(t, apiIssues, 1)
225+
226+
query = url.Values{"milestones": {"milestone1"}, "state": {"all"}}
227+
link.RawQuery = query.Encode()
228+
req = NewRequest(t, "GET", link.String())
229+
resp = session.MakeRequest(t, req, http.StatusOK)
230+
DecodeJSON(t, resp, &apiIssues)
231+
assert.Len(t, apiIssues, 1)
232+
233+
query = url.Values{"milestones": {"milestone1,milestone3"}, "state": {"all"}}
234+
link.RawQuery = query.Encode()
235+
req = NewRequest(t, "GET", link.String())
236+
resp = session.MakeRequest(t, req, http.StatusOK)
237+
DecodeJSON(t, resp, &apiIssues)
238+
assert.Len(t, apiIssues, 2)
225239
}
226240

227241
func TestAPISearchIssuesWithLabels(t *testing.T) {

models/issue.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ type IssuesOptions struct {
11001100
LabelIDs []int64
11011101
IncludedLabelNames []string
11021102
ExcludedLabelNames []string
1103+
IncludeMilestones []string
11031104
SortType string
11041105
IssueIDs []int64
11051106
UpdatedAfterUnix int64
@@ -1241,6 +1242,13 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
12411242
if len(opts.ExcludedLabelNames) > 0 {
12421243
sess.And(builder.NotIn("issue.id", BuildLabelNamesIssueIDsCondition(opts.ExcludedLabelNames)))
12431244
}
1245+
1246+
if len(opts.IncludeMilestones) > 0 {
1247+
sess.In("issue.milestone_id",
1248+
builder.Select("id").
1249+
From("milestone").
1250+
Where(builder.In("name", opts.IncludeMilestones)))
1251+
}
12441252
}
12451253

12461254
func applyReposCondition(sess *xorm.Session, repoIDs []int64) *xorm.Session {

modules/convert/user.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func toUser(user *models.User, signed, authed bool) *api.User {
4848
Location: user.Location,
4949
Website: user.Website,
5050
Description: user.Description,
51+
// counter's
52+
Followers: user.NumFollowers,
53+
Following: user.NumFollowing,
54+
StarredRepos: user.NumStars,
5155
}
5256
// hide primary email if API caller is anonymous or user keep email private
5357
if signed && (!user.KeepEmailPrivate || authed) {

modules/structs/user.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ type User struct {
4343
Website string `json:"website"`
4444
// the user's description
4545
Description string `json:"description"`
46+
47+
// user counts
48+
Followers int `json:"followers_count"`
49+
Following int `json:"following_count"`
50+
StarredRepos int `json:"starred_repos_count"`
4651
}
4752

4853
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility

routers/api/v1/repo/issue.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func SearchIssues(ctx *context.APIContext) {
4242
// in: query
4343
// description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
4444
// type: string
45+
// - name: milestones
46+
// in: query
47+
// description: comma separated list of milestone names. Fetch only issues that have any of this milestones. Non existent are discarded
48+
// type: string
4549
// - name: q
4650
// in: query
4751
// description: search string
@@ -164,6 +168,12 @@ func SearchIssues(ctx *context.APIContext) {
164168
includedLabelNames = strings.Split(labels, ",")
165169
}
166170

171+
milestones := strings.TrimSpace(ctx.Query("milestones"))
172+
var includedMilestones []string
173+
if len(milestones) > 0 {
174+
includedMilestones = strings.Split(milestones, ",")
175+
}
176+
167177
// this api is also used in UI,
168178
// so the default limit is set to fit UI needs
169179
limit := ctx.QueryInt("limit")
@@ -175,7 +185,7 @@ func SearchIssues(ctx *context.APIContext) {
175185

176186
// Only fetch the issues if we either don't have a keyword or the search returned issues
177187
// This would otherwise return all issues if no issues were found by the search.
178-
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 {
188+
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 || len(includedMilestones) > 0 {
179189
issuesOpt := &models.IssuesOptions{
180190
ListOptions: models.ListOptions{
181191
Page: ctx.QueryInt("page"),
@@ -185,6 +195,7 @@ func SearchIssues(ctx *context.APIContext) {
185195
IsClosed: isClosed,
186196
IssueIDs: issueIDs,
187197
IncludedLabelNames: includedLabelNames,
198+
IncludeMilestones: includedMilestones,
188199
SortType: "priorityrepo",
189200
PriorityRepoID: ctx.QueryInt64("priority_repo_id"),
190201
IsPull: isPull,

templates/swagger/v1_json.tmpl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,12 @@
18761876
"name": "labels",
18771877
"in": "query"
18781878
},
1879+
{
1880+
"type": "string",
1881+
"description": "comma separated list of milestone names. Fetch only issues that have any of this milestones. Non existent are discarded",
1882+
"name": "milestones",
1883+
"in": "query"
1884+
},
18791885
{
18801886
"type": "string",
18811887
"description": "search string",
@@ -16351,6 +16357,17 @@
1635116357
"format": "email",
1635216358
"x-go-name": "Email"
1635316359
},
16360+
"followers_count": {
16361+
"description": "user counts",
16362+
"type": "integer",
16363+
"format": "int64",
16364+
"x-go-name": "Followers"
16365+
},
16366+
"following_count": {
16367+
"type": "integer",
16368+
"format": "int64",
16369+
"x-go-name": "Following"
16370+
},
1635416371
"full_name": {
1635516372
"description": "the user's full name",
1635616373
"type": "string",
@@ -16397,6 +16414,11 @@
1639716414
"type": "boolean",
1639816415
"x-go-name": "Restricted"
1639916416
},
16417+
"starred_repos_count": {
16418+
"type": "integer",
16419+
"format": "int64",
16420+
"x-go-name": "StarredRepos"
16421+
},
1640016422
"website": {
1640116423
"description": "the user's website",
1640216424
"type": "string",

0 commit comments

Comments
 (0)