Skip to content

Migrate list_issues tool from REST to GraphQL API #833

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

Merged
merged 14 commits into from
Aug 8, 2025

Conversation

MattBabbage
Copy link
Contributor

@MattBabbage MattBabbage commented Aug 7, 2025

Migrate list_issues tool from REST to GraphQL API

Overview

The key requirement was to ignore PRs when the list_issues tool was used. As per #790. To accomplish this, the tool had to be migrated away from the REST API, as this was not an allowed request. Therefore this PR migrates the list_issues tool from GitHub's REST API to GraphQL API, bringing it in line with other tools like list_discussions. The migration provides cursor-based pagination, improved filtering, and better performance.

Key Changes

  • API Migration: Switched from github.Client (REST) to githubv4.Client (GraphQL)
  • Pagination: Migrated from page-based to cursor-based (after, perPage)
  • Dynamic Queries: Conditional GraphQL queries based on labels and date filtering
  • New Features: Added since parameter for date filtering (ISO 8601 format)
  • Enhanced Performance: GraphQL's selective field querying reduces payload size

GraphQL vs REST

Parameter Updates:

  • pageafter (cursor-based pagination)
  • sortorderBy with new enum values
  • State values: "open""OPEN", "closed""CLOSED"
  • Direction values: "asc""ASC", "desc""DESC"
  • Order fields: "created""CREATED_AT", "updated""UPDATED_AT"

Implementation

Dynamic Query Selection: Factory pattern selects appropriate GraphQL query based on filtering requirements (4 query types: base, with labels, with since, with both).

Fragment Architecture: Reusable IssueFragment with common interface for consistent data conversion.

Testing & Quality

  • Updated tests to use GraphQL mocking with githubv4mock
  • Comprehensive coverage: tool definition, dynamic queries, fragment conversion
  • Updated README.md with new parameter descriptions
  • All linting checks pass

This migration provides better performance, consistent API patterns, and enhanced filtering while maintaining backward compatibility. 🚀

Before & After

Before: Returns correct info (but included PRs) and lots of URLs.
[ { "id": 1234567890, "number": 842, "state": "open", "locked": false, "title": "[sanitized] Tool reports success when a non-existent repo owner is used", "body": "[sanitized] Bug description with reproduction steps...", "author_association": "NONE", "user": { "login": "[username]", "id": 12345678, "node_id": "[sanitized_node_id]", "avatar_url": "[sanitized_avatar_url]", "html_url": "[sanitized_profile_url]", "gravatar_id": "", "type": "User", "site_admin": false, "url": "[sanitized_api_url]", "events_url": "[sanitized_events_url]", "following_url": "[sanitized_following_url]", "followers_url": "[sanitized_followers_url]", "gists_url": "[sanitized_gists_url]", "organizations_url": "[sanitized_orgs_url]", "received_events_url": "[sanitized_received_events_url]", "repos_url": "[sanitized_repos_url]", "starred_url": "[sanitized_starred_url]", "subscriptions_url": "[sanitized_subscriptions_url]" }, "labels": [ { "id": 1234567890, "url": "[sanitized_label_url]", "name": "bug", "color": "d73a4a", "description": "Something isn't working", "default": true, "node_id": "[sanitized_node_id]" } ], "comments": 0, "created_at": "2025-08-08T02:29:19Z", "updated_at": "2025-08-08T07:32:39Z", "url": "[sanitized_api_url]", "html_url": "[sanitized_web_url]", "comments_url": "[sanitized_comments_url]", "events_url": "[sanitized_events_url]", "labels_url": "[sanitized_labels_url]", "repository_url": "[sanitized_repo_url]", "reactions": { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "confused": 0, "heart": 0, "hooray": 0, "rocket": 0, "eyes": 0, "url": "[sanitized_reactions_url]" }, "node_id": "[sanitized_node_id]" } ]

After: Reduction in context, avoiding unnecessary URLs, irrelevant data and does not return PRs.

{ "issues": [ { "id": 1234567890, "number": 1234, "state": "OPEN", "title": "[sanitized] Sample issue title", "body": "[sanitized] Issue description and reproduction steps...", "user": { "login": "[username]" }, "labels": [ { "name": "bug", "description": "Something isn't working", "node_id": "[sanitized_node_id]" } ], "created_at": "2025-08-07T17:21:22Z", "updated_at": "2025-08-07T17:21:22Z" } ], "pageInfo": { "endCursor": "[base64_cursor]", "hasNextPage": true, "hasPreviousPage": false, "startCursor": "[base64_cursor]" }, "totalCount": 622 }

@MattBabbage MattBabbage requested a review from a team as a code owner August 7, 2025 10:36
@Copilot Copilot AI review requested due to automatic review settings August 7, 2025 10:36
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 migrates the list_issues tool from GitHub's REST API to GraphQL API to improve performance and provide more efficient data fetching capabilities.

  • Replaced REST API client with GraphQL client for issue listing functionality
  • Implemented conditional GraphQL query structures based on label filtering requirements
  • Migrated from page-based to cursor-based pagination with improved user guidance

Reviewed Changes

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

File Description
pkg/github/tools.go Updated tool registration to use GraphQL client instead of REST client
pkg/github/queries.json Added sample GraphQL response data and mock JSON structures
pkg/github/issues.go Complete migration of list_issues implementation from REST to GraphQL with new data structures and pagination

@MattBabbage MattBabbage linked an issue Aug 8, 2025 that may be closed by this pull request
Copy link
Contributor

@kerobbi kerobbi left a comment

Choose a reason for hiding this comment

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

LGTM!

@kerobbi kerobbi merged commit 8aa3379 into main Aug 8, 2025
16 checks passed
@kerobbi kerobbi deleted the fix-790-separate-issues-from-prs branch August 8, 2025 14:26
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.

Provide a top level function for fetching non-PR issues
3 participants