Skip to content

feat: list_discussions sort by updatedAt & createdAt, return updatedAt and author #690

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

tommaso-moro
Copy link
Contributor

@tommaso-moro tommaso-moro commented Jul 16, 2025

Addresses #670

Overview
This PR expands the functionality of the list_discussions tool. It adds

  • The updatedAt and author.login (i.e. username) fields to the discussions payload in the list_discussions tool
  • The ability to order discussions by field (updated_at and created_at) and direction (ascending order, descending order)

Refactoring
The PR includes extensive refactoring of the list_discussions tool to handle optional parameters in our graphql queries. This was needed because the githubv4 library requires GraphQL queries to be defined using Go struct tags that must be known at compile time, so we could not dynamically construct query strings at runtime based on user input.

The changes made include

  • Introduced reusable DiscussionFragment struct to avoid field duplication
  • Created 4 pre-defined query variants:
    • BasicNoOrder: No optional parameters (uses GitHub API's defaults)
    • BasicWithOrder: Only ordering parameters
    • WithCategoryNoOrder: Only category filtering
    • WithCategoryAndOrder: Both category and ordering
  • Added runtime query selection logic to choose the appropriate variant based on user input

Tests
I updated the tests in discussions_test.go to match the new queries, and to test the new ordering functionality with different sorting combinations.

Demo

Simple "list discussions" prompt Screenshot 2025-07-17 at 17 37 47
Ordering: from most recently created to least recently created Screenshot 2025-07-17 at 17 43 14
Ordering: from least recently updated to most recently updated Screenshot 2025-07-17 at 17 44 05
Less explicit prompt: show me discussions from last 10 days Screenshot 2025-07-17 at 17 47 09
Ordering with weaker model (GPT-4o) Screenshot 2025-07-17 at 17 59 42

Note: this PR adds author data to the payload of the list_discussions tool but doesn't add support for filtering by author when listing discussions because that is not supported on the discussions field in the API, and it would need to be achieved in a separate search tool.

@tommaso-moro tommaso-moro marked this pull request as ready for review July 17, 2025 17:03
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 17:03
@tommaso-moro tommaso-moro requested a review from a team as a code owner July 17, 2025 17:03
@tommaso-moro tommaso-moro requested a review from omgitsads July 17, 2025 17:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the list_discussions tool by adding ordering capabilities and expanding the discussion payload to include author information and updated timestamps. The changes enable users to sort discussions by creation or update date in ascending or descending order, while maintaining backward compatibility with existing functionality.

  • Added updatedAt and author.login fields to the discussion payload
  • Implemented ordering support with orderBy and direction parameters
  • Refactored GraphQL query handling to support optional parameters through pre-defined query variants

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
pkg/github/discussions.go Added new query struct types, ordering logic, and GraphQL query selection based on parameters
pkg/github/discussions_test.go Updated test data and added comprehensive test cases for ordering functionality
README.md Updated documentation to reflect new ordering parameters

@LuluBeatson LuluBeatson changed the title Tommy/expand-list-discussions-tool feat: list_discussions sort by updatedAt & createdAt, return updatedAt and author Jul 21, 2025
@LuluBeatson LuluBeatson self-assigned this Jul 21, 2025
@LuluBeatson LuluBeatson added the enhancement New feature or request label Jul 21, 2025
@LuluBeatson
Copy link
Contributor

Thanks @tommaso-moro for taking on this issue and refactoring the ListDiscussion GraphQL queries.

I have merged main into this branch, bringing GraphQL pagination to Discussion tools.

Plain List
list the last 20 discussions in facebook/react
image
List with Pagination
list all discussions in facebook/react with page size 3
...
Yes fetch the next page too
image image
List with Pagination & Reverse CreatedAt Sorting
list all discussions in facebook/react with page size 3 in reverse order of creation
image
List with Pagination & UpdatedAt Sorting
list all discussions in facebook/react with page size 3 in order of last update
image

@mattdholloway
Copy link
Contributor

mattdholloway commented Jul 22, 2025

This looks great! The only potential issue I can see is with the following user flow:

  1. Gets page 1 with a given sort order eg. ordered by time created
  2. Uses endCursor from that response
  3. Makes another request with a new sort order

A potential improvement might be to force the pagination to be restarted when the sort order is changed so that the results are consistent. Perhaps updating the tool description for endCursor with a warning to the effect of 'this becomes invalid if the sort order changes' might help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discussions toolset: add author.login, updated_at in response; and orderBy in parameters
3 participants