This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
feat(dev): add changelog check into pre-commit #7377
Closed
Closed
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7ba06d7
add changelog tests in pre-commit
whitemoshui 0840d4e
switch to js scripts
whitemoshui b921d4f
remove yellow color
whitemoshui 61f83d8
update the note of the PR template
whitemoshui 9182369
Merge branch '4.x' into fix-7219-add-changelog-check
whitemoshui d60117f
Merge branch '4.x' into fix-7219-add-changelog-check
whitemoshui 88d4f40
refine log
whitemoshui fdc67e9
Merge branch '4.x' into fix-7219-add-changelog-check
whitemoshui e9f8f08
just check ts/json and exclude test files
whitemoshui c48f5ce
Merge branch '4.x' into fix-7219-add-changelog-check
whitemoshui b2dc1a7
Merge branch '4.x' into fix-7219-add-changelog-check
whitemoshui 6b448d3
Merge branch '4.x' into fix-7219-add-changelog-check
Muhammad-Altabba d36991e
support --skip-changelog
whitemoshui 64bd3ad
support --skip-changelog
whitemoshui 5e63587
support --skip-changelog
whitemoshui 7895796
update Contributing.md --sc
whitemoshui abb48c1
recover pre-commit
whitemoshui ea7013b
Merge branch '4.x' into fix-7219-add-changelog-check
whitemoshui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
|
||
npm run check-changelog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const { execSync } = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
// Colors for output | ||
const colors = { | ||
red: text => `\x1b[31m${text}\x1b[0m`, | ||
green: text => `\x1b[32m${text}\x1b[0m`, | ||
}; | ||
|
||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @whitemoshui There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me have a try |
||
// Get all staged files | ||
const stagedFiles = execSync('git diff --cached --name-only', { encoding: 'utf-8' }) | ||
.trim() | ||
.split('\n') | ||
.filter(Boolean); | ||
|
||
// Initialize map to track packages with code changes and changelog updates | ||
const packagesWithChanges = new Map(); | ||
|
||
// Scan all staged files | ||
stagedFiles.forEach(file => { | ||
// Get package name | ||
const packageMatch = file.match(/packages\/([^/]+)/); | ||
if (!packageMatch) return; | ||
|
||
const packageName = packageMatch[1]; | ||
|
||
// Check if it's a code file | ||
const isCodeFile = /\.(js|jsx|ts|tsx|css|json)$/.test(file); | ||
whitemoshui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// Check if it's a changelog file | ||
const isChangelog = file.endsWith('CHANGELOG.md'); | ||
|
||
if (!packagesWithChanges.has(packageName)) { | ||
packagesWithChanges.set(packageName, { | ||
hasCodeChanges: false, | ||
hasChangelogUpdate: false, | ||
}); | ||
} | ||
|
||
const packageInfo = packagesWithChanges.get(packageName); | ||
|
||
if (isCodeFile && !isChangelog) { | ||
packageInfo.hasCodeChanges = true; | ||
} | ||
|
||
if (isChangelog) { | ||
packageInfo.hasChangelogUpdate = true; | ||
} | ||
}); | ||
|
||
// Check if packages with code changes have changelog updates | ||
let hasError = false; | ||
|
||
for (const [packageName, info] of packagesWithChanges) { | ||
if (info.hasCodeChanges) { | ||
if (!info.hasChangelogUpdate) { | ||
console.log( | ||
colors.red( | ||
`Error: Package '${packageName}' has code changes but no CHANGELOG.md update`, | ||
), | ||
); | ||
hasError = true; | ||
} else { | ||
console.log( | ||
colors.green( | ||
`✓ Package '${packageName}' has both code changes and CHANGELOG.md update`, | ||
), | ||
); | ||
} | ||
} | ||
} | ||
|
||
if (hasError) { | ||
console.log( | ||
colors.red( | ||
'\nCommit rejected: Please update packages/web3-xxx/CHANGELOG.md for all modified packages', | ||
luu-alex marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
), | ||
); | ||
process.exit(1); | ||
} else if (packagesWithChanges.size > 0) { | ||
console.log(colors.green('\nAll package changes have corresponding changelog updates')); | ||
} | ||
} catch (error) { | ||
console.error(colors.red('Error executing script:'), error); | ||
// Skip this check and return 0 if something goes wrong | ||
process.exit(0); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These spaces are added automatically by the check