CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import { useState, useEffect, useCallback } from 'react';
import { api, type PullRequest, type PullComment } from '../api/client';
export function usePulls(owner: string | null, repo: string | null, state: 'open' | 'closed' | 'merged' | 'all' = 'open') {
const [pulls, setPulls] = useState<PullRequest[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const fetch = useCallback(async () => {
if (!owner || !repo) return;
setLoading(true);
setError(null);
try {
const data = await api.listPulls(owner, repo, state);
setPulls(data);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load pull requests');
} finally {
setLoading(false);
}
}, [owner, repo, state]);
useEffect(() => {
fetch();
}, [fetch]);
return { pulls, loading, error, refresh: fetch };
}
export function usePull(owner: string | null, repo: string | null, number: number | null) {
const [pull, setPull] = useState<PullRequest | null>(null);
const [comments, setComments] = useState<PullComment[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const fetch = useCallback(async () => {
if (!owner || !repo || number === null) return;
setLoading(true);
setError(null);
try {
const data = await api.getPull(owner, repo, number);
setPull(data.pull);
setComments(data.comments);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load pull request');
} finally {
setLoading(false);
}
}, [owner, repo, number]);
useEffect(() => {
fetch();
}, [fetch]);
return { pull, comments, loading, error, refresh: fetch };
}
|