Skip to content

Commit dc446c2

Browse files
committed
feat(discussions): add upvoteCount to list_discussions and get_discussion (#2661)
1 parent 3422703 commit dc446c2

2 files changed

Lines changed: 142 additions & 123 deletions

File tree

pkg/github/discussions.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/github/github-mcp-server/pkg/translations"
1313
"github.com/github/github-mcp-server/pkg/utils"
1414
"github.com/go-viper/mapstructure/v2"
15-
"github.com/google/go-github/v87/github"
1615
"github.com/google/jsonschema-go/jsonschema"
1716
"github.com/modelcontextprotocol/go-sdk/mcp"
1817
"github.com/shurcooL/githubv4"
@@ -56,6 +55,7 @@ type NodeFragment struct {
5655
Closed githubv4.Boolean
5756
IsAnswered githubv4.Boolean
5857
AnswerChosenAt *githubv4.DateTime
58+
UpvoteCount githubv4.Int
5959
Author struct {
6060
Login githubv4.String
6161
}
@@ -96,22 +96,6 @@ type WithCategoryNoOrder struct {
9696
} `graphql:"repository(owner: $owner, name: $repo)"`
9797
}
9898

99-
func fragmentToDiscussion(fragment NodeFragment) *github.Discussion {
100-
return &github.Discussion{
101-
Number: github.Ptr(int(fragment.Number)),
102-
Title: github.Ptr(string(fragment.Title)),
103-
HTMLURL: github.Ptr(string(fragment.URL)),
104-
CreatedAt: &github.Timestamp{Time: fragment.CreatedAt.Time},
105-
UpdatedAt: &github.Timestamp{Time: fragment.UpdatedAt.Time},
106-
User: &github.User{
107-
Login: github.Ptr(string(fragment.Author.Login)),
108-
},
109-
DiscussionCategory: &github.DiscussionCategory{
110-
Name: github.Ptr(string(fragment.Category.Name)),
111-
},
112-
}
113-
}
114-
11599
func getQueryType(useOrdering bool, categoryID *githubv4.ID) any {
116100
if categoryID != nil && useOrdering {
117101
return &WithCategoryAndOrder{}
@@ -245,13 +229,28 @@ func ListDiscussions(t translations.TranslationHelperFunc) inventory.ServerTool
245229
}
246230

247231
// Extract and convert all discussion nodes using the common interface
248-
var discussions []*github.Discussion
232+
var discussions []map[string]any
249233
var pageInfo PageInfoFragment
250234
var totalCount githubv4.Int
251235
if queryResult, ok := discussionQuery.(DiscussionQueryResult); ok {
252236
fragment := queryResult.GetDiscussionFragment()
253237
for _, node := range fragment.Nodes {
254-
discussions = append(discussions, fragmentToDiscussion(node))
238+
d := map[string]any{
239+
"number": int(node.Number),
240+
"title": string(node.Title),
241+
"url": string(node.URL),
242+
"createdAt": node.CreatedAt.Time,
243+
"updatedAt": node.UpdatedAt.Time,
244+
"closed": bool(node.Closed),
245+
"isAnswered": bool(node.IsAnswered),
246+
"upvoteCount": int(node.UpvoteCount),
247+
"author": map[string]any{"login": string(node.Author.Login)},
248+
"category": map[string]any{"name": string(node.Category.Name)},
249+
}
250+
if node.AnswerChosenAt != nil {
251+
d["answerChosenAt"] = node.AnswerChosenAt.Time
252+
}
253+
discussions = append(discussions, d)
255254
}
256255
pageInfo = fragment.PageInfo
257256
totalCount = fragment.TotalCount
@@ -337,6 +336,7 @@ func GetDiscussion(t translations.TranslationHelperFunc) inventory.ServerTool {
337336
Closed githubv4.Boolean
338337
IsAnswered githubv4.Boolean
339338
AnswerChosenAt *githubv4.DateTime
339+
UpvoteCount githubv4.Int
340340
URL githubv4.String `graphql:"url"`
341341
Category struct {
342342
Name githubv4.String
@@ -359,13 +359,14 @@ func GetDiscussion(t translations.TranslationHelperFunc) inventory.ServerTool {
359359
// so we use map[string]interface{} for the response (consistent with other functions
360360
// like ListDiscussions and GetDiscussionComments).
361361
response := map[string]any{
362-
"number": int(d.Number),
363-
"title": string(d.Title),
364-
"body": string(d.Body),
365-
"url": string(d.URL),
366-
"closed": bool(d.Closed),
367-
"isAnswered": bool(d.IsAnswered),
368-
"createdAt": d.CreatedAt.Time,
362+
"number": int(d.Number),
363+
"title": string(d.Title),
364+
"body": string(d.Body),
365+
"url": string(d.URL),
366+
"closed": bool(d.Closed),
367+
"isAnswered": bool(d.IsAnswered),
368+
"createdAt": d.CreatedAt.Time,
369+
"upvoteCount": int(d.UpvoteCount),
369370
"category": map[string]any{
370371
"name": string(d.Category.Name),
371372
},

0 commit comments

Comments
 (0)