Skip to content

Commit 8c5acd5

Browse files
committed
Removal of redundant code, and increase limit on label return
1 parent 0f155f9 commit 8c5acd5

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

pkg/github/issues.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type IssueFragment struct {
3737
ID githubv4.String
3838
Description githubv4.String
3939
}
40-
} `graphql:"labels(first: 10)"`
40+
} `graphql:"labels(first: 100)"`
4141
}
4242

4343
// Common interface for all issue query types
@@ -916,24 +916,21 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
916916
return mcp.NewToolResultError(err.Error()), nil
917917
}
918918

919-
// If labels is empty, default to nil for gql query
920-
if len(labels) == 0 {
921-
labels = nil
922-
}
923-
924919
orderBy, err := OptionalParam[string](request, "orderBy")
925920
if err != nil {
926921
return mcp.NewToolResultError(err.Error()), nil
927922
}
928-
// If orderBy is empty, default to CREATED_AT
929-
if orderBy == "" {
930-
orderBy = "CREATED_AT"
931-
}
932923

933924
direction, err := OptionalParam[string](request, "direction")
934925
if err != nil {
935926
return mcp.NewToolResultError(err.Error()), nil
936927
}
928+
929+
// These variables are required for the GraphQL query to be set by default
930+
// If orderBy is empty, default to CREATED_AT
931+
if orderBy == "" {
932+
orderBy = "CREATED_AT"
933+
}
937934
// If direction is empty, default to DESC
938935
if direction == "" {
939936
direction = "DESC"
@@ -944,6 +941,7 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
944941
return mcp.NewToolResultError(err.Error()), nil
945942
}
946943

944+
// There are two optional parameters: since and labels.
947945
var sinceTime time.Time
948946
var hasSince bool
949947
if since != "" {
@@ -953,6 +951,7 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
953951
}
954952
hasSince = true
955953
}
954+
hasLabels := len(labels) > 0
956955

957956
// Get pagination parameters and convert to GraphQL format
958957
pagination, err := OptionalCursorPaginationParams(request)
@@ -997,12 +996,11 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
997996
if paginationParams.After != nil {
998997
vars["after"] = githubv4.String(*paginationParams.After)
999998
} else {
999+
// Used within query, therefore must be set to nil and provided as $after
10001000
vars["after"] = (*githubv4.String)(nil)
10011001
}
10021002

1003-
// Choose the appropriate query based on whether labels are specified
1004-
hasLabels := len(labels) > 0
1005-
1003+
// Ensure optional parameters are set
10061004
if hasLabels {
10071005
// Use query with labels filtering - convert string labels to githubv4.String slice
10081006
labelStrings := make([]githubv4.String, len(labels))

pkg/github/issues_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ func Test_ListIssues(t *testing.T) {
875875
}
876876

877877
// Define the actual query strings that match the implementation
878-
qBasicNoLabels := "query($after:String$direction:OrderDirection!$first:Int!$orderBy:IssueOrderField!$owner:String!$repo:String!$states:[IssueState!]!){repository(owner: $owner, name: $repo){issues(first: $first, after: $after, states: $states, orderBy: {field: $orderBy, direction: $direction}){nodes{number,title,body,state,databaseId,author{login},createdAt,updatedAt,labels(first: 10){nodes{name,id,description}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
879-
qWithLabels := "query($after:String$direction:OrderDirection!$first:Int!$labels:[String!]!$orderBy:IssueOrderField!$owner:String!$repo:String!$states:[IssueState!]!){repository(owner: $owner, name: $repo){issues(first: $first, after: $after, labels: $labels, states: $states, orderBy: {field: $orderBy, direction: $direction}){nodes{number,title,body,state,databaseId,author{login},createdAt,updatedAt,labels(first: 10){nodes{name,id,description}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
878+
qBasicNoLabels := "query($after:String$direction:OrderDirection!$first:Int!$orderBy:IssueOrderField!$owner:String!$repo:String!$states:[IssueState!]!){repository(owner: $owner, name: $repo){issues(first: $first, after: $after, states: $states, orderBy: {field: $orderBy, direction: $direction}){nodes{number,title,body,state,databaseId,author{login},createdAt,updatedAt,labels(first: 100){nodes{name,id,description}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
879+
qWithLabels := "query($after:String$direction:OrderDirection!$first:Int!$labels:[String!]!$orderBy:IssueOrderField!$owner:String!$repo:String!$states:[IssueState!]!){repository(owner: $owner, name: $repo){issues(first: $first, after: $after, labels: $labels, states: $states, orderBy: {field: $orderBy, direction: $direction}){nodes{number,title,body,state,databaseId,author{login},createdAt,updatedAt,labels(first: 100){nodes{name,id,description}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
880880

881881
for _, tc := range tests {
882882
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)