import fs from "fs/promises";
import path from "path";
import type { Octokits } from "../api/client";
import { GITHUB_SERVER_URL } from "../api/config";
const escapedUrl = GITHUB_SERVER_URL.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const IMAGE_REGEX = new RegExp(
`!\\[[^\\]]*\\]\\((${escapedUrl}\\/user-attachments\\/assets\\/[^)]+)\\)`,
"g",
);
const HTML_IMG_REGEX = new RegExp(
`
]+src=["']([^"']*${escapedUrl}\\/user-attachments\\/assets\\/[^"']+)["'][^>]*>`,
"gi",
);
type IssueComment = {
type: "issue_comment";
id: string;
body: string;
};
type ReviewComment = {
type: "review_comment";
id: string;
body: string;
};
type ReviewBody = {
type: "review_body";
id: string;
pullNumber: string;
body: string;
};
type IssueBody = {
type: "issue_body";
issueNumber: string;
body: string;
};
type PullRequestBody = {
type: "pr_body";
pullNumber: string;
body: string;
};
export type CommentWithImages =
| IssueComment
| ReviewComment
| ReviewBody
| IssueBody
| PullRequestBody;
export async function downloadCommentImages(
octokits: Octokits,
owner: string,
repo: string,
comments: CommentWithImages[],
): Promise