From 8c125db804c500e77c82009151210fc2acb5efd8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 15 Oct 2025 12:01:32 -0500 Subject: [PATCH] Fix linter errors --- .../git/AnnounceRepositoryDialog.tsx | 18 +++--- src/components/git/PullRequestDialog.tsx | 56 +++++++++---------- src/components/git/PullRequestForm.tsx | 5 +- src/hooks/usePullRequests.ts | 12 +++- src/lib/configUtils.test.ts | 1 + src/lib/git-hosts/GitHubProvider.ts | 5 +- src/lib/git-hosts/GitLabProvider.ts | 41 +++++++------- src/lib/git-hosts/GiteaProvider.ts | 2 +- src/lib/git-hosts/NostrGitProvider.ts | 8 +-- src/lib/git-hosts/index.ts | 3 +- 10 files changed, 79 insertions(+), 72 deletions(-) diff --git a/src/components/git/AnnounceRepositoryDialog.tsx b/src/components/git/AnnounceRepositoryDialog.tsx index 29028dda..a2f3a2f0 100644 --- a/src/components/git/AnnounceRepositoryDialog.tsx +++ b/src/components/git/AnnounceRepositoryDialog.tsx @@ -71,15 +71,6 @@ export function AnnounceRepositoryDialog({ } }, [open]); - useEffect(() => { - if (isOpen && remoteUrl) { - // Parse remote URL to pre-fill data - parseRemoteUrl(remoteUrl); - // Get earliest commit - getEarliestCommit(); - } - }, [isOpen, remoteUrl, parseRemoteUrl, getEarliestCommit]); - const parseRemoteUrl = useCallback((url: string) => { // Extract repo ID from Nostr URL if (url.startsWith('nostr://')) { @@ -114,6 +105,15 @@ export function AnnounceRepositoryDialog({ } }, [git, projectPath]); + useEffect(() => { + if (isOpen && remoteUrl) { + // Parse remote URL to pre-fill data + parseRemoteUrl(remoteUrl); + // Get earliest commit + getEarliestCommit(); + } + }, [isOpen, remoteUrl, parseRemoteUrl, getEarliestCommit]); + const addWebUrl = () => { if (newWebUrl.trim() && !webUrls.includes(newWebUrl.trim())) { setWebUrls([...webUrls, newWebUrl.trim()]); diff --git a/src/components/git/PullRequestDialog.tsx b/src/components/git/PullRequestDialog.tsx index 719ed4b1..ee07a558 100644 --- a/src/components/git/PullRequestDialog.tsx +++ b/src/components/git/PullRequestDialog.tsx @@ -141,6 +141,33 @@ export function PullRequestDialog({ return; } + const ensureFork = async (info: RemoteInfo, token: string): Promise<{ owner: string; repo: string; url: string }> => { + console.log('=== ENSURE FORK ==='); + console.log('Repository:', `${info.owner}/${info.repo}`); + + // First check if fork already exists + const user = await getCurrentUser(info, token); + console.log('Current user:', user.username); + + const existingFork = await checkForkExists(info, token, user.username); + + if (existingFork) { + console.log('Found existing fork:', existingFork); + return existingFork; + } + + // Create fork + console.log('No existing fork found, creating new fork...'); + const fork = await createFork(info, token); + console.log('Fork created:', fork); + + // Wait a bit for fork to be ready + console.log('Waiting 2 seconds for fork to be ready...'); + await new Promise(resolve => setTimeout(resolve, 2000)); + + return fork; + }; + setIsCheckingPermissions(true); try { const credentials = findCredentialsForRepo(remoteUrl, settings.credentials); @@ -178,7 +205,7 @@ export function PullRequestDialog({ } finally { setIsCheckingPermissions(false); } - }, [remoteInfo, remoteUrl, settings.credentials, ensureFork]); + }, [remoteInfo, remoteUrl, settings.credentials]); useEffect(() => { if (isOpen && remoteUrl) { @@ -569,33 +596,6 @@ export function PullRequestDialog({ } }; - const ensureFork = async (info: RemoteInfo, token: string): Promise<{ owner: string; repo: string; url: string }> => { - console.log('=== ENSURE FORK ==='); - console.log('Repository:', `${info.owner}/${info.repo}`); - - // First check if fork already exists - const user = await getCurrentUser(info, token); - console.log('Current user:', user.username); - - const existingFork = await checkForkExists(info, token, user.username); - - if (existingFork) { - console.log('Found existing fork:', existingFork); - return existingFork; - } - - // Create fork - console.log('No existing fork found, creating new fork...'); - const fork = await createFork(info, token); - console.log('Fork created:', fork); - - // Wait a bit for fork to be ready - console.log('Waiting 2 seconds for fork to be ready...'); - await new Promise(resolve => setTimeout(resolve, 2000)); - - return fork; - }; - const getCurrentUser = async (info: RemoteInfo, token: string): Promise<{ username: string }> => { const url = info.platform === 'github' ? `${info.apiUrl}/user` : `${info.apiUrl}/user`; const headers: Record = info.platform === 'github' diff --git a/src/components/git/PullRequestForm.tsx b/src/components/git/PullRequestForm.tsx index c070175e..cf290825 100644 --- a/src/components/git/PullRequestForm.tsx +++ b/src/components/git/PullRequestForm.tsx @@ -106,13 +106,12 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq } else { setError('Unsupported remote URL format'); } - } catch (err) { + } catch { setError('Failed to parse remote URL'); } }, []); const loadRemoteBranches = useCallback(async () => { - setIsLoadingBranches(true); try { const branches = await git.listBranches({ dir: projectPath, @@ -129,8 +128,6 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq } } catch { setRemoteBranches(['main', 'master', 'develop']); - } finally { - setIsLoadingBranches(false); } }, [git, projectPath]); diff --git a/src/hooks/usePullRequests.ts b/src/hooks/usePullRequests.ts index b944e768..237f4c4e 100644 --- a/src/hooks/usePullRequests.ts +++ b/src/hooks/usePullRequests.ts @@ -260,7 +260,14 @@ async function fetchNostrPatches( try { // Build query filter based on whether user is repo owner or contributor - const filter: any = { + interface PatchFilter { + kinds: number[]; + '#a': string[]; + limit: number; + authors?: string[]; + } + + const filter: PatchFilter = { kinds: [1617], '#a': [`30617:${info.owner}:${info.repo}`], limit: 50, @@ -286,12 +293,13 @@ async function fetchNostrPatches( let statusEvents: NostrEvent[] = []; if (patchIds.length > 0) { - statusEvents = await nostr.query([ + const events = await nostr.query([ { kinds: [1630, 1631, 1632, 1633], // Open, Applied/Merged, Closed, Draft '#e': patchIds, } ], { signal }); + statusEvents = events as NostrEvent[]; console.log(`Found ${statusEvents.length} status events`); } diff --git a/src/lib/configUtils.test.ts b/src/lib/configUtils.test.ts index d536b026..9ab3c3db 100644 --- a/src/lib/configUtils.test.ts +++ b/src/lib/configUtils.test.ts @@ -165,6 +165,7 @@ describe('configUtils', () => { expect(result).toEqual({ credentials: {}, + hostTokens: {}, coAuthorEnabled: true, }); }); diff --git a/src/lib/git-hosts/GitHubProvider.ts b/src/lib/git-hosts/GitHubProvider.ts index bd8c072c..40a01615 100644 --- a/src/lib/git-hosts/GitHubProvider.ts +++ b/src/lib/git-hosts/GitHubProvider.ts @@ -5,6 +5,7 @@ import type { GitRepository, GitFork, PullRequest, + PullRequestCheck, CreatePullRequestOptions, GitHostUser, } from './types'; @@ -274,7 +275,7 @@ export class GitHubProvider implements GitHostProvider { mergeable?: boolean; merged?: boolean; }): PullRequest { - const state = data.merged ? 'merged' : data.state; + const state: 'open' | 'closed' | 'merged' = data.merged ? 'merged' : data.state as 'open' | 'closed'; return { number: data.number, @@ -294,7 +295,7 @@ export class GitHubProvider implements GitHostProvider { }; } - private transformChecks(data: any): PullRequestCheck[] | undefined { + private transformChecks(_data: unknown): PullRequestCheck[] | undefined { // GitHub's check runs are in a separate API call, so we don't have them here // This would need a separate API call to /repos/{owner}/{repo}/commits/{ref}/check-runs return undefined; diff --git a/src/lib/git-hosts/GitLabProvider.ts b/src/lib/git-hosts/GitLabProvider.ts index f14a7be3..9934b9de 100644 --- a/src/lib/git-hosts/GitLabProvider.ts +++ b/src/lib/git-hosts/GitLabProvider.ts @@ -5,6 +5,7 @@ import type { GitRepository, GitFork, PullRequest, + PullRequestCheck, CreatePullRequestOptions, GitHostUser, } from './types'; @@ -25,6 +26,10 @@ interface GitLabMRResponse { target_project_id: number; merge_status?: string; merged_at?: string; + pipeline?: { + status: string; + web_url: string; + }; } export class GitLabProvider implements GitHostProvider { @@ -245,7 +250,7 @@ export class GitLabProvider implements GitHostProvider { async closePullRequest(owner: string, repo: string, number: number): Promise { const projectPath = this.encodeProjectPath(owner, repo); - const data = await this.fetch(`/projects/${projectPath}/merge_requests/${number}`, { + const data = await this.fetch(`/projects/${projectPath}/merge_requests/${number}`, { method: 'PUT', body: JSON.stringify({ state_event: 'close', @@ -278,23 +283,7 @@ export class GitLabProvider implements GitHostProvider { return `https://gitlab.com/${baseRepo}/-/merge_requests/new?merge_request[source_branch]=${headBranch}&merge_request[source_project]=${headOwner}/${headRepoName}&merge_request[target_branch]=${baseBranch}`; } - private transformMergeRequest(data: { - id: number; - iid: number; - state: string; - title: string; - description: string; - web_url: string; - created_at: string; - updated_at: string; - author: { username: string }; - source_branch: string; - target_branch: string; - source_project_id: number; - target_project_id: number; - merge_status?: string; - merged_at?: string; - }): PullRequest { + private transformMergeRequest(data: GitLabMRResponse): PullRequest { const state = data.state === 'merged' ? 'merged' : data.state === 'opened' ? 'open' : 'closed'; return { @@ -315,14 +304,24 @@ export class GitLabProvider implements GitHostProvider { }; } - private transformPipeline(data: any): PullRequestCheck[] | undefined { + private transformPipeline(data: GitLabMRResponse): PullRequestCheck[] | undefined { if (!data.pipeline) return undefined; + const mapConclusion = (status: string): PullRequestCheck['conclusion'] => { + switch (status) { + case 'success': return 'success'; + case 'failed': return 'failure'; + case 'canceled': return 'cancelled'; + case 'skipped': return 'skipped'; + default: return undefined; + } + }; + return [{ name: 'Pipeline', status: data.pipeline.status === 'running' ? 'pending' : - data.pipeline.status === 'success' ? 'success' : 'failure', - conclusion: data.pipeline.status, + data.pipeline.status === 'success' ? 'success' : 'failure', + conclusion: mapConclusion(data.pipeline.status), detailsUrl: data.pipeline.web_url, }]; } diff --git a/src/lib/git-hosts/GiteaProvider.ts b/src/lib/git-hosts/GiteaProvider.ts index 2a5c74dc..1da4b2ec 100644 --- a/src/lib/git-hosts/GiteaProvider.ts +++ b/src/lib/git-hosts/GiteaProvider.ts @@ -272,7 +272,7 @@ export class GiteaProvider implements GitHostProvider { mergeable?: boolean; merged?: boolean; }): PullRequest { - const state = data.merged ? 'merged' : data.state; + const state: 'open' | 'closed' | 'merged' = data.merged ? 'merged' : data.state as 'open' | 'closed'; return { number: data.number, diff --git a/src/lib/git-hosts/NostrGitProvider.ts b/src/lib/git-hosts/NostrGitProvider.ts index b4792581..4b814d63 100644 --- a/src/lib/git-hosts/NostrGitProvider.ts +++ b/src/lib/git-hosts/NostrGitProvider.ts @@ -1,4 +1,4 @@ -import { NRelay1 } from '@nostrify/nostrify'; +import { NRelay1, type NostrEvent } from '@nostrify/nostrify'; import type { GitHostProvider, GitHostConfig, @@ -10,7 +10,7 @@ import type { } from './types'; interface NostrSigner { - signEvent: (event: { kind: number; content: string; tags: string[][]; created_at: number }) => Promise; + signEvent: (event: { kind: number; content: string; tags: string[][]; created_at: number }) => Promise; } /** @@ -36,7 +36,7 @@ export class NostrGitProvider implements GitHostProvider { this.relay = new NRelay1('wss://relay.nostr.band'); // Default, will be changed } - private async queryRepo(owner: string, repo: string): Promise<{ tags: string[][]; content: string }> { + private async queryRepo(owner: string, repo: string): Promise { // Query for repository announcement (kind 30617) // d tag is the repo-id (usually kebab-case short name) const events = await this.relay.query([ @@ -46,7 +46,7 @@ export class NostrGitProvider implements GitHostProvider { '#d': [repo], // repo is the d tag identifier limit: 1, } - ]); + ]) as NostrEvent[]; if (events.length === 0) { throw new Error(`Repository not found: ${owner}/${repo}`); diff --git a/src/lib/git-hosts/index.ts b/src/lib/git-hosts/index.ts index 55155ae0..ef200559 100644 --- a/src/lib/git-hosts/index.ts +++ b/src/lib/git-hosts/index.ts @@ -10,12 +10,13 @@ import { GiteaProvider } from './GiteaProvider'; import { NostrGitProvider } from './NostrGitProvider'; import { detectGitHost } from './types'; import type { GitHostProvider, GitHostConfig } from './types'; +import type { NostrEvent } from '@nostrify/nostrify'; /** * Create a Git host provider instance based on the repository URL */ interface NostrSigner { - signEvent: (event: { kind: number; content: string; tags: string[][]; created_at: number }) => Promise; + signEvent: (event: { kind: number; content: string; tags: string[][]; created_at: number }) => Promise; } export function createGitHostProvider(