Something went wrong. Try again.
A local-first, resumable GitHub-to-Tangled issue migrator. Built with Next.js and shadcn/ui. MIT licensed.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import { execFile } from 'node:child_process';import { promisify } from 'node:util';import { repositoryName } from './configuration.mjs';import { LocalFailure } from './errors.mjs';const run = promisify(execFile);
// Every comment page is exported explicitly. A list view's embedded comment// connection can be truncated even when every issue itself was returned.export async function exportGithubIssues(repository, { execute = run } = {}) { repositoryName(repository); const request = async path => { let result; try { result = await execute('gh', ['api', '--paginate', '--slurp', path], { timeout: 180_000, maxBuffer: 64 * 1024 * 1024, windowsHide: true }); } catch (error) { throw new LocalFailure(error?.code === 'ENOENT' ? 'GITHUB_CLI_NOT_FOUND' : 'GITHUB_EXPORT_FAILED', 502); } let pages; try { pages = JSON.parse(result.stdout); } catch { throw new LocalFailure('GITHUB_EXPORT_INVALID', 502); } if (!Array.isArray(pages) || pages.some(page => !Array.isArray(page))) throw new LocalFailure('GITHUB_EXPORT_INVALID', 502); return pages.flat(); }; const issues = (await request(`repos/${repository}/issues?state=all&per_page=100`)).filter(issue => !issue.pull_request); if (issues.length > 10000) throw new LocalFailure('GITHUB_EXPORT_TOO_LARGE', 502); const output = new Array(issues.length); let next = 0; await Promise.all(Array.from({ length: Math.min(4, issues.length) }, async () => { while (next < issues.length) { const index = next++; const issue = issues[index]; if (!Number.isSafeInteger(issue.number) || issue.number < 1) throw new LocalFailure('GITHUB_EXPORT_INVALID', 502); const comments = issue.comments ? await request(`repos/${repository}/issues/${issue.number}/comments?per_page=100`) : []; if (!Number.isInteger(issue.comments) || issue.comments < 0 || comments.length !== issue.comments) throw new LocalFailure('GITHUB_EXPORT_CHANGED', 409); output[index] = { ...issue, url: issue.html_url, author: issue.user, createdAt: issue.created_at, updatedAt: issue.updated_at, closedAt: issue.closed_at, stateReason: issue.state_reason, comments: comments.map(comment => ({ ...comment, url: comment.html_url, author: comment.user, createdAt: comment.created_at, updatedAt: comment.updated_at })), }; } })); return output;}