Skip to content

Port discussions.py off the requests library onto PyGithub GraphQL #790

Description

@zkoppert

Is your feature request related to a problem?

discussions.py sends its GraphQL query with a direct requests.post call. When we migrated the rest of the action from github3.py to PyGithub (#789), this left requests as the one direct dependency that PyGithub does not cover, so we had to re-declare requests==2.34.2 (and types-requests) in pyproject.toml just to keep that single module working. Every other GitHub call now goes through PyGithub. If PyGithub ever swaps its HTTP backend, import discussions would break at load time.

For context, discussions.py predates the PyGithub move. github3.py had no Discussions support, so the original code reached for requests to hit the GraphQL API directly.

Describe the solution you'd like

Move get_discussions() onto PyGithub's GraphQL support and drop the direct requests usage:

  • PyGithub 2.9.1 exposes github_connection.requester.graphql_query(query, variables) (via the public requester property), which returns (headers, data) and reuses PyGithub's auth, base URL, and GitHub Enterprise /api/graphql handling.
  • Refactor get_discussions() to accept the Github connection instead of the raw token and ghe, then call graphql_query with the existing query string.
  • Once nothing imports requests directly, remove requests from dependencies and types-requests from the dev dependencies in pyproject.toml, and refresh uv.lock.
  • Confirm the Enterprise path: verify graphql_query builds the /api/graphql endpoint correctly for a GH_ENTERPRISE_URL base URL.
  • Update test_discussions.py, which currently patches requests.post, to mock the PyGithub GraphQL call instead.

Describe alternatives you've considered

  • Keep requests as a direct dependency (what we did in refactor: migrate from github3.py to PyGithub #789). It works, but it keeps a second HTTP client in the tree for one module and relies on us remembering it is a real direct dependency.
  • Wait for a high-level PyGithub Discussions object. PyGithub 2.9.1 has RepositoryDiscussion* classes but no object for a global search(type: DISCUSSION) query, so there is no drop-in replacement today. graphql_query is the available path.

Additional context

Follow-up from the PyGithub migration in #789. graphql_query is a lower-level method rather than a documented high-level API, so this is worth a small spike to confirm the return shape and Enterprise handling before committing to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions