Skip to content

Commit 22b5ec9

Browse files
committed
Auto-correct invalid enum parameters
1 parent c94200d commit 22b5ec9

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

pkg/github/issues.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,11 +1381,14 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
13811381
return utils.NewToolResultError(err.Error()), nil, nil
13821382
}
13831383

1384-
// If the state has a value, cast into an array of strings
1384+
// Normalize and filter by state
1385+
state = strings.ToUpper(state)
13851386
var states []githubv4.IssueState
1386-
if state != "" {
1387-
states = append(states, githubv4.IssueState(strings.ToUpper(state)))
1388-
} else {
1387+
1388+
switch state {
1389+
case "OPEN", "CLOSED":
1390+
states = []githubv4.IssueState{githubv4.IssueState(state)}
1391+
default:
13891392
states = []githubv4.IssueState{githubv4.IssueStateOpen, githubv4.IssueStateClosed}
13901393
}
13911394

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

1408-
// These variables are required for the GraphQL query to be set by default
1409-
// If orderBy is empty, default to CREATED_AT
1410-
if orderBy == "" {
1411+
// Normalize and validate orderBy
1412+
orderBy = strings.ToUpper(orderBy)
1413+
switch orderBy {
1414+
case "CREATED_AT", "UPDATED_AT", "COMMENTS":
1415+
// Valid, keep as is
1416+
default:
14111417
orderBy = "CREATED_AT"
14121418
}
1413-
// If direction is empty, default to DESC
1414-
if direction == "" {
1419+
1420+
// Normalize and validate direction
1421+
direction = strings.ToUpper(direction)
1422+
switch direction {
1423+
case "ASC", "DESC":
1424+
// Valid, keep as is
1425+
default:
14151426
direction = "DESC"
14161427
}
14171428

@@ -1467,8 +1478,8 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
14671478
"owner": githubv4.String(owner),
14681479
"repo": githubv4.String(repo),
14691480
"states": states,
1470-
"orderBy": githubv4.IssueOrderField(strings.ToUpper(orderBy)),
1471-
"direction": githubv4.OrderDirection(strings.ToUpper(direction)),
1481+
"orderBy": githubv4.IssueOrderField(orderBy),
1482+
"direction": githubv4.OrderDirection(direction),
14721483
"first": githubv4.Int(*paginationParams.First),
14731484
}
14741485

0 commit comments

Comments
 (0)