Skip to content

Commit dbbf724

Browse files
committed
added initial support for orderby and direction
1 parent 687ee8f commit dbbf724

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

pkg/github/discussions.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
3131
mcp.WithString("category",
3232
mcp.Description("Optional filter by discussion category ID. If provided, only discussions with this category are listed."),
3333
),
34+
mcp.WithString("orderBy",
35+
mcp.Description("Order discussions by field"),
36+
mcp.Enum("CREATED_AT", "UPDATED_AT"),
37+
),
38+
mcp.WithString("direction",
39+
mcp.Description("Order direction"),
40+
mcp.Enum("ASC", "DESC"),
41+
),
3442
),
3543
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
3644
// Required params
@@ -61,6 +69,27 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
6169
categoryID = &id
6270
}
6371

72+
orderBy, err := OptionalParam[string](request, "orderBy")
73+
if err != nil {
74+
return mcp.NewToolResultError(err.Error()), nil
75+
}
76+
if orderBy == "" {
77+
orderBy = "UPDATED_AT" // or "CREATED_AT"
78+
}
79+
direction, err := OptionalParam[string](request, "direction")
80+
if err != nil {
81+
return mcp.NewToolResultError(err.Error()), nil
82+
}
83+
if direction == "" {
84+
direction = "DESC"
85+
}
86+
87+
/* orderByInput := map[string]interface{}{
88+
"field": orderBy,
89+
"direction": direction,
90+
} */
91+
92+
6493
// Now execute the discussions query
6594
var discussions []*github.Discussion
6695
if categoryID != nil {
@@ -81,14 +110,20 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
81110
} `graphql:"category"`
82111
URL githubv4.String `graphql:"url"`
83112
}
84-
} `graphql:"discussions(first: 100, categoryId: $categoryId)"`
113+
} `graphql:"discussions(first: 100, categoryId: $categoryId, orderBy: {field: $orderByField, direction: $direction})"`
85114
} `graphql:"repository(owner: $owner, name: $repo)"`
86115
}
116+
117+
87118
vars := map[string]interface{}{
88119
"owner": githubv4.String(owner),
89120
"repo": githubv4.String(repo),
90121
"categoryId": *categoryID,
122+
"orderByField": githubv4.DiscussionOrderField(orderBy),
123+
"direction": githubv4.OrderDirection(direction),
91124
}
125+
126+
92127
if err := client.Query(ctx, &query, vars); err != nil {
93128
return mcp.NewToolResultError(err.Error()), nil
94129
}
@@ -128,13 +163,18 @@ func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelp
128163
} `graphql:"category"`
129164
URL githubv4.String `graphql:"url"`
130165
}
131-
} `graphql:"discussions(first: 100)"`
166+
} `graphql:"discussions(first: 100, orderBy: {field: $orderByField, direction: $direction})"`
132167
} `graphql:"repository(owner: $owner, name: $repo)"`
133168
}
169+
170+
134171
vars := map[string]interface{}{
135-
"owner": githubv4.String(owner),
136-
"repo": githubv4.String(repo),
172+
"owner": githubv4.String(owner),
173+
"repo": githubv4.String(repo),
174+
"orderByField": githubv4.DiscussionOrderField(orderBy),
175+
"direction": githubv4.OrderDirection(direction),
137176
}
177+
138178
if err := client.Query(ctx, &query, vars); err != nil {
139179
return mcp.NewToolResultError(err.Error()), nil
140180
}

0 commit comments

Comments
 (0)