Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: print log #33

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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(releaseNodes, 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)('PRList');
(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);
Expand Down
22 changes: 13 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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(releaseNodes, null, 4)}`)
endGroup()
const PRNumbers = getPReformatNotes(releaseNodes.data.body)

const PRListRes = await Promise.all(PRNumbers.map(pull_number => octokit.rest.pulls.get({
owner,
Expand All @@ -45,8 +48,9 @@ async function generatorLogStart() {
})))

const PRList = PRListRes.map(res => res.data as PullsData)

info(`PRList:${JSON.stringify(PRList)}`)
startGroup('PRList')
info(`PRList:${JSON.stringify(PRList, null, 4)}`)
endGroup()

const logRelease = `(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中
## 🌈 ${tag} \`${dayjs().format('YYYY-MM-DD')}\` \n${renderMarkdown(PRList)}\n`
Expand Down