Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
3.8 kB · 133 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134// GitHub Issues Integration (no auth required for public repos)
export interface GitHubIssue { id: number; number: number; title: string; url: string; state: string; labels: { name: string; color: string }[]; assignee?: { login: string }; created_at: string;}
// Parse GitHub URL to extract owner/repoexport function parseGitHubUrl(url: string): { owner: string; repo: string } | null { // Match github.com/owner/repo or github.com/owner/repo/... const match = url.match(/github\.com\/([^\/]+)\/([^\/]+)/); if (match) { return { owner: match[1], repo: match[2].replace(/\.git$/, "") }; } return null;}
// Fetch issues from a public GitHub repoexport async function fetchGitHubIssues( owner: string, repo: string, state: "open" | "closed" | "all" = "open"): Promise<GitHubIssue[]> { const url = `https://api.github.com/repos/${owner}/${repo}/issues?state=${state}&per_page=50`;
console.log(`\x1b[38;5;141m[github]\x1b[0m Fetching issues from ${owner}/${repo}`);
const res = await fetch(url, { headers: { "Accept": "application/vnd.github.v3+json", "User-Agent": "OpenUI-Agent-Manager", }, });
if (!res.ok) { const text = await res.text(); console.error(`\x1b[38;5;141m[github]\x1b[0m API error:`, res.status, text); throw new Error(`GitHub API error: ${res.status}`); }
const data = await res.json();
// Filter out pull requests (they come through the issues API too) const issues = data .filter((item: any) => !item.pull_request) .map((issue: any) => ({ id: issue.id, number: issue.number, title: issue.title, url: issue.html_url, state: issue.state, labels: issue.labels.map((l: any) => ({ name: l.name, color: l.color })), assignee: issue.assignee ? { login: issue.assignee.login } : undefined, created_at: issue.created_at, }));
console.log(`\x1b[38;5;141m[github]\x1b[0m Found ${issues.length} issues`); return issues;}
// Fetch a single issue by numberexport async function fetchGitHubIssue( owner: string, repo: string, issueNumber: number): Promise<GitHubIssue | null> { const url = `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`;
const res = await fetch(url, { headers: { "Accept": "application/vnd.github.v3+json", "User-Agent": "OpenUI-Agent-Manager", }, });
if (!res.ok) { if (res.status === 404) return null; throw new Error(`GitHub API error: ${res.status}`); }
const issue = await res.json();
return { id: issue.id, number: issue.number, title: issue.title, url: issue.html_url, state: issue.state, labels: issue.labels.map((l: any) => ({ name: l.name, color: l.color })), assignee: issue.assignee ? { login: issue.assignee.login } : undefined, created_at: issue.created_at, };}
// Search issues in a repoexport async function searchGitHubIssues( owner: string, repo: string, query: string): Promise<GitHubIssue[]> { const searchQuery = `${query} repo:${owner}/${repo} is:issue`; const url = `https://api.github.com/search/issues?q=${encodeURIComponent(searchQuery)}&per_page=20`;
const res = await fetch(url, { headers: { "Accept": "application/vnd.github.v3+json", "User-Agent": "OpenUI-Agent-Manager", }, });
if (!res.ok) { throw new Error(`GitHub API error: ${res.status}`); }
const data = await res.json();
return data.items.map((issue: any) => ({ id: issue.id, number: issue.number, title: issue.title, url: issue.html_url, state: issue.state, labels: issue.labels.map((l: any) => ({ name: l.name, color: l.color })), assignee: issue.assignee ? { login: issue.assignee.login } : undefined, created_at: issue.created_at, }));}