Skip to content

Commit 3730b84

Browse files
authored
fix: get_discussion graphQL invalid field (#648)
* rm State which does not exist on type Discussion * update Test_GetDiscussion * use Discussion object instead of Issue
1 parent 39d7fec commit 3730b84

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

pkg/github/discussions.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
6262
}
6363

6464
// Now execute the discussions query
65-
var discussions []*github.Issue
65+
var discussions []*github.Discussion
6666
if categoryID != nil {
6767
// Query with category filter (server-side filtering)
6868
var query struct {
@@ -89,17 +89,15 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
8989
return mcp.NewToolResultError(err.Error()), nil
9090
}
9191

92-
// Map nodes to GitHub Issue objects
92+
// Map nodes to GitHub Discussion objects
9393
for _, n := range query.Repository.Discussions.Nodes {
94-
di := &github.Issue{
94+
di := &github.Discussion{
9595
Number: github.Ptr(int(n.Number)),
9696
Title: github.Ptr(string(n.Title)),
9797
HTMLURL: github.Ptr(string(n.URL)),
9898
CreatedAt: &github.Timestamp{Time: n.CreatedAt.Time},
99-
Labels: []*github.Label{
100-
{
101-
Name: github.Ptr(fmt.Sprintf("category:%s", string(n.Category.Name))),
102-
},
99+
DiscussionCategory: &github.DiscussionCategory{
100+
Name: github.Ptr(string(n.Category.Name)),
103101
},
104102
}
105103
discussions = append(discussions, di)
@@ -129,17 +127,15 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
129127
return mcp.NewToolResultError(err.Error()), nil
130128
}
131129

132-
// Map nodes to GitHub Issue objects
130+
// Map nodes to GitHub Discussion objects
133131
for _, n := range query.Repository.Discussions.Nodes {
134-
di := &github.Issue{
132+
di := &github.Discussion{
135133
Number: github.Ptr(int(n.Number)),
136134
Title: github.Ptr(string(n.Title)),
137135
HTMLURL: github.Ptr(string(n.URL)),
138136
CreatedAt: &github.Timestamp{Time: n.CreatedAt.Time},
139-
Labels: []*github.Label{
140-
{
141-
Name: github.Ptr(fmt.Sprintf("category:%s", string(n.Category.Name))),
142-
},
137+
DiscussionCategory: &github.DiscussionCategory{
138+
Name: github.Ptr(string(n.Category.Name)),
143139
},
144140
}
145141
discussions = append(discussions, di)
@@ -195,7 +191,6 @@ func GetDiscussion(getGQLClient GetGQLClientFn, t translations.TranslationHelper
195191
Discussion struct {
196192
Number githubv4.Int
197193
Body githubv4.String
198-
State githubv4.String
199194
CreatedAt githubv4.DateTime
200195
URL githubv4.String `graphql:"url"`
201196
Category struct {
@@ -213,16 +208,13 @@ func GetDiscussion(getGQLClient GetGQLClientFn, t translations.TranslationHelper
213208
return mcp.NewToolResultError(err.Error()), nil
214209
}
215210
d := q.Repository.Discussion
216-
discussion := &github.Issue{
211+
discussion := &github.Discussion{
217212
Number: github.Ptr(int(d.Number)),
218213
Body: github.Ptr(string(d.Body)),
219-
State: github.Ptr(string(d.State)),
220214
HTMLURL: github.Ptr(string(d.URL)),
221215
CreatedAt: &github.Timestamp{Time: d.CreatedAt.Time},
222-
Labels: []*github.Label{
223-
{
224-
Name: github.Ptr(fmt.Sprintf("category:%s", string(d.Category.Name))),
225-
},
216+
DiscussionCategory: &github.DiscussionCategory{
217+
Name: github.Ptr(string(d.Category.Name)),
226218
},
227219
}
228220
out, err := json.Marshal(discussion)

pkg/github/discussions_test.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"net/http"
7-
"strings"
87
"testing"
98
"time"
109

@@ -168,17 +167,17 @@ func Test_ListDiscussions(t *testing.T) {
168167
}
169168
require.NoError(t, err)
170169

171-
var returnedDiscussions []*github.Issue
170+
var returnedDiscussions []*github.Discussion
172171
err = json.Unmarshal([]byte(text), &returnedDiscussions)
173172
require.NoError(t, err)
174173

175174
assert.Len(t, returnedDiscussions, tc.expectedCount, "Expected %d discussions, got %d", tc.expectedCount, len(returnedDiscussions))
176175

177-
// Verify that all returned discussions have a category label if filtered
176+
// Verify that all returned discussions have a category if filtered
178177
if _, hasCategory := tc.reqParams["category"]; hasCategory {
179178
for _, discussion := range returnedDiscussions {
180-
require.NotEmpty(t, discussion.Labels, "Discussion should have category label")
181-
assert.True(t, strings.HasPrefix(*discussion.Labels[0].Name, "category:"), "Discussion should have category label prefix")
179+
require.NotNil(t, discussion.DiscussionCategory, "Discussion should have category")
180+
assert.NotEmpty(t, *discussion.DiscussionCategory.Name, "Discussion should have category name")
182181
}
183182
}
184183
})
@@ -200,7 +199,6 @@ func Test_GetDiscussion(t *testing.T) {
200199
Discussion struct {
201200
Number githubv4.Int
202201
Body githubv4.String
203-
State githubv4.String
204202
CreatedAt githubv4.DateTime
205203
URL githubv4.String `graphql:"url"`
206204
Category struct {
@@ -218,7 +216,7 @@ func Test_GetDiscussion(t *testing.T) {
218216
name string
219217
response githubv4mock.GQLResponse
220218
expectError bool
221-
expected *github.Issue
219+
expected *github.Discussion
222220
errContains string
223221
}{
224222
{
@@ -227,23 +225,19 @@ func Test_GetDiscussion(t *testing.T) {
227225
"repository": map[string]any{"discussion": map[string]any{
228226
"number": 1,
229227
"body": "This is a test discussion",
230-
"state": "open",
231228
"url": "https://github.com/owner/repo/discussions/1",
232229
"createdAt": "2025-04-25T12:00:00Z",
233230
"category": map[string]any{"name": "General"},
234231
}},
235232
}),
236233
expectError: false,
237-
expected: &github.Issue{
234+
expected: &github.Discussion{
238235
HTMLURL: github.Ptr("https://github.com/owner/repo/discussions/1"),
239236
Number: github.Ptr(1),
240237
Body: github.Ptr("This is a test discussion"),
241-
State: github.Ptr("open"),
242238
CreatedAt: &github.Timestamp{Time: time.Date(2025, 4, 25, 12, 0, 0, 0, time.UTC)},
243-
Labels: []*github.Label{
244-
{
245-
Name: github.Ptr("category:General"),
246-
},
239+
DiscussionCategory: &github.DiscussionCategory{
240+
Name: github.Ptr("General"),
247241
},
248242
},
249243
},
@@ -272,15 +266,13 @@ func Test_GetDiscussion(t *testing.T) {
272266
}
273267

274268
require.NoError(t, err)
275-
var out github.Issue
269+
var out github.Discussion
276270
require.NoError(t, json.Unmarshal([]byte(text), &out))
277271
assert.Equal(t, *tc.expected.HTMLURL, *out.HTMLURL)
278272
assert.Equal(t, *tc.expected.Number, *out.Number)
279273
assert.Equal(t, *tc.expected.Body, *out.Body)
280-
assert.Equal(t, *tc.expected.State, *out.State)
281274
// Check category label
282-
require.Len(t, out.Labels, 1)
283-
assert.Equal(t, *tc.expected.Labels[0].Name, *out.Labels[0].Name)
275+
assert.Equal(t, *tc.expected.DiscussionCategory.Name, *out.DiscussionCategory.Name)
284276
})
285277
}
286278
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy