Skip to content

Adding comments sorting for list_issues #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
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
Binary file added github-mcp-server
Binary file not shown.
3 changes: 2 additions & 1 deletion pkg/github/__toolsnaps__/list_issues.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"description": "Order issues by field. If provided, the 'direction' also needs to be provided.",
"enum": [
"CREATED_AT",
"UPDATED_AT"
"UPDATED_AT",
"COMMENTS"
],
"type": "string"
},
Expand Down
14 changes: 9 additions & 5 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type IssueFragment struct {
Description githubv4.String
}
} `graphql:"labels(first: 100)"`
Comments struct {
TotalCount githubv4.Int
} `graphql:"comments"`
}

// Common interface for all issue query types
Expand Down Expand Up @@ -133,10 +136,11 @@ func fragmentToIssue(fragment IssueFragment) *github.Issue {
User: &github.User{
Login: github.Ptr(string(fragment.Author.Login)),
},
State: github.Ptr(string(fragment.State)),
ID: github.Ptr(fragment.DatabaseID),
Body: github.Ptr(string(fragment.Body)),
Labels: foundLabels,
State: github.Ptr(string(fragment.State)),
ID: github.Ptr(fragment.DatabaseID),
Body: github.Ptr(string(fragment.Body)),
Labels: foundLabels,
Comments: github.Ptr(int(fragment.Comments.TotalCount)),
}
}

Expand Down Expand Up @@ -875,7 +879,7 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
),
mcp.WithString("orderBy",
mcp.Description("Order issues by field. If provided, the 'direction' also needs to be provided."),
mcp.Enum("CREATED_AT", "UPDATED_AT"),
mcp.Enum("CREATED_AT", "UPDATED_AT", "COMMENTS"),
),
mcp.WithString("direction",
mcp.Description("Order direction. If provided, the 'orderBy' also needs to be provided."),
Expand Down
13 changes: 11 additions & 2 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ func Test_ListIssues(t *testing.T) {
{"name": "bug", "id": "label1", "description": "Bug label"},
},
},
"comments": map[string]any{
"totalCount": 5,
},
},
{
"number": 456,
Expand All @@ -696,6 +699,9 @@ func Test_ListIssues(t *testing.T) {
{"name": "enhancement", "id": "label2", "description": "Enhancement label"},
},
},
"comments": map[string]any{
"totalCount": 3,
},
},
}

Expand All @@ -713,6 +719,9 @@ func Test_ListIssues(t *testing.T) {
"labels": map[string]any{
"nodes": []map[string]any{},
},
"comments": map[string]any{
"totalCount": 1,
},
},
}

Expand Down Expand Up @@ -875,8 +884,8 @@ func Test_ListIssues(t *testing.T) {
}

// Define the actual query strings that match the implementation
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}}}"
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}}}"
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}},comments{totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
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}},comments{totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Loading