Skip to content

Commit

Permalink
refactor: Rename fine-grained permission functions for clarity and co…
Browse files Browse the repository at this point in the history
…nsistency
  • Loading branch information
mamertofabian committed Jan 22, 2025
1 parent 8bc8ead commit fe7efc6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
30 changes: 14 additions & 16 deletions src/lib/components/GitHubSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
}
}
async function checkFineGrainedPermissions() {
async function checkTokenPermissions() {
if (!githubToken || isCheckingPermissions) return;
isCheckingPermissions = true;
Expand All @@ -218,7 +218,7 @@
try {
const githubService = new GitHubService(githubToken);
const result = await githubService.verifyFineGrainedPermissions(
const result = await githubService.verifyTokenPermissions(
repoOwner,
({ permission, isValid }) => {
currentCheck = permission;
Expand Down Expand Up @@ -264,18 +264,16 @@
const handleSave = async (event: Event) => {
event.preventDefault();
if (tokenType === 'fine-grained') {
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
const needsCheck =
previousToken !== githubToken ||
!lastPermissionCheck ||
Date.now() - lastPermissionCheck > THIRTY_DAYS;
if (needsCheck) {
await checkFineGrainedPermissions();
if (permissionError) {
return; // Don't proceed if permissions check failed
}
const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000;
const needsCheck =
previousToken !== githubToken ||
!lastPermissionCheck ||
Date.now() - lastPermissionCheck > THIRTY_DAYS;
if (needsCheck) {
await checkTokenPermissions();
if (permissionError) {
return; // Don't proceed if permissions check failed
}
}
Expand Down Expand Up @@ -329,14 +327,14 @@
<p class="text-sm text-emerald-400">
{tokenType === 'classic' ? '🔑 Classic' : '✨ Fine-grained'} token detected
</p>
{#if tokenType === 'fine-grained' && isTokenValid}
{#if isTokenValid}
<div class="flex items-center gap-2">
<Button
type="button"
variant="outline"
size="sm"
class="text-xs"
on:click={checkFineGrainedPermissions}
on:click={checkTokenPermissions}
disabled={isCheckingPermissions}
>
{#if isCheckingPermissions}
Expand Down
4 changes: 2 additions & 2 deletions src/services/GitHubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export class GitHubService extends BaseGitHubService {
return this.tokenValidator.validateTokenAndUser(username);
}

async verifyFineGrainedPermissions(
async verifyTokenPermissions(
username: string,
onProgress?: ProgressCallback
): Promise<{ isValid: boolean; error?: string }> {
return this.tokenValidator.verifyFineGrainedPermissions(username, onProgress);
return this.tokenValidator.verifyTokenPermissions(username, onProgress);
}

async repoExists(owner: string, repo: string): Promise<boolean> {
Expand Down
6 changes: 1 addition & 5 deletions src/services/GitHubTokenValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ export class GitHubTokenValidator extends BaseGitHubService {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async verifyFineGrainedPermissions(
async verifyTokenPermissions(
username: string,
onProgress?: ProgressCallback
): Promise<{ isValid: boolean; error?: string }> {
if (!this.isFineGrainedToken()) {
return { isValid: false, error: 'Not a fine-grained token' };
}

try {
// Create a temporary test repo
const timestamp = Date.now();
Expand Down

0 comments on commit fe7efc6

Please sign in to comment.