Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,14 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
return utils.NewToolResultError(err.Error()), nil, nil
}

// If the state has a value, cast into an array of strings
// Normalize and filter by state
state = strings.ToUpper(state)
var states []githubv4.IssueState
if state != "" {
states = append(states, githubv4.IssueState(state))
} else {

switch state {
case "OPEN", "CLOSED":
states = []githubv4.IssueState{githubv4.IssueState(state)}
default:
states = []githubv4.IssueState{githubv4.IssueStateOpen, githubv4.IssueStateClosed}
}

Expand All @@ -1405,13 +1408,21 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
return utils.NewToolResultError(err.Error()), nil, nil
}

// These variables are required for the GraphQL query to be set by default
// If orderBy is empty, default to CREATED_AT
if orderBy == "" {
// Normalize and validate orderBy
orderBy = strings.ToUpper(orderBy)
switch orderBy {
case "CREATED_AT", "UPDATED_AT", "COMMENTS":
// Valid, keep as is
default:
orderBy = "CREATED_AT"
}
// If direction is empty, default to DESC
if direction == "" {

// Normalize and validate direction
direction = strings.ToUpper(direction)
switch direction {
case "ASC", "DESC":
// Valid, keep as is
default:
direction = "DESC"
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,16 @@ func Test_ListIssues(t *testing.T) {
expectError: false,
expectedCount: 2,
},
{
name: "filter by open state - lc",
reqParams: map[string]interface{}{
"owner": "owner",
"repo": "repo",
"state": "open",
},
expectError: false,
expectedCount: 2,
},
{
name: "filter by closed state",
reqParams: map[string]interface{}{
Expand Down Expand Up @@ -1229,6 +1239,9 @@ func Test_ListIssues(t *testing.T) {
case "filter by open state":
matcher := githubv4mock.NewQueryMatcher(qBasicNoLabels, varsOpenOnly, mockResponseOpenOnly)
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
case "filter by open state - lc":
matcher := githubv4mock.NewQueryMatcher(qBasicNoLabels, varsOpenOnly, mockResponseOpenOnly)
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
case "filter by closed state":
matcher := githubv4mock.NewQueryMatcher(qBasicNoLabels, varsClosedOnly, mockResponseClosedOnly)
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
Expand Down