Skip to content

Conversation

@Higangssh
Copy link

@Higangssh Higangssh commented Oct 25, 2025

Problem

The get_discussion tool lacked important metadata fields already available in get_issue, making it difficult
to determine discussion status.

Solution

Added discussion metadata fields:

  • closed - Boolean indicating if the discussion is closed
  • isAnswered - Whether discussion has an accepted answer
  • answerChosenAt - Timestamp when answer was selected (optional)

Implementation Details

Modified GetDiscussion to return map[string]interface{} instead of github.Discussion struct because
go-github v74's Discussion type lacks isAnswered and answerChosenAt fields. This approach mirrors existing
functions: ListDiscussions and GetDiscussionComments use similar patterns.

Changes Made

  • Updated Discussion field mappings to match GitHub GraphQL API schema
  • Replaced non-existent State field with Closed (Boolean)
  • Removed non-existent AnsweredAt field
  • Using AnswerChosenAt for answer timestamp
  • Added nil checks for optional timestamp fields
  • Updated all test cases and mock data
  • All tests passing ✅

Testing

All tests pass with updated snapshots. Linter reports no issues. Backward compatibility verified.

Fixes #1303

Fixes github#1303

The get_discussion tool was missing important state metadata that's
already available in get_issue. Added four fields to provide complete
discussion status information:

- state: Current discussion state (OPEN/CLOSED)
- isAnswered: Whether the discussion has an accepted answer
- answeredAt: Timestamp when answer was provided
- answerChosenAt: Timestamp when answer was selected

Changed GetDiscussion to return a map instead of github.Discussion
struct since the go-github library doesn't include all these fields
in its type definition. This approach is consistent with other
functions in this codebase (ListDiscussions, GetDiscussionComments).

All tests pass and linter checks pass.
Copy link
Contributor

@tommaso-moro tommaso-moro left a comment

Choose a reason for hiding this comment

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

Hi @Higangssh thank you for your work on this. I have tested it locally and it is not working (screenshot below), it looks like some of the fields are invalid. For example, State, IsAnswered and AnsweredAt don't exist on Discussion.

Instead of State you can use the closed field and then update the response map to use "closed": bool(d.Closed). As to the other two, I would recommend using answerChosenAt, and deriving isAnswered from it (specifically, it will be equivalent to answerChosenAt != nil).

I also recommend using the official GitHub GraphQL API Explorer to play around with the query and see which fields are available and what they return.

If you can, it would be great if you could update this PR. Otherwise, I am also happy to do it if you prefer. Thank you!

Image

Title githubv4.String
CreatedAt githubv4.DateTime
UpdatedAt githubv4.DateTime
State githubv4.String
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe State, AnsweredAt and IsAnswered are not valid fields for the Discussion type

Changes:
- Replace 'State' (doesn't exist) with 'Closed' (Boolean)
- Remove 'AnsweredAt' (doesn't exist)
- Keep 'IsAnswered' (verified to exist in GitHub GraphQL API)
- Use 'AnswerChosenAt' for answer timestamp

Updated both implementation and tests to match actual GitHub GraphQL schema.
All tests passing.
@Higangssh
Copy link
Author

Hi @tommaso-moro, thank you so much for the detailed review and suggestions!

I've updated the PR following your recommendations:

  • StateClosed (Boolean)
  • AnsweredAt → Removed (using answerChosenAt instead)

Regarding isAnswered:

Following your suggestion to use the GraphQL API Explorer, I tested the available fields and found that isAnswered is actually a valid field in the Discussion type.

Evidence:

  1. Official Documentation: The GitHub GraphQL Reference lists isAnswered (Boolean) as a field for Discussion objects.

  2. GraphQL Query Test: I tested with both answered and unanswered discussions:

   query {
     repository(owner: "github", name: "github-mcp-server") {
       discussion(number: 1248) {
         isAnswered
         answerChosenAt
       }
     }
   }
  • Answered discussion (1248): { "isAnswered": true, "answerChosenAt": "2025-10-20T09:57:37Z" }
  • Unanswered discussion (1088): { "isAnswered": false, "answerChosenAt": null }

Both queries executed successfully without errors, confirming that isAnswered is valid.

Given this, I've kept isAnswered as a direct field query rather than deriving it. This approach uses the field that GitHub's API provides and is more efficient than client-side calculation.

Would you prefer I derive it from answerChosenAt != nil instead, or is this approach acceptable?

Thank you again for your help! 🙏


image --- image

@Higangssh Higangssh changed the title Add state metadata fields to get_discussion tool Add discussion metadata fields to get_discussion tool Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_discussion not returning whether discussion is open/closed

2 participants