Skip to content

Commit

Permalink
build: Update changelog-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinerer committed Sep 29, 2024
1 parent fd7e711 commit ce31c57
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@changesets/cli": "^2.26.2",
"@types/jest": "^29.5.10",
"@types/node": "^20.8.9",
"diy-log": "^2.5.1",
"gulp": "^4.0.2",
"jest": "^29.7.0",
"minimist": "^1.2.8",
Expand Down
19 changes: 10 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const simpleGit = require('simple-git')
const { promisify } = require('util')
const log = require('diy-log')

const git = simpleGit()

// 获取从特定 commit ID 开始的所有最新记录
async function getCommitsSince(commitId) {
const log = promisify(git.log.bind(git))
const logOptions = {
from: commitId
from: commitId,
}

try {
Expand All @@ -31,7 +32,7 @@ async function getCommitsSinceLatestTag() {
}

const logOptions = {
from: latestTag
from: latestTag,
}

try {
Expand All @@ -44,9 +45,9 @@ async function getCommitsSinceLatestTag() {
}

// 格式化 commit 记录
function formatCommits(commits, filter = commit => commit) {
function formatCommits(commits, filter = (commit) => commit) {
const regex = /\(([^)]+)\)/
return commits.filter(filter).map(commit => {
return commits.filter(filter).map((commit) => {
const { message } = commit
const match = message.match(regex)

Expand All @@ -56,7 +57,7 @@ function formatCommits(commits, filter = commit => commit) {
date: commit.date,
message: message,
package: match ? match[1].toLowerCase() : '',
text: match ? message.replace(match[0], '').trim() : ''
text: match ? message.replace(match[0], '').trim() : '',
}
})
}
Expand All @@ -66,20 +67,27 @@ function formatCommits(commits, filter = commit => commit) {
try {
// const commits = await getCommitsSince('4ac1e7a')
const commits = await getCommitsSinceLatestTag()
const formattedCommits = formatCommits(commits, commit => {
const formattedCommits = formatCommits(commits, (commit) => {
return moduleRegex.test(commit.message)
}).reduce((acc, commit) => {
if (!commit.package) throw new Error('No package found in commit message: ' + commit.message)
if (!acc[commit.package]) {
acc[commit.package] = []
}
acc[commit.package].push(
`- ${commit.text} ([${commit.hash.slice(0, 7)}](https://github.com/Meqn/pipflow/commit/${commit.hash}))`
`- ${commit.text} ([${commit.hash.slice(0, 7)}](https://github.com/Meqn/pipflow/commit/${
commit.hash
}))`
)
return acc
}, {})
console.log('Commit messages:', formatCommits(commits).map(commit => commit.message))
console.log('Commits:', formattedCommits)
console.log(
'Commit messages:',
formatCommits(commits).map((commit) => commit.message)
)
Object.entries(formattedCommits).forEach(([key, value]) => {
log.tag.warn('\n' + value.join('\n'), key)
})
} catch (error) {
console.error('error:', error.message)
}
Expand Down

0 comments on commit ce31c57

Please sign in to comment.