-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseVCSIssues.js
More file actions
54 lines (54 loc) · 2.13 KB
/
Copy pathuseVCSIssues.js
File metadata and controls
54 lines (54 loc) · 2.13 KB
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useVCSIssues = useVCSIssues;
const react_1 = require("react");
/**
* Hook for fetching issues and PRs from VCS API
* Follows the same pattern as useVCSSelections
*/
function useVCSIssues(provider, owner, repo) {
const [issuesAndPRs, setIssuesAndPRs] = (0, react_1.useState)([]);
const [isLoadingIssues, setIsLoadingIssues] = (0, react_1.useState)(false);
const [error, setError] = (0, react_1.useState)(null);
(0, react_1.useEffect)(() => {
if (!provider || !owner || !repo) {
setIssuesAndPRs([]);
return;
}
const fetchIssues = async () => {
setIsLoadingIssues(true);
setError(null);
try {
console.log('[useVCSIssues] Fetching issues for:', { provider, owner, repo });
const response = await fetch(`/api/vcs?resource=issues&provider=${provider}&owner=${encodeURIComponent(owner)}&repo=${encodeURIComponent(repo)}`);
if (!response.ok) {
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
throw new Error(errorData.error || 'Failed to fetch issues and PRs');
}
const data = await response.json();
console.log('[useVCSIssues] Received data:', data);
// Format the issues/PRs for the IssueSelector component
const formatted = (data.issues || []).map((item) => ({
id: String(item.number),
title: item.title,
isPR: !!item.pull_request,
url: item.url || item.html_url || ''
}));
setIssuesAndPRs(formatted);
}
catch (err) {
console.error('[useVCSIssues] Error:', err);
setError(err.message);
}
finally {
setIsLoadingIssues(false);
}
};
fetchIssues();
}, [provider, owner, repo]);
return {
issuesAndPRs,
isLoadingIssues,
error
};
}