Skip to content

Commit 70102b0

Browse files
committed
wip
Signed-off-by: Adam Setch <[email protected]>
1 parent 04a3199 commit 70102b0

File tree

5 files changed

+70
-17
lines changed

5 files changed

+70
-17
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"@discordapp/twemoji": "16.0.1",
8484
"@electron/notarize": "3.0.2",
8585
"@octokit/core": "^6.1.6",
86+
"@octokit/plugin-rest-endpoint-methods": "^16.1.0",
8687
"@primer/octicons-react": "19.15.5",
8788
"@primer/primitives": "11.1.0",
8889
"@primer/react": "36.27.0",

pnpm-lock.yaml

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

src/renderer/components/fields/__snapshots__/Tooltip.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/utils/api/client.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,45 @@ export function headNotifications(
6464
*
6565
* Endpoint documentation: https://docs.github.com/en/rest/activity/notifications#list-notifications-for-the-authenticated-user
6666
*/
67-
export function listNotificationsForAuthenticatedUser(
67+
export async function listNotificationsForAuthenticatedUser(
6868
account: Account,
6969
settings: SettingsState,
70-
): AxiosPromise<Notification[]> {
71-
const url = getGitHubAPIBaseUrl(account.hostname);
72-
url.pathname += 'notifications';
73-
url.searchParams.append('participating', String(settings.participating));
74-
return apiRequestAuth(
75-
url.toString() as Link,
76-
'GET',
77-
account.token,
78-
{},
79-
settings.fetchAllNotifications,
80-
);
70+
): Promise<AxiosPromise<Notification[]>> {
71+
const octokit = await createOctokitClient(account.hostname, account.token);
72+
73+
let response: any;
74+
75+
if (settings.fetchAllNotifications) {
76+
response = await octokit.paginate.iterator(
77+
octokit.rest.activity.listNotificationsForAuthenticatedUser,
78+
{
79+
participating: settings.participating,
80+
},
81+
);
82+
}
83+
84+
response = await octokit.rest.activity.listNotificationsForAuthenticatedUser({
85+
participating: settings.participating,
86+
});
87+
88+
// Return axios-like response format
89+
return {
90+
data: response,
91+
status: 200,
92+
statusText: 'OK',
93+
headers: {},
94+
} as any;
95+
96+
// const url = getGitHubAPIBaseUrl(account.hostname);
97+
// url.pathname += 'notifications';
98+
// url.searchParams.append('participating', String(settings.participating));
99+
// return apiRequestAuth(
100+
// url.toString() as Link,
101+
// 'GET',
102+
// account.token,
103+
// {},
104+
// settings.fetchAllNotifications,
105+
// );
81106
}
82107

83108
/**
@@ -239,7 +264,7 @@ export async function searchDiscussions(
239264
notification.account.hostname,
240265
notification.account.token,
241266
);
242-
267+
243268
const result = await octokit.graphql(print(QUERY_SEARCH_DISCUSSIONS), {
244269
queryStatement: formatAsGitHubSearchSyntax(
245270
notification.repository.full_name,

src/renderer/utils/api/octokit.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Octokit } from '@octokit/core';
22
import { paginateRest } from '@octokit/plugin-paginate-rest';
3+
import { restEndpointMethods } from '@octokit/plugin-rest-endpoint-methods';
34

45
import { logWarn } from '../../../shared/logger';
56
import type { Hostname, Token } from '../../types';
67
import { decryptValue } from '../comms';
78
import { getGitHubAPIBaseUrl } from './utils';
89

910
// Create the Octokit class with pagination plugin
10-
const OctokitWithPagination = Octokit.plugin(paginateRest);
11+
const OctokitWithPagination = Octokit.plugin(restEndpointMethods, paginateRest);
1112

1213
/**
1314
* Create an Octokit client instance for a given hostname and token
@@ -20,7 +21,7 @@ export async function createOctokitClient(
2021
// TODO - Remove this try-catch block in a future release
2122
try {
2223
apiToken = (await decryptValue(token)) as Token;
23-
} catch (err) {
24+
} catch (_err) {
2425
logWarn('createOctokitClient', 'Token is not yet encrypted');
2526
}
2627

@@ -45,4 +46,4 @@ export function createOctokitClientFromToken(
4546
auth: token,
4647
baseUrl: baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl,
4748
});
48-
}
49+
}

0 commit comments

Comments
 (0)