From 6fd0ac3ff755c716dc76cdbc524f9ac2b00967a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Tue, 13 Aug 2024 16:20:05 +0800 Subject: [PATCH] chore: print log --- dist/index.js | 16 ++++++++++++---- src/index.ts | 22 +++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/dist/index.js b/dist/index.js index e47a5d3..8c8845f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29220,7 +29220,9 @@ const github_1 = __nccwpck_require__(5942); const dayjs_1 = __importDefault(__nccwpck_require__(9090)); const renderer_1 = __nccwpck_require__(5656); const GITHUB_TOKEN = node_process_1.default.env.GITHUB_TOKEN; -(0, core_1.info)(`github.context:${JSON.stringify(github_1.context)}`); +(0, core_1.startGroup)('github.context'); +(0, core_1.info)(`github.context:${JSON.stringify(github_1.context, null, 4)}`); +(0, core_1.endGroup)(); // console.log('payload', context.payload); if (!GITHUB_TOKEN) { throw new Error('GitHub\'s API requires a token. Please pass a valid token (GITHUB_TOKEN) as an env variable, no scopes are required.'); @@ -29235,20 +29237,26 @@ function generatorLogStart() { } const { owner, repo } = github_1.context.repo; (0, core_1.info)(`owner:${owner}, repo:${repo}`); - const releases = yield octokit.rest.repos.generateReleaseNotes({ + // https://octokit.github.io/rest.js/v20#repos-generate-release-notes + const releaseNodes = yield octokit.rest.repos.generateReleaseNotes({ owner, repo, tag_name: tag, // 'package.version' target_commitish: 'develop', // 也可以从上下文中拿 }); - const PRNumbers = (0, renderer_1.getPReformatNotes)(releases.data.body); + (0, core_1.startGroup)('releaseNodes'); + (0, core_1.info)(`releaseNodes:${JSON.stringify(github_1.context, null, 4)}`); + (0, core_1.endGroup)(); + const PRNumbers = (0, renderer_1.getPReformatNotes)(releaseNodes.data.body); const PRListRes = yield Promise.all(PRNumbers.map(pull_number => octokit.rest.pulls.get({ owner, repo, pull_number, }))); const PRList = PRListRes.map(res => res.data); - (0, core_1.info)(`PRList:${JSON.stringify(PRList)}`); + (0, core_1.startGroup)('releaseNodes'); + (0, core_1.info)(`PRList:${JSON.stringify(PRList, null, 4)}`); + (0, core_1.endGroup)(); const logRelease = `(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 ## 🌈 ${tag} \`${(0, dayjs_1.default)().format('YYYY-MM-DD')}\` \n${(0, renderer_1.renderMarkdown)(PRList)}\n`; (0, core_1.info)(logRelease); diff --git a/src/index.ts b/src/index.ts index 39f900f..06e50f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,15 @@ import fs from 'node:fs' import process from 'node:process' -import { getInput, info, setFailed, setOutput } from '@actions/core' +import { endGroup, getInput, info, setFailed, setOutput, startGroup } from '@actions/core' import { context, getOctokit } from '@actions/github' import dayjs from 'dayjs' import { getPReformatNotes, renderMarkdown } from './renderer' import type { PullsData } from './types' const GITHUB_TOKEN = process.env.GITHUB_TOKEN - -info(`github.context:${JSON.stringify(context)}`) +startGroup('github.context') +info(`github.context:${JSON.stringify(context, null, 4)}`) +endGroup() // console.log('payload', context.payload); @@ -28,15 +29,17 @@ async function generatorLogStart() { } const { owner, repo } = context.repo info(`owner:${owner}, repo:${repo}`) - - const releases = await octokit.rest.repos.generateReleaseNotes({ + // https://octokit.github.io/rest.js/v20#repos-generate-release-notes + const releaseNodes = await octokit.rest.repos.generateReleaseNotes({ owner, repo, tag_name: tag, // 'package.version' target_commitish: 'develop', // 也可以从上下文中拿 }) - - const PRNumbers = getPReformatNotes(releases.data.body) + startGroup('releaseNodes') + info(`releaseNodes:${JSON.stringify(context, null, 4)}`) + endGroup() + const PRNumbers = getPReformatNotes(releaseNodes.data.body) const PRListRes = await Promise.all(PRNumbers.map(pull_number => octokit.rest.pulls.get({ owner, @@ -45,8 +48,9 @@ async function generatorLogStart() { }))) const PRList = PRListRes.map(res => res.data as PullsData) - - info(`PRList:${JSON.stringify(PRList)}`) + startGroup('releaseNodes') + info(`PRList:${JSON.stringify(PRList, null, 4)}`) + endGroup() const logRelease = `(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中 ## 🌈 ${tag} \`${dayjs().format('YYYY-MM-DD')}\` \n${renderMarkdown(PRList)}\n`