Skip to content

Commit fe7efc6

Browse files
committed
refactor: Rename fine-grained permission functions for clarity and consistency
1 parent 8bc8ead commit fe7efc6

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/lib/components/GitHubSettings.svelte

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
}
205205
}
206206
207-
async function checkFineGrainedPermissions() {
207+
async function checkTokenPermissions() {
208208
if (!githubToken || isCheckingPermissions) return;
209209
210210
isCheckingPermissions = true;
@@ -218,7 +218,7 @@
218218
try {
219219
const githubService = new GitHubService(githubToken);
220220
221-
const result = await githubService.verifyFineGrainedPermissions(
221+
const result = await githubService.verifyTokenPermissions(
222222
repoOwner,
223223
({ permission, isValid }) => {
224224
currentCheck = permission;
@@ -264,18 +264,16 @@
264264
const handleSave = async (event: Event) => {
265265
event.preventDefault();
266266
267-
if (tokenType === 'fine-grained') {
268-
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
269-
const needsCheck =
270-
previousToken !== githubToken ||
271-
!lastPermissionCheck ||
272-
Date.now() - lastPermissionCheck > THIRTY_DAYS;
273-
274-
if (needsCheck) {
275-
await checkFineGrainedPermissions();
276-
if (permissionError) {
277-
return; // Don't proceed if permissions check failed
278-
}
267+
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
268+
const needsCheck =
269+
previousToken !== githubToken ||
270+
!lastPermissionCheck ||
271+
Date.now() - lastPermissionCheck > THIRTY_DAYS;
272+
273+
if (needsCheck) {
274+
await checkTokenPermissions();
275+
if (permissionError) {
276+
return; // Don't proceed if permissions check failed
279277
}
280278
}
281279
@@ -329,14 +327,14 @@
329327
<p class="text-sm text-emerald-400">
330328
{tokenType === 'classic' ? '🔑 Classic' : '✨ Fine-grained'} token detected
331329
</p>
332-
{#if tokenType === 'fine-grained' && isTokenValid}
330+
{#if isTokenValid}
333331
<div class="flex items-center gap-2">
334332
<Button
335333
type="button"
336334
variant="outline"
337335
size="sm"
338336
class="text-xs"
339-
on:click={checkFineGrainedPermissions}
337+
on:click={checkTokenPermissions}
340338
disabled={isCheckingPermissions}
341339
>
342340
{#if isCheckingPermissions}

src/services/GitHubService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export class GitHubService extends BaseGitHubService {
5252
return this.tokenValidator.validateTokenAndUser(username);
5353
}
5454

55-
async verifyFineGrainedPermissions(
55+
async verifyTokenPermissions(
5656
username: string,
5757
onProgress?: ProgressCallback
5858
): Promise<{ isValid: boolean; error?: string }> {
59-
return this.tokenValidator.verifyFineGrainedPermissions(username, onProgress);
59+
return this.tokenValidator.verifyTokenPermissions(username, onProgress);
6060
}
6161

6262
async repoExists(owner: string, repo: string): Promise<boolean> {

src/services/GitHubTokenValidator.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ export class GitHubTokenValidator extends BaseGitHubService {
2323
return new Promise((resolve) => setTimeout(resolve, ms));
2424
}
2525

26-
async verifyFineGrainedPermissions(
26+
async verifyTokenPermissions(
2727
username: string,
2828
onProgress?: ProgressCallback
2929
): Promise<{ isValid: boolean; error?: string }> {
30-
if (!this.isFineGrainedToken()) {
31-
return { isValid: false, error: 'Not a fine-grained token' };
32-
}
33-
3430
try {
3531
// Create a temporary test repo
3632
const timestamp = Date.now();

0 commit comments

Comments
 (0)