mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Fix all linting and type errors
- Remove unused imports (Badge, PullRequestCheck) - Fix React Hook dependency warnings by using useCallback - Replace 'any' types with proper TypeScript interfaces - Fix unused variable errors by prefixing with underscore - Remove placeholder comments - Consolidate duplicate type definitions at module level - Add proper type definitions for API responses - Fix const vs let issues
This commit is contained in:
1 parent
67aea6a3b2
commit
1c4b1e6263
11 files changed
+343
-96
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
} from '@/components/ui/dialog';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import {
|
||||
GitBranch,
|
||||
Loader2,
|
||||
@@ -79,9 +78,9 @@ export function AnnounceRepositoryDialog({
|
||||
// Get earliest commit
|
||||
getEarliestCommit();
|
||||
}
|
||||
}, [isOpen, remoteUrl]);
|
||||
}, [isOpen, remoteUrl, parseRemoteUrl, getEarliestCommit]);
|
||||
|
||||
const parseRemoteUrl = (url: string) => {
|
||||
const parseRemoteUrl = useCallback((url: string) => {
|
||||
// Extract repo ID from Nostr URL
|
||||
if (url.startsWith('nostr://')) {
|
||||
const match = url.match(/^nostr:\/\/[^/]+\/(.+)$/);
|
||||
@@ -96,9 +95,9 @@ export function AnnounceRepositoryDialog({
|
||||
if (url && !cloneUrls.includes(url)) {
|
||||
setCloneUrls([url]);
|
||||
}
|
||||
};
|
||||
}, [cloneUrls]);
|
||||
|
||||
const getEarliestCommit = async () => {
|
||||
const getEarliestCommit = useCallback(async () => {
|
||||
try {
|
||||
const commits = await git.log({
|
||||
dir: projectPath,
|
||||
@@ -113,7 +112,7 @@ export function AnnounceRepositoryDialog({
|
||||
} catch (err) {
|
||||
console.warn('Failed to get earliest commit:', err);
|
||||
}
|
||||
};
|
||||
}, [git, projectPath]);
|
||||
|
||||
const addWebUrl = () => {
|
||||
if (newWebUrl.trim() && !webUrls.includes(newWebUrl.trim())) {
|
||||
|
||||
@@ -61,7 +61,7 @@ export function MergeDialog({
|
||||
projectId,
|
||||
currentBranch,
|
||||
sourceBranch: initialSourceBranch,
|
||||
targetBranch: initialTargetBranch,
|
||||
targetBranch: _initialTargetBranch,
|
||||
open,
|
||||
onOpenChange,
|
||||
onMergeComplete,
|
||||
|
||||
@@ -38,7 +38,6 @@ import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useNostr } from '@/hooks/useNostr';
|
||||
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';
|
||||
|
||||
@@ -179,7 +178,7 @@ export function PullRequestDialog({
|
||||
} finally {
|
||||
setIsCheckingPermissions(false);
|
||||
}
|
||||
}, [remoteInfo, remoteUrl, settings.credentials]);
|
||||
}, [remoteInfo, remoteUrl, settings.credentials, ensureFork]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && remoteUrl) {
|
||||
@@ -211,7 +210,7 @@ export function PullRequestDialog({
|
||||
if (url.startsWith('nostr://')) {
|
||||
match = url.match(/^nostr:\/\/([^/]+)\/(.+)$/);
|
||||
if (match) {
|
||||
let pubkeyOrNpub = match[1];
|
||||
const pubkeyOrNpub = match[1];
|
||||
repo = match[2]; // repo-id (d tag)
|
||||
|
||||
// Convert npub to hex if needed
|
||||
@@ -827,7 +826,7 @@ export function PullRequestDialog({
|
||||
});
|
||||
baseRef = `origin/${baseBranch}`;
|
||||
console.log(`Using remote tracking branch: ${baseRef}`);
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Fall back to local branch if remote doesn't exist
|
||||
console.log(`Remote tracking branch origin/${baseBranch} not found, using local ${baseBranch}`);
|
||||
}
|
||||
@@ -1001,7 +1000,7 @@ export function PullRequestDialog({
|
||||
let errorMessage = error.message || `GitHub API error: ${response.status} - ${response.statusText}`;
|
||||
|
||||
if (error.errors && Array.isArray(error.errors)) {
|
||||
const errorDetails = error.errors.map((e: any) => {
|
||||
const errorDetails = error.errors.map((e: { message?: string; field?: string; code?: string }) => {
|
||||
if (e.message) return e.message;
|
||||
if (e.field && e.code) return `${e.field}: ${e.code}`;
|
||||
return JSON.stringify(e);
|
||||
|
||||
@@ -51,7 +51,6 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
const [description, setDescription] = useState('');
|
||||
const [targetBranch, setTargetBranch] = useState('main');
|
||||
const [remoteBranches, setRemoteBranches] = useState<string[]>([]);
|
||||
const [isLoadingBranches, setIsLoadingBranches] = useState(false);
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const [remoteInfo, setRemoteInfo] = useState<RemoteInfo | null>(null);
|
||||
const [forkInfo, setForkInfo] = useState<ForkInfo>({ needsFork: false });
|
||||
@@ -68,15 +67,7 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
// (parseRemoteUrl, checkPushPermissions, ensureFork, etc.)
|
||||
// For brevity, I'll import them or duplicate the core logic
|
||||
|
||||
useEffect(() => {
|
||||
if (remoteUrl) {
|
||||
parseRemoteUrl(remoteUrl);
|
||||
loadRemoteBranches();
|
||||
checkPermissionsAndFork();
|
||||
}
|
||||
}, [remoteUrl]);
|
||||
|
||||
const parseRemoteUrl = (url: string) => {
|
||||
const parseRemoteUrl = useCallback((url: string) => {
|
||||
// Same implementation as PullRequestDialog
|
||||
setError(null);
|
||||
try {
|
||||
@@ -118,7 +109,7 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
} catch (err) {
|
||||
setError('Failed to parse remote URL');
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const loadRemoteBranches = useCallback(async () => {
|
||||
setIsLoadingBranches(true);
|
||||
@@ -164,6 +155,14 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
}
|
||||
}, [remoteInfo, remoteUrl, settings.credentials]);
|
||||
|
||||
useEffect(() => {
|
||||
if (remoteUrl) {
|
||||
parseRemoteUrl(remoteUrl);
|
||||
loadRemoteBranches();
|
||||
checkPermissionsAndFork();
|
||||
}
|
||||
}, [remoteUrl, parseRemoteUrl, loadRemoteBranches, checkPermissionsAndFork]);
|
||||
|
||||
const createPullRequest = async () => {
|
||||
if (!remoteInfo || !currentBranch) return;
|
||||
|
||||
@@ -343,7 +342,7 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq
|
||||
let errorMessage = error.message || `API error: ${response.status} - ${response.statusText}`;
|
||||
|
||||
if (error.errors && Array.isArray(error.errors)) {
|
||||
const errorDetails = error.errors.map((e: any) => {
|
||||
const errorDetails = error.errors.map((e: { message?: string; field?: string; code?: string }) => {
|
||||
if (e.message) return e.message;
|
||||
if (e.field && e.code) return `${e.field}: ${e.code}`;
|
||||
return JSON.stringify(e);
|
||||
|
||||
@@ -193,7 +193,7 @@ export function useGitHubOAuth() {
|
||||
}));
|
||||
return false;
|
||||
}
|
||||
}, [addCredential, corsProxy]);
|
||||
}, [addCredential, addHostToken, corsProxy]);
|
||||
|
||||
return {
|
||||
...state,
|
||||
|
||||
@@ -33,7 +33,7 @@ function parseRemoteUrl(url: string): RemoteInfo | null {
|
||||
if (url.startsWith('nostr://')) {
|
||||
const match = url.match(/^nostr:\/\/([^/]+)\/(.+)$/);
|
||||
if (match) {
|
||||
let pubkeyOrNpub = match[1];
|
||||
const pubkeyOrNpub = match[1];
|
||||
const repo = match[2];
|
||||
|
||||
// Convert npub to hex if needed
|
||||
@@ -132,7 +132,20 @@ async function fetchGitHubPRs(info: RemoteInfo, token?: string, currentUsername?
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
const allPRs = data.map((pr: any) => ({
|
||||
interface GitHubPR {
|
||||
id: number;
|
||||
number: number;
|
||||
title: string;
|
||||
state: string;
|
||||
user: { login: string };
|
||||
html_url: string;
|
||||
created_at: string;
|
||||
head: { ref: string };
|
||||
base: { ref: string };
|
||||
body?: string;
|
||||
}
|
||||
|
||||
const allPRs = data.map((pr: GitHubPR) => ({
|
||||
id: pr.id,
|
||||
number: pr.number,
|
||||
title: pr.title,
|
||||
@@ -188,7 +201,20 @@ async function fetchGitLabMRs(info: RemoteInfo, token?: string, currentUsername?
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
const allMRs = data.map((mr: any) => ({
|
||||
interface GitLabMR {
|
||||
id: number;
|
||||
iid: number;
|
||||
title: string;
|
||||
state: string;
|
||||
author: { username: string };
|
||||
web_url: string;
|
||||
created_at: string;
|
||||
source_branch: string;
|
||||
target_branch: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
const allMRs = data.map((mr: GitLabMR) => ({
|
||||
id: mr.id,
|
||||
number: mr.iid,
|
||||
title: mr.title,
|
||||
@@ -211,10 +237,14 @@ async function fetchGitLabMRs(info: RemoteInfo, token?: string, currentUsername?
|
||||
return [];
|
||||
}
|
||||
|
||||
interface NostrInterface {
|
||||
query: (filters: unknown[], options?: { signal?: AbortSignal }) => Promise<unknown[]>;
|
||||
}
|
||||
|
||||
async function fetchNostrPatches(
|
||||
info: RemoteInfo,
|
||||
currentUserPubkey: string | undefined,
|
||||
nostr: any,
|
||||
nostr: NostrInterface,
|
||||
signal: AbortSignal,
|
||||
isRepoOwner?: boolean
|
||||
): Promise<PullRequest[]> {
|
||||
|
||||
@@ -7,9 +7,24 @@ import type {
|
||||
PullRequest,
|
||||
CreatePullRequestOptions,
|
||||
GitHostUser,
|
||||
PullRequestCheck,
|
||||
} from './types';
|
||||
|
||||
interface GitHubPRResponse {
|
||||
id: number;
|
||||
number: number;
|
||||
state: string;
|
||||
title: string;
|
||||
body: string;
|
||||
html_url: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
user: { login: string };
|
||||
head: { ref: string; repo: { full_name: string } };
|
||||
base: { ref: string; repo: { full_name: string } };
|
||||
mergeable?: boolean;
|
||||
merged?: boolean;
|
||||
}
|
||||
|
||||
export class GitHubProvider implements GitHostProvider {
|
||||
readonly name = 'GitHub';
|
||||
readonly apiBaseUrl = 'https://api.github.com';
|
||||
@@ -44,7 +59,18 @@ export class GitHubProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getRepository(owner: string, repo: string): Promise<GitRepository> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}`);
|
||||
interface GitHubRepo {
|
||||
owner: { login: string };
|
||||
name: string;
|
||||
full_name: string;
|
||||
default_branch: string;
|
||||
clone_url: string;
|
||||
html_url: string;
|
||||
description: string;
|
||||
private: boolean;
|
||||
}
|
||||
|
||||
const data = await this.fetch<GitHubRepo>(`/repos/${owner}/${repo}`);
|
||||
|
||||
return {
|
||||
owner: data.owner.login,
|
||||
@@ -60,33 +86,54 @@ export class GitHubProvider implements GitHostProvider {
|
||||
|
||||
async canUserPush(owner: string, repo: string): Promise<boolean> {
|
||||
try {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}`);
|
||||
interface GitHubRepoWithPermissions {
|
||||
permissions?: { push?: boolean; admin?: boolean };
|
||||
}
|
||||
|
||||
const data = await this.fetch<GitHubRepoWithPermissions>(`/repos/${owner}/${repo}`);
|
||||
return data.permissions?.push === true || data.permissions?.admin === true;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// If we can't check permissions, assume no push access
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async createFork(owner: string, repo: string): Promise<GitFork> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/forks`, {
|
||||
interface GitHubFork {
|
||||
owner: { login: string };
|
||||
name: string;
|
||||
clone_url: string;
|
||||
html_url: string;
|
||||
}
|
||||
|
||||
const data = await this.fetch<GitHubFork>(`/repos/${owner}/${repo}/forks`, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
return {
|
||||
owner: data.owner.login,
|
||||
name: data.name,
|
||||
fullName: data.full_name,
|
||||
fullName: `${data.owner.login}/${data.name}`,
|
||||
cloneUrl: data.clone_url,
|
||||
webUrl: data.html_url,
|
||||
parentFullName: data.parent.full_name,
|
||||
parentFullName: `${owner}/${repo}`,
|
||||
};
|
||||
}
|
||||
|
||||
async getFork(upstreamOwner: string, upstreamRepo: string, username: string): Promise<GitFork | null> {
|
||||
try {
|
||||
interface GitHubForkCheck {
|
||||
fork: boolean;
|
||||
owner: { login: string };
|
||||
name: string;
|
||||
full_name: string;
|
||||
clone_url: string;
|
||||
html_url: string;
|
||||
parent?: { full_name: string };
|
||||
}
|
||||
|
||||
// Check if the fork already exists
|
||||
const data = await this.fetch<any>(`/repos/${username}/${upstreamRepo}`);
|
||||
const data = await this.fetch<GitHubForkCheck>(`/repos/${username}/${upstreamRepo}`);
|
||||
|
||||
// Verify it's actually a fork of the upstream repo
|
||||
if (data.fork && data.parent?.full_name === `${upstreamOwner}/${upstreamRepo}`) {
|
||||
@@ -135,7 +182,7 @@ export class GitHubProvider implements GitHostProvider {
|
||||
? `${headOwner}:${options.headBranch}`
|
||||
: options.headBranch;
|
||||
|
||||
const data = await this.fetch<any>(`/repos/${baseOwner}/${baseRepo}/pulls`, {
|
||||
const data = await this.fetch<GitHubPRResponse>(`/repos/${baseOwner}/${baseRepo}/pulls`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -151,7 +198,7 @@ export class GitHubProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getPullRequest(owner: string, repo: string, number: number): Promise<PullRequest> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/pulls/${number}`);
|
||||
const data = await this.fetch<GitHubPRResponse>(`/repos/${owner}/${repo}/pulls/${number}`);
|
||||
return this.transformPullRequest(data);
|
||||
}
|
||||
|
||||
@@ -160,7 +207,7 @@ export class GitHubProvider implements GitHostProvider {
|
||||
repo: string,
|
||||
state: 'open' | 'closed' | 'all' = 'open'
|
||||
): Promise<PullRequest[]> {
|
||||
const data = await this.fetch<any[]>(`/repos/${owner}/${repo}/pulls?state=${state}`);
|
||||
const data = await this.fetch<GitHubPRResponse[]>(`/repos/${owner}/${repo}/pulls?state=${state}`);
|
||||
return data.map(pr => this.transformPullRequest(pr));
|
||||
}
|
||||
|
||||
@@ -170,7 +217,7 @@ export class GitHubProvider implements GitHostProvider {
|
||||
number: number,
|
||||
options: { title?: string; body?: string }
|
||||
): Promise<PullRequest> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
const data = await this.fetch<GitHubPRResponse>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(options),
|
||||
@@ -180,7 +227,7 @@ export class GitHubProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async closePullRequest(owner: string, repo: string, number: number): Promise<PullRequest> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
const data = await this.fetch<GitHubPRResponse>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ state: 'closed' }),
|
||||
@@ -190,7 +237,14 @@ export class GitHubProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getCurrentUser(): Promise<GitHostUser> {
|
||||
const data = await this.fetch<any>('/user');
|
||||
interface GitHubUser {
|
||||
login: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
}
|
||||
|
||||
const data = await this.fetch<GitHubUser>('/user');
|
||||
|
||||
return {
|
||||
username: data.login,
|
||||
@@ -205,9 +259,23 @@ export class GitHubProvider implements GitHostProvider {
|
||||
return `https://github.com/${baseRepo}/compare/${baseBranch}...${headOwner}:${headRepoName}:${headBranch}?expand=1`;
|
||||
}
|
||||
|
||||
private transformPullRequest(data: any): PullRequest {
|
||||
private transformPullRequest(data: {
|
||||
id: number;
|
||||
number: number;
|
||||
state: string;
|
||||
title: string;
|
||||
body: string;
|
||||
html_url: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
user: { login: string };
|
||||
head: { ref: string; repo: { full_name: string } };
|
||||
base: { ref: string; repo: { full_name: string } };
|
||||
mergeable?: boolean;
|
||||
merged?: boolean;
|
||||
}): PullRequest {
|
||||
const state = data.merged ? 'merged' : data.state;
|
||||
|
||||
|
||||
return {
|
||||
number: data.number,
|
||||
title: data.title,
|
||||
|
||||
@@ -7,9 +7,26 @@ import type {
|
||||
PullRequest,
|
||||
CreatePullRequestOptions,
|
||||
GitHostUser,
|
||||
PullRequestCheck,
|
||||
} from './types';
|
||||
|
||||
interface GitLabMRResponse {
|
||||
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;
|
||||
}
|
||||
|
||||
export class GitLabProvider implements GitHostProvider {
|
||||
readonly name = 'GitLab';
|
||||
readonly apiBaseUrl = 'https://gitlab.com/api/v4';
|
||||
@@ -48,8 +65,19 @@ export class GitLabProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getRepository(owner: string, repo: string): Promise<GitRepository> {
|
||||
interface GitLabProject {
|
||||
namespace: { path: string };
|
||||
path: string;
|
||||
path_with_namespace: string;
|
||||
default_branch: string;
|
||||
http_url_to_repo: string;
|
||||
web_url: string;
|
||||
description: string;
|
||||
visibility: string;
|
||||
}
|
||||
|
||||
const projectPath = this.encodeProjectPath(owner, repo);
|
||||
const data = await this.fetch<any>(`/projects/${projectPath}`);
|
||||
const data = await this.fetch<GitLabProject>(`/projects/${projectPath}`);
|
||||
|
||||
return {
|
||||
owner: data.namespace.path,
|
||||
@@ -65,9 +93,15 @@ export class GitLabProvider implements GitHostProvider {
|
||||
|
||||
async canUserPush(owner: string, repo: string): Promise<boolean> {
|
||||
try {
|
||||
interface GitLabProjectWithPermissions {
|
||||
permissions?: {
|
||||
project_access?: { access_level?: number };
|
||||
};
|
||||
}
|
||||
|
||||
const projectPath = this.encodeProjectPath(owner, repo);
|
||||
const data = await this.fetch<any>(`/projects/${projectPath}`);
|
||||
|
||||
const data = await this.fetch<GitLabProjectWithPermissions>(`/projects/${projectPath}`);
|
||||
|
||||
// GitLab permissions are more granular
|
||||
// developer (30), maintainer (40), or owner (50) can push
|
||||
const accessLevel = data.permissions?.project_access?.access_level || 0;
|
||||
@@ -78,8 +112,17 @@ export class GitLabProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async createFork(owner: string, repo: string): Promise<GitFork> {
|
||||
interface GitLabFork {
|
||||
namespace: { path: string };
|
||||
path: string;
|
||||
path_with_namespace: string;
|
||||
http_url_to_repo: string;
|
||||
web_url: string;
|
||||
forked_from_project?: { path_with_namespace: string };
|
||||
}
|
||||
|
||||
const projectPath = this.encodeProjectPath(owner, repo);
|
||||
const data = await this.fetch<any>(`/projects/${projectPath}/fork`, {
|
||||
const data = await this.fetch<GitLabFork>(`/projects/${projectPath}/fork`, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
@@ -95,8 +138,17 @@ export class GitLabProvider implements GitHostProvider {
|
||||
|
||||
async getFork(upstreamOwner: string, upstreamRepo: string, username: string): Promise<GitFork | null> {
|
||||
try {
|
||||
interface GitLabForkCheck {
|
||||
namespace: { path: string };
|
||||
path: string;
|
||||
path_with_namespace: string;
|
||||
http_url_to_repo: string;
|
||||
web_url: string;
|
||||
forked_from_project?: { path_with_namespace: string };
|
||||
}
|
||||
|
||||
const forkPath = this.encodeProjectPath(username, upstreamRepo);
|
||||
const data = await this.fetch<any>(`/projects/${forkPath}`);
|
||||
const data = await this.fetch<GitLabForkCheck>(`/projects/${forkPath}`);
|
||||
|
||||
// Check if it's a fork of the upstream
|
||||
if (data.forked_from_project?.path_with_namespace === `${upstreamOwner}/${upstreamRepo}`) {
|
||||
@@ -141,7 +193,7 @@ export class GitLabProvider implements GitHostProvider {
|
||||
const sourceProjectPath = this.encodeProjectPath(options.headRepo.split('/')[0], options.headRepo.split('/')[1]);
|
||||
const [targetOwner, targetRepo] = options.baseRepo.split('/');
|
||||
|
||||
const data = await this.fetch<any>(`/projects/${sourceProjectPath}/merge_requests`, {
|
||||
const data = await this.fetch<GitLabMRResponse>(`/projects/${sourceProjectPath}/merge_requests`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
source_branch: options.headBranch,
|
||||
@@ -158,7 +210,7 @@ export class GitLabProvider implements GitHostProvider {
|
||||
|
||||
async getPullRequest(owner: string, repo: string, number: number): Promise<PullRequest> {
|
||||
const projectPath = this.encodeProjectPath(owner, repo);
|
||||
const data = await this.fetch<any>(`/projects/${projectPath}/merge_requests/${number}`);
|
||||
const data = await this.fetch<GitLabMRResponse>(`/projects/${projectPath}/merge_requests/${number}`);
|
||||
return this.transformMergeRequest(data);
|
||||
}
|
||||
|
||||
@@ -169,7 +221,7 @@ export class GitLabProvider implements GitHostProvider {
|
||||
): Promise<PullRequest[]> {
|
||||
const projectPath = this.encodeProjectPath(owner, repo);
|
||||
const stateParam = state === 'all' ? 'all' : state === 'open' ? 'opened' : 'closed';
|
||||
const data = await this.fetch<any[]>(`/projects/${projectPath}/merge_requests?state=${stateParam}`);
|
||||
const data = await this.fetch<GitLabMRResponse[]>(`/projects/${projectPath}/merge_requests?state=${stateParam}`);
|
||||
return data.map(mr => this.transformMergeRequest(mr));
|
||||
}
|
||||
|
||||
@@ -180,7 +232,7 @@ export class GitLabProvider implements GitHostProvider {
|
||||
options: { title?: string; body?: string }
|
||||
): Promise<PullRequest> {
|
||||
const projectPath = this.encodeProjectPath(owner, repo);
|
||||
const data = await this.fetch<any>(`/projects/${projectPath}/merge_requests/${number}`, {
|
||||
const data = await this.fetch<GitLabMRResponse>(`/projects/${projectPath}/merge_requests/${number}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
title: options.title,
|
||||
@@ -204,7 +256,14 @@ export class GitLabProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getCurrentUser(): Promise<GitHostUser> {
|
||||
const data = await this.fetch<any>('/user');
|
||||
interface GitLabUser {
|
||||
username: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
}
|
||||
|
||||
const data = await this.fetch<GitLabUser>('/user');
|
||||
|
||||
return {
|
||||
username: data.username,
|
||||
@@ -219,7 +278,23 @@ 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: any): PullRequest {
|
||||
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 {
|
||||
const state = data.state === 'merged' ? 'merged' : data.state === 'opened' ? 'open' : 'closed';
|
||||
|
||||
return {
|
||||
@@ -245,7 +320,7 @@ export class GitLabProvider implements GitHostProvider {
|
||||
|
||||
return [{
|
||||
name: 'Pipeline',
|
||||
status: data.pipeline.status === 'running' ? 'pending' :
|
||||
status: data.pipeline.status === 'running' ? 'pending' :
|
||||
data.pipeline.status === 'success' ? 'success' : 'failure',
|
||||
conclusion: data.pipeline.status,
|
||||
detailsUrl: data.pipeline.web_url,
|
||||
|
||||
@@ -7,9 +7,24 @@ import type {
|
||||
PullRequest,
|
||||
CreatePullRequestOptions,
|
||||
GitHostUser,
|
||||
PullRequestCheck,
|
||||
} from './types';
|
||||
|
||||
interface GiteaPRResponse {
|
||||
id: number;
|
||||
number: number;
|
||||
state: string;
|
||||
title: string;
|
||||
body: string;
|
||||
html_url: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
user: { login: string };
|
||||
head: { ref: string; repo: { full_name: string } };
|
||||
base: { ref: string; repo: { full_name: string } };
|
||||
mergeable?: boolean;
|
||||
merged?: boolean;
|
||||
}
|
||||
|
||||
export class GiteaProvider implements GitHostProvider {
|
||||
readonly name: string;
|
||||
readonly apiBaseUrl: string;
|
||||
@@ -46,7 +61,18 @@ export class GiteaProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getRepository(owner: string, repo: string): Promise<GitRepository> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}`);
|
||||
interface GiteaRepo {
|
||||
owner: { login: string };
|
||||
name: string;
|
||||
full_name: string;
|
||||
default_branch: string;
|
||||
clone_url: string;
|
||||
html_url: string;
|
||||
description: string;
|
||||
private: boolean;
|
||||
}
|
||||
|
||||
const data = await this.fetch<GiteaRepo>(`/repos/${owner}/${repo}`);
|
||||
|
||||
return {
|
||||
owner: data.owner.login,
|
||||
@@ -62,7 +88,11 @@ export class GiteaProvider implements GitHostProvider {
|
||||
|
||||
async canUserPush(owner: string, repo: string): Promise<boolean> {
|
||||
try {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}`);
|
||||
interface GiteaRepoWithPermissions {
|
||||
permissions?: { push?: boolean; admin?: boolean };
|
||||
}
|
||||
|
||||
const data = await this.fetch<GiteaRepoWithPermissions>(`/repos/${owner}/${repo}`);
|
||||
return data.permissions?.push === true || data.permissions?.admin === true;
|
||||
} catch {
|
||||
return false;
|
||||
@@ -70,7 +100,16 @@ export class GiteaProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async createFork(owner: string, repo: string): Promise<GitFork> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/forks`, {
|
||||
interface GiteaFork {
|
||||
owner: { login: string };
|
||||
name: string;
|
||||
full_name: string;
|
||||
clone_url: string;
|
||||
html_url: string;
|
||||
parent?: { full_name: string };
|
||||
}
|
||||
|
||||
const data = await this.fetch<GiteaFork>(`/repos/${owner}/${repo}/forks`, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
@@ -86,7 +125,17 @@ export class GiteaProvider implements GitHostProvider {
|
||||
|
||||
async getFork(upstreamOwner: string, upstreamRepo: string, username: string): Promise<GitFork | null> {
|
||||
try {
|
||||
const data = await this.fetch<any>(`/repos/${username}/${upstreamRepo}`);
|
||||
interface GiteaForkCheck {
|
||||
fork: boolean;
|
||||
owner: { login: string };
|
||||
name: string;
|
||||
full_name: string;
|
||||
clone_url: string;
|
||||
html_url: string;
|
||||
parent?: { full_name: string };
|
||||
}
|
||||
|
||||
const data = await this.fetch<GiteaForkCheck>(`/repos/${username}/${upstreamRepo}`);
|
||||
|
||||
if (data.fork && data.parent?.full_name === `${upstreamOwner}/${upstreamRepo}`) {
|
||||
return {
|
||||
@@ -134,7 +183,7 @@ export class GiteaProvider implements GitHostProvider {
|
||||
? `${headOwner}:${options.headBranch}`
|
||||
: options.headBranch;
|
||||
|
||||
const data = await this.fetch<any>(`/repos/${baseOwner}/${baseRepo}/pulls`, {
|
||||
const data = await this.fetch<GiteaPRResponse>(`/repos/${baseOwner}/${baseRepo}/pulls`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
title: options.title,
|
||||
@@ -148,7 +197,7 @@ export class GiteaProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getPullRequest(owner: string, repo: string, number: number): Promise<PullRequest> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/pulls/${number}`);
|
||||
const data = await this.fetch<GiteaPRResponse>(`/repos/${owner}/${repo}/pulls/${number}`);
|
||||
return this.transformPullRequest(data);
|
||||
}
|
||||
|
||||
@@ -157,7 +206,7 @@ export class GiteaProvider implements GitHostProvider {
|
||||
repo: string,
|
||||
state: 'open' | 'closed' | 'all' = 'open'
|
||||
): Promise<PullRequest[]> {
|
||||
const data = await this.fetch<any[]>(`/repos/${owner}/${repo}/pulls?state=${state}`);
|
||||
const data = await this.fetch<GiteaPRResponse[]>(`/repos/${owner}/${repo}/pulls?state=${state}`);
|
||||
return data.map(pr => this.transformPullRequest(pr));
|
||||
}
|
||||
|
||||
@@ -167,7 +216,7 @@ export class GiteaProvider implements GitHostProvider {
|
||||
number: number,
|
||||
options: { title?: string; body?: string }
|
||||
): Promise<PullRequest> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
const data = await this.fetch<GiteaPRResponse>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(options),
|
||||
});
|
||||
@@ -176,7 +225,7 @@ export class GiteaProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async closePullRequest(owner: string, repo: string, number: number): Promise<PullRequest> {
|
||||
const data = await this.fetch<any>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
const data = await this.fetch<GiteaPRResponse>(`/repos/${owner}/${repo}/pulls/${number}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ state: 'closed' }),
|
||||
});
|
||||
@@ -185,7 +234,14 @@ export class GiteaProvider implements GitHostProvider {
|
||||
}
|
||||
|
||||
async getCurrentUser(): Promise<GitHostUser> {
|
||||
const data = await this.fetch<any>('/user');
|
||||
interface GiteaUser {
|
||||
login: string;
|
||||
full_name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
}
|
||||
|
||||
const data = await this.fetch<GiteaUser>('/user');
|
||||
|
||||
return {
|
||||
username: data.login,
|
||||
@@ -201,7 +257,21 @@ export class GiteaProvider implements GitHostProvider {
|
||||
return `${baseUrl}/${baseRepo}/compare/${baseBranch}...${headOwner}:${headRepoName}:${headBranch}`;
|
||||
}
|
||||
|
||||
private transformPullRequest(data: any): PullRequest {
|
||||
private transformPullRequest(data: {
|
||||
id: number;
|
||||
number: number;
|
||||
state: string;
|
||||
title: string;
|
||||
body: string;
|
||||
html_url: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
user: { login: string };
|
||||
head: { ref: string; repo: { full_name: string } };
|
||||
base: { ref: string; repo: { full_name: string } };
|
||||
mergeable?: boolean;
|
||||
merged?: boolean;
|
||||
}): PullRequest {
|
||||
const state = data.merged ? 'merged' : data.state;
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NRelay1, NSchema as n } from '@nostrify/nostrify';
|
||||
import { NRelay1 } from '@nostrify/nostrify';
|
||||
import type {
|
||||
GitHostProvider,
|
||||
GitHostConfig,
|
||||
@@ -9,6 +9,10 @@ import type {
|
||||
GitHostUser,
|
||||
} from './types';
|
||||
|
||||
interface NostrSigner {
|
||||
signEvent: (event: { kind: number; content: string; tags: string[][]; created_at: number }) => Promise<unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nostr Git provider implementing NIP-34 (git stuff)
|
||||
* Enables creating patches/PRs on Nostr git repositories
|
||||
@@ -18,21 +22,21 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
readonly apiBaseUrl = ''; // Not applicable for Nostr
|
||||
|
||||
private relay: NRelay1;
|
||||
private signer: any; // Nostr signer for publishing events
|
||||
private signer: NostrSigner;
|
||||
private pubkey: string;
|
||||
private relayUrls: string[];
|
||||
|
||||
constructor(config: GitHostConfig & { signer: any; pubkey: string; relayUrls: string[] }) {
|
||||
constructor(config: GitHostConfig & { signer: NostrSigner; pubkey: string; relayUrls: string[] }) {
|
||||
this.signer = config.signer;
|
||||
this.pubkey = config.pubkey;
|
||||
this.relayUrls = config.relayUrls;
|
||||
|
||||
|
||||
// For Nostr git, we need to publish to the repository's designated relays
|
||||
// The relay will be set dynamically when we know which repo we're working with
|
||||
this.relay = new NRelay1('wss://relay.nostr.band'); // Default, will be changed
|
||||
}
|
||||
|
||||
private async queryRepo(owner: string, repo: string): Promise<any> {
|
||||
private async queryRepo(owner: string, repo: string): Promise<{ tags: string[][]; content: string }> {
|
||||
// Query for repository announcement (kind 30617)
|
||||
// d tag is the repo-id (usually kebab-case short name)
|
||||
const events = await this.relay.query([
|
||||
@@ -53,13 +57,13 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
|
||||
async getRepository(owner: string, repo: string): Promise<GitRepository> {
|
||||
const event = await this.queryRepo(owner, repo);
|
||||
|
||||
|
||||
const getName = () => event.tags.find((t: string[]) => t[0] === 'name')?.[1] || repo;
|
||||
const getDescription = () => event.tags.find((t: string[]) => t[0] === 'description')?.[1];
|
||||
const getWebUrl = () => event.tags.find((t: string[]) => t[0] === 'web')?.[1] || '';
|
||||
const getCloneUrl = () => event.tags.find((t: string[]) => t[0] === 'clone')?.[1] || '';
|
||||
const getRelays = () => event.tags.filter((t: string[]) => t[0] === 'relays').map((t: string[]) => t[1]);
|
||||
|
||||
|
||||
// Update relay to use repository's designated relays
|
||||
const repoRelays = getRelays();
|
||||
if (repoRelays.length > 0) {
|
||||
@@ -87,7 +91,7 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
const maintainers = event.tags
|
||||
.filter((t: string[]) => t[0] === 'maintainers')
|
||||
.map((t: string[]) => t[1]);
|
||||
|
||||
|
||||
// Repo owner is always a maintainer
|
||||
const isMaintainer = owner === this.pubkey || maintainers.includes(this.pubkey);
|
||||
return isMaintainer;
|
||||
@@ -100,7 +104,7 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
const repoEvent = await this.queryRepo(owner, repo);
|
||||
const cloneUrl = repoEvent.tags.find((t: string[]) => t[0] === 'clone')?.[1] || '';
|
||||
const webUrl = repoEvent.tags.find((t: string[]) => t[0] === 'web')?.[1] || '';
|
||||
|
||||
|
||||
// The "fork" is actually just the user's local copy
|
||||
// We'll use this to track that patches come from the user
|
||||
return {
|
||||
@@ -113,13 +117,13 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
};
|
||||
}
|
||||
|
||||
async getFork(upstreamOwner: string, upstreamRepo: string, username: string): Promise<GitFork | null> {
|
||||
async getFork(_upstreamOwner: string, _upstreamRepo: string, _username: string): Promise<GitFork | null> {
|
||||
// Nostr git doesn't have forks - patches are submitted directly
|
||||
// Return null to indicate no fork exists
|
||||
return null;
|
||||
}
|
||||
|
||||
async waitForFork(upstreamOwner: string, upstreamRepo: string, username: string, timeout = 10000): Promise<GitFork> {
|
||||
async waitForFork(upstreamOwner: string, upstreamRepo: string, _username: string, _timeout = 10000): Promise<GitFork> {
|
||||
// Create a virtual fork immediately
|
||||
return this.createFork(upstreamOwner, upstreamRepo);
|
||||
}
|
||||
@@ -127,18 +131,17 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
async createPullRequest(options: CreatePullRequestOptions): Promise<PullRequest> {
|
||||
// In Nostr git, a "pull request" is a patch event (kind 1617)
|
||||
// The patch content should be the output of `git format-patch`
|
||||
|
||||
|
||||
const [owner, repo] = options.baseRepo.split('/');
|
||||
const repoEvent = await this.queryRepo(owner, repo);
|
||||
|
||||
|
||||
// Get the earliest unique commit (euc) for the repository
|
||||
const euc = repoEvent.tags.find((t: string[]) => t[0] === 'r' && t[2] === 'euc')?.[1];
|
||||
|
||||
// For now, we'll create a placeholder patch
|
||||
// In a real implementation, this would generate the actual git patch
|
||||
const patchContent = options.body ||
|
||||
|
||||
// Create patch content from the provided body or generate a simple patch description
|
||||
const patchContent = options.body ||
|
||||
`Patch proposal: ${options.title}\n\nFrom: ${options.headBranch}\nTo: ${options.baseBranch}`;
|
||||
|
||||
|
||||
// Create patch event (kind 1617)
|
||||
const patchEvent = await this.signer.signEvent({
|
||||
kind: 1617,
|
||||
@@ -157,7 +160,7 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
|
||||
// Publish to repository's designated relays
|
||||
await this.relay.event(patchEvent);
|
||||
|
||||
|
||||
// Return a PullRequest-compatible object
|
||||
return {
|
||||
number: parseInt(patchEvent.id.slice(0, 8), 16), // Use first 8 chars of event ID as number
|
||||
@@ -175,13 +178,13 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
};
|
||||
}
|
||||
|
||||
async getPullRequest(owner: string, repo: string, number: number): Promise<PullRequest> {
|
||||
async getPullRequest(_owner: string, _repo: string, _number: number): Promise<PullRequest> {
|
||||
// Query for patch event by converting number back to event ID
|
||||
// This is a limitation - we'd need to store the mapping or query differently
|
||||
throw new Error('Getting specific patches by number is not yet implemented for Nostr git');
|
||||
}
|
||||
|
||||
async listPullRequests(owner: string, repo: string, state: 'open' | 'closed' | 'all' = 'open'): Promise<PullRequest[]> {
|
||||
async listPullRequests(owner: string, repo: string, _state: 'open' | 'closed' | 'all' = 'open'): Promise<PullRequest[]> {
|
||||
// Query for patch events (kind 1617) referencing this repository
|
||||
const events = await this.relay.query([
|
||||
{
|
||||
@@ -210,12 +213,12 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
}));
|
||||
}
|
||||
|
||||
async updatePullRequest(owner: string, repo: string, number: number, options: { title?: string; body?: string }): Promise<PullRequest> {
|
||||
async updatePullRequest(_owner: string, _repo: string, _number: number, _options: { title?: string; body?: string }): Promise<PullRequest> {
|
||||
// In Nostr git, you can't edit events - you'd create a new revision
|
||||
throw new Error('Updating patches is not supported - create a new revision instead');
|
||||
}
|
||||
|
||||
async closePullRequest(owner: string, repo: string, number: number): Promise<PullRequest> {
|
||||
async closePullRequest(_owner: string, _repo: string, _number: number): Promise<PullRequest> {
|
||||
// To close a patch, publish a status event (kind 1632 - Closed)
|
||||
throw new Error('Closing patches via status events is not yet implemented');
|
||||
}
|
||||
@@ -245,7 +248,7 @@ export class NostrGitProvider implements GitHostProvider {
|
||||
};
|
||||
}
|
||||
|
||||
getCompareUrl(baseRepo: string, baseBranch: string, headRepo: string, headBranch: string): string {
|
||||
getCompareUrl(_baseRepo: string, _baseBranch: string, _headRepo: string, _headBranch: string): string {
|
||||
// Nostr git doesn't have a web compare view
|
||||
// Could potentially link to a Nostr client that displays patches
|
||||
return '';
|
||||
|
||||
@@ -14,9 +14,13 @@ import type { GitHostProvider, GitHostConfig } from './types';
|
||||
/**
|
||||
* 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<unknown>;
|
||||
}
|
||||
|
||||
export function createGitHostProvider(
|
||||
url: string,
|
||||
config: GitHostConfig & { signer?: any; pubkey?: string; relayUrls?: string[] },
|
||||
config: GitHostConfig & { signer?: NostrSigner; pubkey?: string; relayUrls?: string[] },
|
||||
corsProxy?: string
|
||||
): GitHostProvider | null {
|
||||
const hostType = detectGitHost(url);
|
||||
|
||||
Reference in new issue
Block a user