Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: get_discussion graphQL invalid field#648

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
LuluBeatson merged 3 commits intomainfromlulu/get-discussion
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
32 changes: 12 additions & 20 deletionspkg/github/discussions.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,7 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
}

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

// Map nodes to GitHubIssue objects
// Map nodes to GitHubDiscussion objects
for _, n := range query.Repository.Discussions.Nodes {
di := &github.Issue{
di := &github.Discussion{
Number: github.Ptr(int(n.Number)),
Title: github.Ptr(string(n.Title)),
HTMLURL: github.Ptr(string(n.URL)),
CreatedAt: &github.Timestamp{Time: n.CreatedAt.Time},
Labels: []*github.Label{
{
Name: github.Ptr(fmt.Sprintf("category:%s", string(n.Category.Name))),
},
DiscussionCategory: &github.DiscussionCategory{
Name: github.Ptr(string(n.Category.Name)),
},
}
discussions = append(discussions, di)
Expand DownExpand Up@@ -129,17 +127,15 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
return mcp.NewToolResultError(err.Error()), nil
}

// Map nodes to GitHubIssue objects
// Map nodes to GitHubDiscussion objects
for _, n := range query.Repository.Discussions.Nodes {
di := &github.Issue{
di := &github.Discussion{
Number: github.Ptr(int(n.Number)),
Title: github.Ptr(string(n.Title)),
HTMLURL: github.Ptr(string(n.URL)),
CreatedAt: &github.Timestamp{Time: n.CreatedAt.Time},
Labels: []*github.Label{
{
Name: github.Ptr(fmt.Sprintf("category:%s", string(n.Category.Name))),
},
DiscussionCategory: &github.DiscussionCategory{
Name: github.Ptr(string(n.Category.Name)),
},
}
discussions = append(discussions, di)
Expand DownExpand Up@@ -195,7 +191,6 @@ func GetDiscussion(getGQLClient GetGQLClientFn, t translations.TranslationHelper
Discussion struct {
Number githubv4.Int
Body githubv4.String
State githubv4.String
CreatedAt githubv4.DateTime
URL githubv4.String `graphql:"url"`
Category struct {
Expand All@@ -213,16 +208,13 @@ func GetDiscussion(getGQLClient GetGQLClientFn, t translations.TranslationHelper
return mcp.NewToolResultError(err.Error()), nil
}
d := q.Repository.Discussion
discussion := &github.Issue{
discussion := &github.Discussion{
Number: github.Ptr(int(d.Number)),
Body: github.Ptr(string(d.Body)),
State: github.Ptr(string(d.State)),
HTMLURL: github.Ptr(string(d.URL)),
CreatedAt: &github.Timestamp{Time: d.CreatedAt.Time},
Labels: []*github.Label{
{
Name: github.Ptr(fmt.Sprintf("category:%s", string(d.Category.Name))),
},
DiscussionCategory: &github.DiscussionCategory{
Name: github.Ptr(string(d.Category.Name)),
},
}
out, err := json.Marshal(discussion)
Expand Down
28 changes: 10 additions & 18 deletionspkg/github/discussions_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"net/http"
"strings"
"testing"
"time"

Expand DownExpand Up@@ -168,17 +167,17 @@ func Test_ListDiscussions(t *testing.T) {
}
require.NoError(t, err)

var returnedDiscussions []*github.Issue
var returnedDiscussions []*github.Discussion
err = json.Unmarshal([]byte(text), &returnedDiscussions)
require.NoError(t, err)

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

// Verify that all returned discussions have a categorylabelif filtered
// Verify that all returned discussions have a category if filtered
if _, hasCategory := tc.reqParams["category"]; hasCategory {
for _, discussion := range returnedDiscussions {
require.NotEmpty(t, discussion.Labels, "Discussion should have category label")
assert.True(t,strings.HasPrefix(*discussion.Labels[0].Name, "category:"), "Discussion should have categorylabel prefix")
require.NotNil(t, discussion.DiscussionCategory, "Discussion should have category")
assert.NotEmpty(t, *discussion.DiscussionCategory.Name, "Discussion should have categoryname")
}
}
})
Expand All@@ -200,7 +199,6 @@ func Test_GetDiscussion(t *testing.T) {
Discussion struct {
Number githubv4.Int
Body githubv4.String
State githubv4.String
CreatedAt githubv4.DateTime
URL githubv4.String `graphql:"url"`
Category struct {
Expand All@@ -218,7 +216,7 @@ func Test_GetDiscussion(t *testing.T) {
name string
response githubv4mock.GQLResponse
expectError bool
expected *github.Issue
expected *github.Discussion
errContains string
}{
{
Expand All@@ -227,23 +225,19 @@ func Test_GetDiscussion(t *testing.T) {
"repository": map[string]any{"discussion": map[string]any{
"number": 1,
"body": "This is a test discussion",
"state": "open",
"url": "https://github.com/owner/repo/discussions/1",
"createdAt": "2025-04-25T12:00:00Z",
"category": map[string]any{"name": "General"},
}},
}),
expectError: false,
expected: &github.Issue{
expected: &github.Discussion{
HTMLURL: github.Ptr("https://github.com/owner/repo/discussions/1"),
Number: github.Ptr(1),
Body: github.Ptr("This is a test discussion"),
State: github.Ptr("open"),
CreatedAt: &github.Timestamp{Time: time.Date(2025, 4, 25, 12, 0, 0, 0, time.UTC)},
Labels: []*github.Label{
{
Name: github.Ptr("category:General"),
},
DiscussionCategory: &github.DiscussionCategory{
Name: github.Ptr("General"),
},
},
},
Expand DownExpand Up@@ -272,15 +266,13 @@ func Test_GetDiscussion(t *testing.T) {
}

require.NoError(t, err)
var out github.Issue
var out github.Discussion
require.NoError(t, json.Unmarshal([]byte(text), &out))
assert.Equal(t, *tc.expected.HTMLURL, *out.HTMLURL)
assert.Equal(t, *tc.expected.Number, *out.Number)
assert.Equal(t, *tc.expected.Body, *out.Body)
assert.Equal(t, *tc.expected.State, *out.State)
// Check category label
require.Len(t, out.Labels, 1)
assert.Equal(t, *tc.expected.Labels[0].Name, *out.Labels[0].Name)
assert.Equal(t, *tc.expected.DiscussionCategory.Name, *out.DiscussionCategory.Name)
})
}
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp