Spaces:
Paused
Paused
Download src/github.ts from delqhi/sin-github-issues: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/spaces/delqhi/sin-github-issues/resolve/refs%2Fpr%2F1/src/github.ts
- Command line
-
hf download hf://spaces/delqhi/sin-github-issues@refs/pr/1/src/github.ts
-
curl -L -o github.ts https://huggingface.co/spaces/delqhi/sin-github-issues/resolve/refs%2Fpr%2F1/src/github.ts
2.09 kB
| import { runCommand, runJsonCommand } from './command.js'; | |
| type IssueRow = { number: number; title: string; url: string; state: string }; | |
| export async function ensureIssue(input: { | |
| repo: string; | |
| title: string; | |
| body: string; | |
| labels?: string[]; | |
| }) { | |
| const rows = await runJsonCommand<IssueRow[]>('gh', ['issue', 'list', '--repo', input.repo, '--state', 'all', '--limit', '200', '--json', 'number,title,url,state']); | |
| const existing = rows.find((row) => row.title.trim().toLowerCase() === input.title.trim().toLowerCase()); | |
| if (existing) { | |
| await runCommand('gh', ['issue', 'edit', String(existing.number), '--repo', input.repo, '--body', input.body], undefined); | |
| for (const label of input.labels || []) { | |
| try { | |
| await runCommand('gh', ['issue', 'edit', String(existing.number), '--repo', input.repo, '--add-label', label], undefined); | |
| } catch { | |
| } | |
| } | |
| return { created: false, issue: existing, issueNumber: existing.number, issueUrl: existing.url }; | |
| } | |
| let created; | |
| try { | |
| created = await runCommand('gh', ['issue', 'create', '--repo', input.repo, '--title', input.title, '--body', input.body, ...(input.labels || []).flatMap((label) => ['--label', label])], undefined); | |
| } catch { | |
| created = await runCommand('gh', ['issue', 'create', '--repo', input.repo, '--title', input.title, '--body', input.body], undefined); | |
| } | |
| const url = created.stdout.trim(); | |
| const issueNumber = Number.parseInt(url.split('/').pop() || '', 10); | |
| return { created: true, issueUrl: url, issueNumber }; | |
| } | |
| export async function commentIssue(repo: string, issueNumber: number, body: string) { | |
| await runCommand('gh', ['issue', 'comment', String(issueNumber), '--repo', repo, '--body', body], undefined); | |
| return { ok: true, repo, issueNumber }; | |
| } | |
| export async function closeIssue(repo: string, issueNumber: number, comment?: string) { | |
| const args = ['issue', 'close', String(issueNumber), '--repo', repo]; | |
| if (comment) args.push('--comment', comment); | |
| await runCommand('gh', args, undefined); | |
| return { ok: true, repo, issueNumber }; | |
| } | |