Fix TypeScript errors in nostr-git-support branch

- Fix duplicate useState import in GitManagementDialog
- Add missing hostTokens property to GitSettings in all test files
- Fix type narrowing issues in PullRequestDialog with proper type assertions
- Fix fetch headers to use Record<string, string> type
- Fix credentials type to GitCredential | undefined instead of null
- Fix auth callback to handle undefined credentials
- Fix patchLines array type annotation
- Fix git statusMatrix workdir type assertions
- All TypeScript compilation errors resolved
This commit is contained in:
shakespeare.diy committed 2025-10-15 01:29:04 -05:00
1 parent 865a7b83b8
commit 6ec4f7319c
6 files changed
+25 -17

No files matched your search

@@ -68,6 +68,7 @@ describe('GitSettingsProvider', () => {
const { readGitSettings } = await import('@/lib/configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
hostTokens: {},
});
});
@@ -183,6 +184,7 @@ describe('GitSettingsProvider', () => {
password: 'gitlab-token',
},
},
hostTokens: {},
};
const { readGitSettings } = await import('@/lib/configUtils');
+1 -2
View File
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import {
Dialog,
DialogContent,
@@ -20,7 +20,6 @@ import { DiffViewer } from './DiffViewer';
import { PullRequestForm } from './PullRequestForm';
import { useGitStatus } from '@/hooks/useGitStatus';
import { useGit } from '@/hooks/useGit';
import { useState, useEffect } from 'react';
interface GitManagementDialogProps {
projectId: string;
+15 -13
View File
@@ -40,6 +40,7 @@ import { useAppContext } from '@/hooks/useAppContext';
import { findCredentialsForRepo } from '@/lib/gitCredentials';
import { createGitHostProvider, detectGitHost, parseRepoUrl } from '@/lib/git-hosts';
import { nip19 } from 'nostr-tools';
import type { GitCredential } from '@/contexts/GitSettingsContext';
interface PullRequestDialogProps {
projectId: string;
@@ -218,7 +219,7 @@ export function PullRequestDialog({
try {
const decoded = nip19.decode(pubkeyOrNpub);
if (decoded.type === 'npub') {
owner = decoded.data; // hex pubkey
owner = decoded.data as string; // hex pubkey
} else {
throw new Error('Invalid npub');
}
@@ -365,9 +366,9 @@ export function PullRequestDialog({
// Stage all changes
for (const [filepath, , workdir] of statusMatrix) {
if (workdir === 0) {
if ((workdir as number) === 0) {
await git.remove({ dir: projectPath, filepath });
} else if (workdir !== 0) {
} else if ((workdir as number) !== 0) {
await git.add({ dir: projectPath, filepath });
}
}
@@ -406,7 +407,7 @@ export function PullRequestDialog({
}
// Get credentials (not needed for Nostr git)
let credentials = null;
let credentials: GitCredential | undefined = undefined;
if (remoteInfo.platform !== 'nostr') {
credentials = findCredentialsForRepo(remoteUrl || '', settings.credentials);
@@ -424,7 +425,8 @@ export function PullRequestDialog({
);
}
if (!credentials.password || credentials.password.trim() === '') {
const password = credentials.password;
if (!password || password.trim() === '') {
throw new Error(
`Credentials found but token is empty. Please check your ${remoteInfo.platform === 'github' ? 'GitHub' : 'GitLab'} token in Settings > Git`
);
@@ -490,7 +492,7 @@ export function PullRequestDialog({
dir: projectPath,
remote: pushRemote,
ref: branchToUse,
onAuth: () => credentials,
onAuth: credentials ? () => credentials : undefined,
});
console.log('Successfully pushed to fork');
} catch (pushError) {
@@ -511,10 +513,10 @@ export function PullRequestDialog({
// Create PR based on platform
console.log(`Creating ${remoteInfo.platform} PR...`);
if (remoteInfo.platform === 'github' && credentials) {
const prUrl = await createGitHubPR(remoteInfo, credentials.password, headRef);
const prUrl = await createGitHubPR(remoteInfo, credentials.password || '', headRef);
setCreatedPrUrl(prUrl);
} else if (remoteInfo.platform === 'gitlab' && credentials) {
const prUrl = await createGitLabMR(remoteInfo, credentials.password);
const prUrl = await createGitLabMR(remoteInfo, credentials.password || '');
setCreatedPrUrl(prUrl);
} else if (remoteInfo.platform === 'nostr') {
const prUrl = await createNostrPatch(remoteInfo, branchToUse, targetBranch);
@@ -546,7 +548,7 @@ export function PullRequestDialog({
? `${info.apiUrl}/repos/${info.owner}/${info.repo}`
: `${info.apiUrl}/projects/${encodeURIComponent(`${info.owner}/${info.repo}`)}`;
const headers = info.platform === 'github'
const headers: Record<string, string> = info.platform === 'github'
? { 'Authorization': `token ${token}`, 'Accept': 'application/vnd.github.v3+json' }
: { 'PRIVATE-TOKEN': token };
@@ -596,7 +598,7 @@ export function PullRequestDialog({
const getCurrentUser = async (info: RemoteInfo, token: string): Promise<{ username: string }> => {
const url = info.platform === 'github' ? `${info.apiUrl}/user` : `${info.apiUrl}/user`;
const headers = info.platform === 'github'
const headers: Record<string, string> = info.platform === 'github'
? { 'Authorization': `token ${token}` }
: { 'PRIVATE-TOKEN': token };
@@ -617,7 +619,7 @@ export function PullRequestDialog({
? `${info.apiUrl}/repos/${username}/${info.repo}`
: `${info.apiUrl}/projects/${encodeURIComponent(`${username}/${info.repo}`)}`;
const headers = info.platform === 'github'
const headers: Record<string, string> = info.platform === 'github'
? { 'Authorization': `token ${token}` }
: { 'PRIVATE-TOKEN': token };
@@ -649,7 +651,7 @@ export function PullRequestDialog({
? `${info.apiUrl}/repos/${info.owner}/${info.repo}/forks`
: `${info.apiUrl}/projects/${encodeURIComponent(`${info.owner}/${info.repo}`)}/fork`;
const headers = info.platform === 'github'
const headers: Record<string, string> = info.platform === 'github'
? { 'Authorization': `token ${token}`, 'Content-Type': 'application/json' }
: { 'PRIVATE-TOKEN': token, 'Content-Type': 'application/json' };
@@ -846,7 +848,7 @@ export function PullRequestDialog({
}
// Build patch content following git format-patch format
const patchLines = [];
const patchLines: string[] = [];
patchLines.push(`From ${currentCommitId} Mon Sep 17 00:00:00 2001`);
patchLines.push(`From: ${commit.commit.author.name} <${commit.commit.author.email}>`);
patchLines.push(`Date: ${new Date(commit.commit.author.timestamp * 1000).toUTCString()}`);
+2 -2
View File
@@ -225,9 +225,9 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
console.log('Committing changes to new branch');
for (const [filepath, , workdir] of statusMatrix) {
if (workdir === 0) {
if ((workdir as number) === 0) {
await git.remove({ dir: projectPath, filepath });
} else if (workdir !== 0) {
} else if ((workdir as number) !== 0) {
await git.add({ dir: projectPath, filepath });
}
}
+1
View File
@@ -144,6 +144,7 @@ describe('configUtils', () => {
password: 'token123',
},
},
hostTokens: {},
};
describe('readGitSettings', () => {
+4
View File
@@ -306,6 +306,7 @@ describe('Git', () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
hostTokens: {},
coAuthorEnabled: true,
});
@@ -333,6 +334,7 @@ describe('Git', () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
hostTokens: {},
name: 'John Doe',
email: '[email protected]',
coAuthorEnabled: true,
@@ -362,6 +364,7 @@ describe('Git', () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
hostTokens: {},
name: 'John Doe',
email: '[email protected]',
coAuthorEnabled: false,
@@ -391,6 +394,7 @@ describe('Git', () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
hostTokens: {},
name: 'John Doe',
email: '[email protected]',
coAuthorEnabled: true,