Skip to content

refactor: use make_graphql_headers in pat_handler _test_pat_against_repo#1164

Merged
anderdc merged 2 commits into
entrius:testfrom
ebios-star:refactor/use-make-graphql-headers-in-pat-handler
May 12, 2026
Merged

refactor: use make_graphql_headers in pat_handler _test_pat_against_repo#1164
anderdc merged 2 commits into
entrius:testfrom
ebios-star:refactor/use-make-graphql-headers-in-pat-handler

Conversation

@ebios-star
Copy link
Copy Markdown
Contributor

Summary

Follow-up to merged #499, which introduced make_graphql_headers(token) in gittensor/utils/github_api_tools.py and replaced two inline {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'} dicts in execute_graphql_query and get_github_graphql_query.

gittensor/validator/pat_handler.py::_test_pat_against_repo still builds the same dict inline:

headers = {'Authorization': f'Bearer {pat}', 'Accept': 'application/json'}
try:
    response = requests.post(
        f'{BASE_GITHUB_API_URL}/graphql',
        json={'query': GRAPHQL_VIEWER_QUERY},
        headers=headers,
        timeout=GITHUB_HTTP_TIMEOUT_SECONDS,
    )

This is the one GraphQL Authorization: Bearer … header construction in the codebase that doesn't use make_graphql_headers. grep -rn "'Authorization': f'Bearer" confirms only this site and the helper's own definition remain.

Switching to make_graphql_headers(pat) puts every GraphQL Authorization header through one factory. The helper adds an explicit 'Content-Type': 'application/json' header — requests.post(..., json=...) already sets the same value automatically from the json= kwarg, so the wire request is unchanged.

Net: +2 / -2 lines, single file.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other

Testing

  • pytest tests/ — all 1491 tests pass.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Changes are documented (if applicable)

Follow-up to entrius#499, which introduced make_graphql_headers and replaced
two inline {'Authorization': f'Bearer {token}', ...} dicts in
github_api_tools.py. validator/pat_handler.py._test_pat_against_repo
still built the same dict inline.

Switch the one remaining call site to the canonical helper so all
GraphQL Authorization headers are constructed in one place. The helper
adds an explicit 'Content-Type: application/json' header — requests.post
sets the same value automatically from the json= kwarg, so this is not
a behaviour change for this request.
@ebios-star
Copy link
Copy Markdown
Contributor Author

@anderdc whenever you have a moment, this is a small follow-up to #499 that routes the one remaining inline GraphQL Authorization header construction through make_graphql_headers. Happy to revise scope if you'd prefer. Thanks!

@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label May 11, 2026
@anderdc anderdc merged commit d7a1255 into entrius:test May 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants