Skip to content

Commit 1f4fd85

Browse files
committed
Merge branch 'main' into feat/octokit-types
Signed-off-by: Adam Setch <[email protected]>
2 parents 08dd85a + 74d5872 commit 1f4fd85

File tree

13 files changed

+139
-85
lines changed

13 files changed

+139
-85
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"@primer/css": "22.0.2",
8989
"@primer/octicons-react": "19.21.1",
9090
"@primer/primitives": "11.3.2",
91-
"@primer/react": "38.6.1",
91+
"@primer/react": "38.6.2",
9292
"@tailwindcss/postcss": "4.1.18",
9393
"@testing-library/jest-dom": "6.9.1",
9494
"@testing-library/react": "16.3.1",
@@ -135,7 +135,7 @@
135135
"webpack-cli": "6.0.1",
136136
"webpack-merge": "6.0.1"
137137
},
138-
"packageManager": "[email protected].1",
138+
"packageManager": "[email protected].2",
139139
"pnpm": {
140140
"onlyBuiltDependencies": [
141141
"@biomejs/biome",

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/__mocks__/user-mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { User } from '../typesGitHub';
44
export const mockGitifyUser: GitifyUser = {
55
login: 'octocat',
66
name: 'Mona Lisa Octocat',
7-
id: 123456789,
7+
id: '123456789',
88
avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
99
};
1010

src/renderer/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export interface GitifyUser {
204204
login: string;
205205
name: string | null;
206206
avatar: Link | null;
207-
id: number;
207+
id: string;
208208
}
209209

210210
export interface GitifyError {

src/renderer/typesGitHub.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ import type { GitifyNotification, GitifySubject, Link } from './types';
44

55
// TODO: #828 Add explicit types for GitHub API response vs Gitify Notifications object
66

7+
export interface User {
8+
login: string;
9+
id: number;
10+
node_id: string;
11+
avatar_url: Link;
12+
gravatar_url: Link;
13+
url: Link;
14+
html_url: Link;
15+
followers_url: Link;
16+
following_url: Link;
17+
gists_url: Link;
18+
starred_url: Link;
19+
subscriptions_url: Link;
20+
organizations_url: Link;
21+
repos_url: Link;
22+
events_url: Link;
23+
received_events_url: Link;
24+
type: UserType;
25+
site_admin: boolean;
26+
}
27+
728
export type Notification = GitHubNotification &
829
GitifyNotification & {
930
reason: Reason;

src/renderer/utils/api/client.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
mockNonCachedAuthHeaders,
1010
} from './__mocks__/request-mocks';
1111
import {
12-
getAuthenticatedUser,
1312
getHtmlUrl,
1413
headNotifications,
1514
ignoreNotificationThreadSubscription,
@@ -29,17 +28,6 @@ describe('renderer/utils/api/client.ts', () => {
2928
jest.clearAllMocks();
3029
});
3130

32-
it('getAuthenticatedUser - should fetch authenticated user', async () => {
33-
await getAuthenticatedUser(mockGitHubHostname, mockToken);
34-
35-
expect(axios).toHaveBeenCalledWith({
36-
url: 'https://api.github.com/user',
37-
headers: mockAuthHeaders,
38-
method: 'GET',
39-
data: {},
40-
});
41-
});
42-
4331
it('headNotifications - should fetch notifications head', async () => {
4432
await headNotifications(mockGitHubHostname, mockToken);
4533

src/renderer/utils/api/client.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,30 @@ import type {
1414
Notification,
1515
NotificationThreadSubscription,
1616
Release,
17-
UserDetails,
1817
} from '../../typesGitHub';
1918
import { isAnsweredDiscussionFeatureSupported } from '../features';
2019
import { rendererLogError } from '../logger';
2120
import {
21+
FetchAuthenticatedUserDetailsDocument,
22+
type FetchAuthenticatedUserDetailsQuery,
2223
FetchDiscussionByNumberDocument,
2324
type FetchDiscussionByNumberQuery,
2425
FetchIssueByNumberDocument,
2526
type FetchIssueByNumberQuery,
2627
FetchPullRequestByNumberDocument,
2728
type FetchPullRequestByNumberQuery,
2829
} from './graphql/generated/graphql';
29-
import { apiRequestAuth, performGraphQLRequest } from './request';
30+
import {
31+
apiRequestAuth,
32+
type ExecutionResultWithHeaders,
33+
performGraphQLRequest,
34+
} from './request';
3035
import {
3136
getGitHubAPIBaseUrl,
3237
getGitHubGraphQLUrl,
3338
getNumberFromUrl,
3439
} from './utils';
3540

36-
/**
37-
* Get the authenticated user
38-
*
39-
* Endpoint documentation: https://docs.github.com/en/rest/users/users#get-the-authenticated-user
40-
*/
41-
export function getAuthenticatedUser(
42-
hostname: Hostname,
43-
token: Token,
44-
): AxiosPromise<UserDetails> {
45-
const url = getGitHubAPIBaseUrl(hostname);
46-
url.pathname += 'user';
47-
48-
return apiRequestAuth(url.toString() as Link, 'GET', token);
49-
}
50-
5141
/**
5242
* Perform a HEAD operation, used to validate that connectivity is established.
5343
*
@@ -187,6 +177,22 @@ export async function getHtmlUrl(url: Link, token: Token): Promise<string> {
187177
}
188178
}
189179

180+
/**
181+
* Fetch details of the currently authenticated GitHub user.
182+
*/
183+
export async function fetchAuthenticatedUserDetails(
184+
hostname: Hostname,
185+
token: Token,
186+
): Promise<ExecutionResultWithHeaders<FetchAuthenticatedUserDetailsQuery>> {
187+
const url = getGitHubGraphQLUrl(hostname);
188+
189+
return performGraphQLRequest(
190+
url.toString() as Link,
191+
token,
192+
FetchAuthenticatedUserDetailsDocument,
193+
);
194+
}
195+
190196
/**
191197
* Fetch GitHub Issue by Issue Number.
192198
*/

src/renderer/utils/api/graphql/generated/gql.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ type Documents = {
1919
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n ...DiscussionDetails\n }\n }\n}\n\nfragment DiscussionDetails on Discussion {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...DiscussionCommentFields\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}\n\nfragment DiscussionCommentFields on DiscussionComment {\n ...CommentFields\n replies(last: $lastReplies) {\n totalCount\n nodes {\n ...CommentFields\n }\n }\n}": typeof types.FetchDiscussionByNumberDocument,
2020
"query FetchIssueByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $firstLabels: Int) {\n repository(owner: $owner, name: $name) {\n issue(number: $number) {\n ...IssueDetails\n }\n }\n}\n\nfragment IssueDetails on Issue {\n __typename\n number\n title\n url\n state\n stateReason\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n}": typeof types.FetchIssueByNumberDocument,
2121
"query FetchPullRequestByNumber($owner: String!, $name: String!, $number: Int!, $firstLabels: Int, $lastComments: Int, $lastReviews: Int, $firstClosingIssues: Int) {\n repository(owner: $owner, name: $name) {\n pullRequest(number: $number) {\n ...PullRequestDetails\n }\n }\n}\n\nfragment PullRequestDetails on PullRequest {\n __typename\n number\n title\n url\n state\n merged\n isDraft\n isInMergeQueue\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n reviews(last: $lastReviews) {\n totalCount\n nodes {\n ...PullRequestReviewFields\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n closingIssuesReferences(first: $firstClosingIssues) {\n nodes {\n number\n }\n }\n}\n\nfragment PullRequestReviewFields on PullRequestReview {\n state\n author {\n login\n }\n}": typeof types.FetchPullRequestByNumberDocument,
22+
"query FetchAuthenticatedUserDetails {\n viewer {\n id\n name\n login\n avatarUrl\n }\n}": typeof types.FetchAuthenticatedUserDetailsDocument,
2223
};
2324
const documents: Documents = {
2425
"fragment AuthorFields on Actor {\n login\n html_url: url\n avatar_url: avatarUrl\n type: __typename\n}\n\nfragment MilestoneFields on Milestone {\n state\n title\n}": types.AuthorFieldsFragmentDoc,
2526
"query FetchDiscussionByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $lastReplies: Int, $firstLabels: Int, $includeIsAnswered: Boolean!) {\n repository(owner: $owner, name: $name) {\n discussion(number: $number) {\n ...DiscussionDetails\n }\n }\n}\n\nfragment DiscussionDetails on Discussion {\n __typename\n number\n title\n stateReason\n isAnswered @include(if: $includeIsAnswered)\n url\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n ...DiscussionCommentFields\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n}\n\nfragment CommentFields on DiscussionComment {\n databaseId\n createdAt\n author {\n ...AuthorFields\n }\n url\n}\n\nfragment DiscussionCommentFields on DiscussionComment {\n ...CommentFields\n replies(last: $lastReplies) {\n totalCount\n nodes {\n ...CommentFields\n }\n }\n}": types.FetchDiscussionByNumberDocument,
2627
"query FetchIssueByNumber($owner: String!, $name: String!, $number: Int!, $lastComments: Int, $firstLabels: Int) {\n repository(owner: $owner, name: $name) {\n issue(number: $number) {\n ...IssueDetails\n }\n }\n}\n\nfragment IssueDetails on Issue {\n __typename\n number\n title\n url\n state\n stateReason\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n}": types.FetchIssueByNumberDocument,
2728
"query FetchPullRequestByNumber($owner: String!, $name: String!, $number: Int!, $firstLabels: Int, $lastComments: Int, $lastReviews: Int, $firstClosingIssues: Int) {\n repository(owner: $owner, name: $name) {\n pullRequest(number: $number) {\n ...PullRequestDetails\n }\n }\n}\n\nfragment PullRequestDetails on PullRequest {\n __typename\n number\n title\n url\n state\n merged\n isDraft\n isInMergeQueue\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n reviews(last: $lastReviews) {\n totalCount\n nodes {\n ...PullRequestReviewFields\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n closingIssuesReferences(first: $firstClosingIssues) {\n nodes {\n number\n }\n }\n}\n\nfragment PullRequestReviewFields on PullRequestReview {\n state\n author {\n login\n }\n}": types.FetchPullRequestByNumberDocument,
29+
"query FetchAuthenticatedUserDetails {\n viewer {\n id\n name\n login\n avatarUrl\n }\n}": types.FetchAuthenticatedUserDetailsDocument,
2830
};
2931

3032
/**
@@ -43,6 +45,10 @@ export function graphql(source: "query FetchIssueByNumber($owner: String!, $name
4345
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
4446
*/
4547
export function graphql(source: "query FetchPullRequestByNumber($owner: String!, $name: String!, $number: Int!, $firstLabels: Int, $lastComments: Int, $lastReviews: Int, $firstClosingIssues: Int) {\n repository(owner: $owner, name: $name) {\n pullRequest(number: $number) {\n ...PullRequestDetails\n }\n }\n}\n\nfragment PullRequestDetails on PullRequest {\n __typename\n number\n title\n url\n state\n merged\n isDraft\n isInMergeQueue\n milestone {\n ...MilestoneFields\n }\n author {\n ...AuthorFields\n }\n comments(last: $lastComments) {\n totalCount\n nodes {\n url\n author {\n ...AuthorFields\n }\n }\n }\n reviews(last: $lastReviews) {\n totalCount\n nodes {\n ...PullRequestReviewFields\n }\n }\n labels(first: $firstLabels) {\n nodes {\n name\n }\n }\n closingIssuesReferences(first: $firstClosingIssues) {\n nodes {\n number\n }\n }\n}\n\nfragment PullRequestReviewFields on PullRequestReview {\n state\n author {\n login\n }\n}"): typeof import('./graphql').FetchPullRequestByNumberDocument;
48+
/**
49+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
50+
*/
51+
export function graphql(source: "query FetchAuthenticatedUserDetails {\n viewer {\n id\n name\n login\n avatarUrl\n }\n}"): typeof import('./graphql').FetchAuthenticatedUserDetailsDocument;
4652

4753

4854
export function graphql(source: string) {

src/renderer/utils/api/graphql/generated/graphql.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36083,6 +36083,11 @@ export type PullRequestReviewFieldsFragment = { __typename?: 'PullRequestReview'
3608336083
| { __typename?: 'User', login: string }
3608436084
| null };
3608536085

36086+
export type FetchAuthenticatedUserDetailsQueryVariables = Exact<{ [key: string]: never; }>;
36087+
36088+
36089+
export type FetchAuthenticatedUserDetailsQuery = { __typename?: 'Query', viewer: { __typename?: 'User', id: string, name?: string | null, login: string, avatarUrl: any } };
36090+
3608636091
export class TypedDocumentString<TResult, TVariables>
3608736092
extends String
3608836093
implements DocumentTypeDecoration<TResult, TVariables>
@@ -36468,4 +36473,14 @@ fragment PullRequestReviewFields on PullRequestReview {
3646836473
author {
3646936474
login
3647036475
}
36471-
}`) as unknown as TypedDocumentString<FetchPullRequestByNumberQuery, FetchPullRequestByNumberQueryVariables>;
36476+
}`) as unknown as TypedDocumentString<FetchPullRequestByNumberQuery, FetchPullRequestByNumberQueryVariables>;
36477+
export const FetchAuthenticatedUserDetailsDocument = new TypedDocumentString(`
36478+
query FetchAuthenticatedUserDetails {
36479+
viewer {
36480+
id
36481+
name
36482+
login
36483+
avatarUrl
36484+
}
36485+
}
36486+
`) as unknown as TypedDocumentString<FetchAuthenticatedUserDetailsQuery, FetchAuthenticatedUserDetailsQueryVariables>;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
query FetchAuthenticatedUserDetails {
2+
viewer {
3+
id
4+
name
5+
login
6+
avatarUrl
7+
}
8+
}

0 commit comments

Comments
 (0)