Skip to content

Conversation

@setchy
Copy link
Member

@setchy setchy commented Dec 23, 2025

No description provided.

@github-actions github-actions bot added the refactor Refactoring of existing feature label Dec 23, 2025
@setchy setchy requested a review from Copilot December 23, 2025 01:22
Signed-off-by: Adam Setch <[email protected]>
Copy link

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 refactors the authenticated user details fetching mechanism from the REST API endpoint to a GraphQL query. The change modernizes the codebase by leveraging GraphQL's more efficient data fetching capabilities while maintaining the same functionality.

Key changes:

  • Replaced REST endpoint /user with GraphQL viewer query for fetching authenticated user details
  • Updated the GitifyUser.id type from number to string to match GraphQL's ID type
  • Modified response structure to use GraphQL field naming conventions (e.g., avatarUrl instead of avatar_url)

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/renderer/utils/api/client.ts Removed getAuthenticatedUser REST function and added fetchAuthenticatedUserDetails GraphQL function
src/renderer/utils/api/graphql/user.graphql New GraphQL query definition for fetching authenticated user details via the viewer field
src/renderer/utils/api/graphql/generated/graphql.ts Auto-generated TypeScript types and document strings for the new GraphQL query
src/renderer/utils/api/graphql/generated/gql.ts Auto-generated GraphQL helper functions for the new query
src/renderer/utils/api/request.ts Added ExecutionResultWithHeaders type to attach HTTP headers to GraphQL responses
src/renderer/utils/auth/utils.ts Updated getUserData and refreshAccount to use the new GraphQL endpoint and handle the new response structure
src/renderer/utils/auth/utils.test.ts Updated tests to mock the new GraphQL function instead of using nock to intercept REST calls
src/renderer/utils/api/client.test.ts Removed test for deprecated getAuthenticatedUser function
src/renderer/types.ts Changed GitifyUser.id type from number to string to match GraphQL ID type
src/renderer/typesGitHub.ts Removed unused UserDetails, UserProfile, and Plan interfaces
src/renderer/mocks/user-mocks.ts Updated mock data to use string ID instead of number
Comments suppressed due to low confidence (1)

src/renderer/utils/auth/utils.ts:80

  • The getUserData function doesn't check for GraphQL errors before accessing response.data.viewer. GraphQL ExecutionResult can contain an 'errors' field even with a 200 HTTP status. If the GraphQL query fails (e.g., due to authentication issues), accessing response.data.viewer could fail or return undefined. Consider checking for response.errors before accessing the data, similar to how other GraphQL-based functions in the codebase should handle errors.
    `https://${authOptions.hostname}/login/oauth/access_token` as Link;
  const data = {

Comment on lines 158 to 162
);

const accountScopes = res.headers['x-oauth-scopes']
const accountScopes = response.headers['x-oauth-scopes']
?.split(',')
.map((scope: string) => scope.trim());
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The refreshAccount function doesn't check for GraphQL errors before accessing response.data.viewer. GraphQL ExecutionResult can contain an 'errors' field even with a 200 HTTP status. If the GraphQL query fails, accessing response.data.viewer could fail or return undefined, potentially causing runtime errors. Consider checking for response.errors before accessing the data.

Copilot uses AI. Check for mistakes.
@setchy setchy changed the title refactor(api): use graphql endpoint for fetching authenticated user details refactor(api): fetch authenticated user details via GraphQL query Dec 24, 2025
@sonarqubecloud
Copy link

@setchy setchy merged commit 74d5872 into main Dec 24, 2025
16 checks passed
@setchy setchy deleted the refactor/api-user branch December 24, 2025 06:31
@github-actions github-actions bot added this to the Release 6.15.0 milestone Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring of existing feature

Development

Successfully merging this pull request may close these issues.

2 participants