Skip to content

Commit 7b3e1b3

Browse files
committed
refactor: use octokit client
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 33aafc8 commit 7b3e1b3

8 files changed

Lines changed: 221 additions & 287 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"@types/react-dom": "19.2.3",
102102
"@types/react-router-dom": "5.3.3",
103103
"@types/semver": "7.7.1",
104-
"axios": "1.13.2",
105104
"babel-jest": "30.2.0",
106105
"clsx": "2.1.1",
107106
"concurrently": "9.2.1",
@@ -152,4 +151,4 @@
152151
"*": "biome check --no-errors-on-unmatched",
153152
"*.{js,ts,tsx}": "pnpm test --findRelatedTests --passWithNoTests --updateSnapshot"
154153
}
155-
}
154+
}

pnpm-lock.yaml

Lines changed: 0 additions & 30 deletions
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: 52 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,36 @@ export async function listNotificationsForAuthenticatedUser(
6464
): Promise<ListNotificationsForAuthenticatedUserResponse> {
6565
const octokit = await createOctokitClient(account);
6666

67-
if (settings.fetchAllNotifications) {
68-
// Fetch all pages using Octokit's pagination
69-
return await octokit.paginate(
70-
octokit.rest.activity.listNotificationsForAuthenticatedUser,
71-
{
67+
if (settings.fetchAllNotifications) {
68+
// Fetch all pages using Octokit's pagination
69+
return await octokit.paginate(
70+
octokit.rest.activity.listNotificationsForAuthenticatedUser,
71+
{
72+
participating: settings.participating,
73+
all: settings.fetchReadNotifications,
74+
per_page: 100,
75+
// TODO - is this the right way to do this
76+
headers: {
77+
'If-None-Match': '', // Prevent caching
78+
},
79+
},
80+
);
81+
}
82+
83+
// Single page request
84+
const response =
85+
await octokit.rest.activity.listNotificationsForAuthenticatedUser({
7286
participating: settings.participating,
7387
all: settings.fetchReadNotifications,
7488
per_page: 100,
7589
// TODO - is this the right way to do this
7690
headers: {
7791
'If-None-Match': '', // Prevent caching
7892
},
79-
},
80-
);
81-
}
93+
});
8294

83-
// Single page request
84-
const response =
85-
await octokit.rest.activity.listNotificationsForAuthenticatedUser({
86-
participating: settings.participating,
87-
all: settings.fetchReadNotifications,
88-
per_page: 100,
89-
// TODO - is this the right way to do this
90-
headers: {
91-
'If-None-Match': '', // Prevent caching
92-
},
93-
});
94-
95-
return response.data;
95+
return response.data;
96+
9697
}
9798

9899
/**
@@ -107,11 +108,12 @@ export async function markNotificationThreadAsRead(
107108
): Promise<MarkNotificationThreadAsReadResponse> {
108109
const octokit = await createOctokitClient(account);
109110

110-
const response = await octokit.rest.activity.markThreadAsRead({
111-
thread_id: Number(threadId),
112-
});
111+
const response = await octokit.rest.activity.markThreadAsRead({
112+
thread_id: Number(threadId),
113+
});
113114

114-
return response.data;
115+
return response.data;
116+
115117
}
116118

117119
/**
@@ -128,11 +130,12 @@ export async function markNotificationThreadAsDone(
128130
): Promise<MarkNotificationThreadAsDoneResponse> {
129131
const octokit = await createOctokitClient(account);
130132

131-
const response = await octokit.rest.activity.markThreadAsDone({
132-
thread_id: Number(threadId),
133-
});
133+
const response = await octokit.rest.activity.markThreadAsDone({
134+
thread_id: Number(threadId),
135+
});
134136

135-
return response.data;
137+
return response.data;
138+
136139
}
137140

138141
/**
@@ -146,12 +149,13 @@ export async function ignoreNotificationThreadSubscription(
146149
): Promise<IgnoreNotificationThreadSubscriptionResponse> {
147150
const octokit = await createOctokitClient(account);
148151

149-
const response = await octokit.rest.activity.setThreadSubscription({
150-
thread_id: Number(threadId),
151-
ignored: true,
152-
});
152+
const response = await octokit.rest.activity.setThreadSubscription({
153+
thread_id: Number(threadId),
154+
ignored: true,
155+
});
153156

154-
return response.data;
157+
return response.data;
158+
155159
}
156160

157161
/**
@@ -163,14 +167,8 @@ export async function getCommit(
163167
account: Account,
164168
url: Link,
165169
): Promise<GetCommitResponse> {
166-
const octokit = await createOctokitClient(account);
170+
return followUrl<GetCommitResponse>(account, url)
167171

168-
// Perform a generic GET request using Octokit's request method
169-
const response = await octokit.request('GET {+url}', {
170-
url: url,
171-
});
172-
173-
return response.data as GetCommitResponse;
174172
}
175173

176174
/**
@@ -182,14 +180,8 @@ export async function getCommitComment(
182180
account: Account,
183181
url: Link,
184182
): Promise<GetCommitCommentResponse> {
185-
const octokit = await createOctokitClient(account);
186-
187-
// Perform a generic GET request using Octokit's request method
188-
const response = await octokit.request('GET {+url}', {
189-
url: url,
190-
});
183+
return followUrl<GetCommitCommentResponse>(account, url)
191184

192-
return response.data as GetCommitCommentResponse;
193185
}
194186

195187
/**
@@ -201,14 +193,8 @@ export async function getRelease(
201193
account: Account,
202194
url: Link,
203195
): Promise<GetReleaseResponse> {
204-
const octokit = await createOctokitClient(account);
205-
206-
// Perform a generic GET request using Octokit's request method
207-
const response = await octokit.request('GET {+url}', {
208-
url: url,
209-
});
196+
return followUrl<GetReleaseResponse>(account, url)
210197

211-
return response.data as GetReleaseResponse;
212198
}
213199

214200
/**
@@ -218,31 +204,25 @@ export async function getHtmlUrl(
218204
account: Account,
219205
url: Link,
220206
): Promise<GitHubHtmlUrlResponse> {
221-
const octokit = await createOctokitClient(account);
222-
223-
// Perform a generic GET request using Octokit's request method
224-
const response = await octokit.request('GET {+url}', {
225-
url: url,
226-
});
227-
228-
return response.data as GitHubHtmlUrlResponse;
207+
return followUrl<GitHubHtmlUrlResponse>(account, url)
229208
}
230209

231210
/**
232211
* Follow GitHub Response URL
233212
*/
234-
export async function followUrl<TResult>(
213+
async function followUrl<TResult>(
235214
account: Account,
236215
url: Link,
237216
): Promise<TResult> {
238217
const octokit = await createOctokitClient(account);
239218

240-
// Perform a generic GET request using Octokit's request method
241-
const response = await octokit.request('GET {+url}', {
242-
url: url,
243-
});
219+
// Perform a generic GET request using Octokit's request method
220+
const response = await octokit.request('GET {+url}', {
221+
url: url,
222+
});
244223

245-
return response.data as TResult;
224+
return response.data as TResult;
225+
246226
}
247227

248228
/**
@@ -253,9 +233,10 @@ export async function fetchAuthenticatedUserDetails(
253233
): Promise<OctokitResponse<GetAuthenticatedUserResponse>> {
254234
const octokit = await createOctokitClient(account);
255235

256-
const response = await octokit.rest.users.getAuthenticated();
236+
const response = await octokit.rest.users.getAuthenticated();
257237

258-
return response;
238+
return response;
239+
259240
}
260241

261242
/**

0 commit comments

Comments
 (0)