import axios from 'axios';
import { randomUUID } from 'node:crypto';
import { appendFileSync, existsSync } from 'node:fs';
import { EOL } from 'node:os';
export const parseIssue = (issue) => {
    if (issue.includes('#')) {
        const split = issue.split('/');
        const split2 = split[1].split('#');
        return { owner: split[0], repository: split2[0], issue: split2[1] };
    }
    return undefined;
};
export const setGithubTaskOutput = (name, value) => {
    const delimiter = `delimiter_${randomUUID()}`;
    const output = `${name}<<${delimiter}${EOL}${value}${EOL}${delimiter}${EOL}`;
    const filePath = process.env.GITHUB_OUTPUT;
    if (filePath && existsSync(filePath)) {
        appendFileSync(filePath, output, { encoding: 'utf8' });
    }
    else {
        console.log(output);
    }
};
export const getGithubIssue = async ({ owner, repository, issue }) => {
    const response = await axios.get(`https://api.github.com/repos/${owner}/${repository}/issues/${issue}`, {
        headers: {
            'X-GitHub-Api-Version': '2022-11-28',
        },
    });
    return response.data;
};
