Skip to content

Commit

Permalink
Merge branch 'main' into api_listReleases_add_filter_draft_and_pre-re…
Browse files Browse the repository at this point in the history
…leases
  • Loading branch information
6543 authored Jun 17, 2021
2 parents 559f1d4 + c9d053f commit 8ec7c9b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
14 changes: 14 additions & 0 deletions integrations/api_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ func TestAPISearchIssues(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)

query = url.Values{"milestones": {"milestone1"}, "state": {"all"}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)

query = url.Values{"milestones": {"milestone1,milestone3"}, "state": {"all"}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
}

func TestAPISearchIssuesWithLabels(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ type IssuesOptions struct {
LabelIDs []int64
IncludedLabelNames []string
ExcludedLabelNames []string
IncludeMilestones []string
SortType string
IssueIDs []int64
UpdatedAfterUnix int64
Expand Down Expand Up @@ -1241,6 +1242,13 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
if len(opts.ExcludedLabelNames) > 0 {
sess.And(builder.NotIn("issue.id", BuildLabelNamesIssueIDsCondition(opts.ExcludedLabelNames)))
}

if len(opts.IncludeMilestones) > 0 {
sess.In("issue.milestone_id",
builder.Select("id").
From("milestone").
Where(builder.In("name", opts.IncludeMilestones)))
}
}

func applyReposCondition(sess *xorm.Session, repoIDs []int64) *xorm.Session {
Expand Down
4 changes: 4 additions & 0 deletions modules/convert/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func toUser(user *models.User, signed, authed bool) *api.User {
Location: user.Location,
Website: user.Website,
Description: user.Description,
// counter's
Followers: user.NumFollowers,
Following: user.NumFollowing,
StarredRepos: user.NumStars,
}
// hide primary email if API caller is anonymous or user keep email private
if signed && (!user.KeepEmailPrivate || authed) {
Expand Down
5 changes: 5 additions & 0 deletions modules/structs/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ type User struct {
Website string `json:"website"`
// the user's description
Description string `json:"description"`

// user counts
Followers int `json:"followers_count"`
Following int `json:"following_count"`
StarredRepos int `json:"starred_repos_count"`
}

// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
Expand Down
13 changes: 12 additions & 1 deletion routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func SearchIssues(ctx *context.APIContext) {
// in: query
// description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
// type: string
// - name: milestones
// in: query
// description: comma separated list of milestone names. Fetch only issues that have any of this milestones. Non existent are discarded
// type: string
// - name: q
// in: query
// description: search string
Expand Down Expand Up @@ -164,6 +168,12 @@ func SearchIssues(ctx *context.APIContext) {
includedLabelNames = strings.Split(labels, ",")
}

milestones := strings.TrimSpace(ctx.Query("milestones"))
var includedMilestones []string
if len(milestones) > 0 {
includedMilestones = strings.Split(milestones, ",")
}

// this api is also used in UI,
// so the default limit is set to fit UI needs
limit := ctx.QueryInt("limit")
Expand All @@ -175,7 +185,7 @@ func SearchIssues(ctx *context.APIContext) {

// Only fetch the issues if we either don't have a keyword or the search returned issues
// This would otherwise return all issues if no issues were found by the search.
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 {
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 || len(includedMilestones) > 0 {
issuesOpt := &models.IssuesOptions{
ListOptions: models.ListOptions{
Page: ctx.QueryInt("page"),
Expand All @@ -185,6 +195,7 @@ func SearchIssues(ctx *context.APIContext) {
IsClosed: isClosed,
IssueIDs: issueIDs,
IncludedLabelNames: includedLabelNames,
IncludeMilestones: includedMilestones,
SortType: "priorityrepo",
PriorityRepoID: ctx.QueryInt64("priority_repo_id"),
IsPull: isPull,
Expand Down
22 changes: 22 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,12 @@
"name": "labels",
"in": "query"
},
{
"type": "string",
"description": "comma separated list of milestone names. Fetch only issues that have any of this milestones. Non existent are discarded",
"name": "milestones",
"in": "query"
},
{
"type": "string",
"description": "search string",
Expand Down Expand Up @@ -16351,6 +16357,17 @@
"format": "email",
"x-go-name": "Email"
},
"followers_count": {
"description": "user counts",
"type": "integer",
"format": "int64",
"x-go-name": "Followers"
},
"following_count": {
"type": "integer",
"format": "int64",
"x-go-name": "Following"
},
"full_name": {
"description": "the user's full name",
"type": "string",
Expand Down Expand Up @@ -16397,6 +16414,11 @@
"type": "boolean",
"x-go-name": "Restricted"
},
"starred_repos_count": {
"type": "integer",
"format": "int64",
"x-go-name": "StarredRepos"
},
"website": {
"description": "the user's website",
"type": "string",
Expand Down

0 comments on commit 8ec7c9b

Please sign in to comment.