mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Fix Add button height in git settings
This commit is contained in:
8 files changed
+6
-85
No files matched your search
@@ -68,7 +68,6 @@ describe('GitSettingsProvider', () => {
|
||||
const { readGitSettings } = await import('@/lib/configUtils');
|
||||
vi.mocked(readGitSettings).mockResolvedValue({
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -185,7 +184,6 @@ describe('GitSettingsProvider', () => {
|
||||
password: 'gitlab-token',
|
||||
},
|
||||
},
|
||||
hostTokens: {},
|
||||
};
|
||||
|
||||
const { readGitSettings } = await import('@/lib/configUtils');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactNode, useState, useEffect } from 'react';
|
||||
import { GitSettingsContext, type GitSettings, type GitCredential, type GitHostToken, type GitSettingsContextType } from '@/contexts/GitSettingsContext';
|
||||
import { GitSettingsContext, type GitSettings, type GitCredential, type GitSettingsContextType } from '@/contexts/GitSettingsContext';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { readGitSettings, writeGitSettings } from '@/lib/configUtils';
|
||||
@@ -10,7 +10,6 @@ interface GitSettingsProviderProps {
|
||||
|
||||
const DEFAULT_SETTINGS: GitSettings = {
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
};
|
||||
|
||||
export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
||||
@@ -88,39 +87,6 @@ export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
||||
}));
|
||||
};
|
||||
|
||||
const addHostToken = (host: string, token: GitHostToken) => {
|
||||
setSettings(prev => ({
|
||||
...prev,
|
||||
hostTokens: {
|
||||
...prev.hostTokens,
|
||||
[host]: token,
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const removeHostToken = (host: string) => {
|
||||
setSettings(prev => {
|
||||
const { [host]: removed, ...rest } = prev.hostTokens;
|
||||
return {
|
||||
...prev,
|
||||
hostTokens: rest,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const updateHostToken = (host: string, token: Partial<GitHostToken>) => {
|
||||
setSettings(prev => ({
|
||||
...prev,
|
||||
hostTokens: {
|
||||
...prev.hostTokens,
|
||||
[host]: {
|
||||
...prev.hostTokens[host],
|
||||
...token,
|
||||
},
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
const isConfigured = Object.entries(settings.credentials).length > 0;
|
||||
|
||||
const contextValue: GitSettingsContextType = {
|
||||
@@ -129,9 +95,6 @@ export function GitSettingsProvider({ children }: GitSettingsProviderProps) {
|
||||
addCredential,
|
||||
removeCredential,
|
||||
updateCredential,
|
||||
addHostToken,
|
||||
removeHostToken,
|
||||
updateHostToken,
|
||||
isConfigured,
|
||||
isInitialized,
|
||||
};
|
||||
|
||||
@@ -5,16 +5,8 @@ export interface GitCredential {
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface GitHostToken {
|
||||
token: string;
|
||||
username?: string;
|
||||
scopes?: string[];
|
||||
createdAt?: number;
|
||||
}
|
||||
|
||||
export interface GitSettings {
|
||||
credentials: Record<string, GitCredential>; // keyed by origin
|
||||
hostTokens: Record<string, GitHostToken>; // keyed by host domain (e.g., 'github.com')
|
||||
name?: string;
|
||||
email?: string;
|
||||
coAuthorEnabled?: boolean;
|
||||
@@ -26,9 +18,6 @@ export interface GitSettingsContextType {
|
||||
addCredential: (origin: string, credential: GitCredential) => void;
|
||||
removeCredential: (origin: string) => void;
|
||||
updateCredential: (origin: string, credential: Partial<GitCredential>) => void;
|
||||
addHostToken: (host: string, token: GitHostToken) => void;
|
||||
removeHostToken: (host: string) => void;
|
||||
updateHostToken: (host: string, token: Partial<GitHostToken>) => void;
|
||||
isConfigured: boolean;
|
||||
isInitialized: boolean;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useCallback } from 'react';
|
||||
import { useOAuth, type OAuthConfig, type OAuthResult } from './useOAuth';
|
||||
import { useGitSettings } from './useGitSettings';
|
||||
import { proxyUrl } from '@/lib/proxyUrl';
|
||||
import type { GitHostToken } from '@/contexts/GitSettingsContext';
|
||||
|
||||
interface GitHubUserInfo {
|
||||
login: string;
|
||||
@@ -18,7 +17,7 @@ interface GitHubUserInfo {
|
||||
* Uses the generic useOAuth hook with GitHub-specific configuration.
|
||||
*/
|
||||
export function useGitHubOAuth() {
|
||||
const { addCredential, addHostToken, isInitialized } = useGitSettings();
|
||||
const { addCredential, isInitialized } = useGitSettings();
|
||||
|
||||
// GitHub OAuth configuration
|
||||
const config: OAuthConfig = {
|
||||
@@ -71,23 +70,14 @@ export function useGitHubOAuth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the credentials (legacy format for existing push/pull operations)
|
||||
// Store the credentials
|
||||
addCredential('https://github.com', {
|
||||
username: result.username || 'git',
|
||||
password: result.accessToken,
|
||||
});
|
||||
|
||||
// Also store as host token for PR/contribution operations
|
||||
const hostToken: GitHostToken = {
|
||||
token: result.accessToken,
|
||||
username: result.username || 'git',
|
||||
scopes: result.scopes || [],
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
addHostToken('github.com', hostToken);
|
||||
|
||||
return true;
|
||||
}, [oauth, addCredential, addHostToken, isInitialized]);
|
||||
}, [oauth, addCredential, isInitialized]);
|
||||
|
||||
return {
|
||||
...oauth,
|
||||
|
||||
@@ -161,7 +161,6 @@ describe('configUtils', () => {
|
||||
password: 'token123',
|
||||
},
|
||||
},
|
||||
hostTokens: {},
|
||||
};
|
||||
|
||||
describe('readGitSettings', () => {
|
||||
@@ -182,7 +181,6 @@ describe('configUtils', () => {
|
||||
|
||||
expect(result).toEqual({
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
coAuthorEnabled: true,
|
||||
});
|
||||
});
|
||||
|
||||
+1
-15
@@ -62,16 +62,8 @@ const gitCredentialSchema = z.object({
|
||||
password: z.string(),
|
||||
});
|
||||
|
||||
const gitHostTokenSchema = z.object({
|
||||
token: z.string(),
|
||||
username: z.string().optional(),
|
||||
scopes: z.array(z.string()).optional(),
|
||||
createdAt: z.number().optional(),
|
||||
});
|
||||
|
||||
const gitSettingsSchema = z.object({
|
||||
credentials: z.record(z.string(), gitCredentialSchema),
|
||||
hostTokens: z.record(z.string(), gitHostTokenSchema).optional(),
|
||||
name: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
coAuthorEnabled: z.boolean().optional(),
|
||||
@@ -220,7 +212,6 @@ export async function writeAISettings(fs: JSRuntimeFS, settings: AISettings, con
|
||||
export async function readGitSettings(fs: JSRuntimeFS, configPath = '/config'): Promise<GitSettings> {
|
||||
const defaultSettings: GitSettings = {
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
coAuthorEnabled: true,
|
||||
};
|
||||
|
||||
@@ -229,12 +220,7 @@ export async function readGitSettings(fs: JSRuntimeFS, configPath = '/config'):
|
||||
const gitConfigPath = getGitConfigPath(configPath);
|
||||
const content = await fs.readFile(gitConfigPath, 'utf8');
|
||||
const data = JSON.parse(content);
|
||||
const parsed = gitSettingsSchema.parse(data);
|
||||
// Ensure hostTokens exists even if not in parsed data
|
||||
return {
|
||||
...parsed,
|
||||
hostTokens: parsed.hostTokens || {},
|
||||
};
|
||||
return gitSettingsSchema.parse(data);
|
||||
} catch {
|
||||
return defaultSettings;
|
||||
}
|
||||
|
||||
@@ -306,7 +306,6 @@ describe('Git', () => {
|
||||
const { readGitSettings } = await import('./configUtils');
|
||||
vi.mocked(readGitSettings).mockResolvedValue({
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
coAuthorEnabled: true,
|
||||
});
|
||||
|
||||
@@ -334,7 +333,6 @@ describe('Git', () => {
|
||||
const { readGitSettings } = await import('./configUtils');
|
||||
vi.mocked(readGitSettings).mockResolvedValue({
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
coAuthorEnabled: true,
|
||||
@@ -364,7 +362,6 @@ describe('Git', () => {
|
||||
const { readGitSettings } = await import('./configUtils');
|
||||
vi.mocked(readGitSettings).mockResolvedValue({
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
coAuthorEnabled: false,
|
||||
@@ -394,7 +391,6 @@ describe('Git', () => {
|
||||
const { readGitSettings } = await import('./configUtils');
|
||||
vi.mocked(readGitSettings).mockResolvedValue({
|
||||
credentials: {},
|
||||
hostTokens: {},
|
||||
name: 'John Doe',
|
||||
email: '[email protected]',
|
||||
coAuthorEnabled: true,
|
||||
|
||||
@@ -319,6 +319,7 @@ export function GitSettings() {
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={!presetTokens[preset.id]?.trim()}
|
||||
size="sm"
|
||||
className="h-10"
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user