diff --git a/.github/actions/issue-to-hexo/index.js b/.github/actions/issue-to-hexo/index.js index a0d7978..5b316b9 100644 --- a/.github/actions/issue-to-hexo/index.js +++ b/.github/actions/issue-to-hexo/index.js @@ -3,14 +3,12 @@ const core = require('@actions/core'); const github = require('@actions/github'); const io = require('@actions/io'); -const main = async () => { - const issue_number = core.getInput('issue_number'); - const token = core.getInput('token'); - const owner = github.context.payload.repository.owner.login; - const repo = github.context.payload.repository.name; - - const octokit = github.getOctokit(token); +/** @type ReturnType */ +let octokit; +let owner = ''; +let repo = ''; +const generateIssue = async (issue_number) => { const issue = await octokit.rest.issues.get({ owner, repo, @@ -22,13 +20,13 @@ const main = async () => { const bodyMatch = body.match(//); if (!bodyMatch) { core.setFailed('no hexo data'); - return; + throw new Error('no hexo data'); } const urlMatch = bodyMatch[1].match(/url: ([\s\S]+?)\r?\n/); if (!urlMatch) { core.setFailed('no url'); - return; + throw new Error('no url'); } const categories = labels @@ -52,8 +50,6 @@ const main = async () => { issue_number, }); - console.log('==comments', comments.data); - const commentBodys = comments?.data ?.filter((v) => { return v.user.login === owner && v.body.includes(''); @@ -63,12 +59,33 @@ const main = async () => { }); content += `\n\n${commentBodys?.join(`\n`)}\n\n`; - console.log('==path', path); - console.log('==content', content); + // console.log('==path', path); + // console.log('==content', content); await io.mkdirP('./src/source/_posts'); fs.writeFileSync(`./src/source/_posts/${path}.md`, content); + + return { path }; +}; + +const main = async () => { + const issue_number = core.getInput('issue_number'); + const token = core.getInput('token'); + owner = github.context.payload.repository.owner.login; + repo = github.context.payload.repository.name; + + octokit = github.getOctokit(token); + + const issueNumbers = issue_number.split(','); + + const results = await Promise.all( + issueNumbers.map((v) => { + return generateIssue(v); + }), + ); + + console.log('==all paths', results); }; try { diff --git a/.github/workflows/issue-to-hexo.yml b/.github/workflows/issue-to-hexo.yml index ed81aa6..ccfce43 100644 --- a/.github/workflows/issue-to-hexo.yml +++ b/.github/workflows/issue-to-hexo.yml @@ -5,7 +5,7 @@ on: inputs: issue_number: required: true - type: number + type: string jobs: build: runs-on: ubuntu-latest