Skip to content

Commit afbaf92

Browse files
aduh95targos
authored andcommitted
tools: improve release proposal linter
PR-URL: #58647 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Tierney Cyren <hello@bnb.im> Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
1 parent b11da11 commit afbaf92

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

‎tools/actions/lint-release-proposal-commit-list.mjs‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//
66
// Example:
77
// $ git log upstream/vXX.x...upstream/vX.X.X-proposal \
8-
// --format='{"prURL":"%(trailers:key=PR-URL,valueonly,separator=)","title":"%s","smallSha":"%h"}' \
8+
// --reverse --format='{"prURL":"%(trailers:key=PR-URL,valueonly,separator=)","title":"%s","smallSha":"%h"}' \
9+
// | sed 's/,"title":"Revert "\([^"]\+\)""/,"title":"Revert \\"\1\\""/g' \
910
// | ./lint-release-proposal-commit-list.mjs "path/to/CHANGELOG.md" "$(git rev-parse upstream/vX.X.X-proposal)"
1011

1112
const[,,CHANGELOG_PATH,RELEASE_COMMIT_SHA]=process.argv;
@@ -52,20 +53,33 @@ for await (const line of stdinLineByLine) {
5253
assert.notStrictEqual(lineStart,-1,`Cannot find ${smallSha} on the list`);
5354
constlineEnd=commitList.indexOf('\n',lineStart+1);
5455

55-
constcolonIndex=title.indexOf(':');
56-
constexpectedCommitTitle=`${`**${title.slice(0,colonIndex)}`.replace('**Revert "','_**Revert**_ "**')}**${title.slice(colonIndex)}`;
5756
try{
58-
assert(commitList.lastIndexOf(`/${smallSha})] - ${expectedCommitTitle} (`,lineEnd)>lineStart,`Commit title doesn't match`);
57+
constcolonIndex=title.indexOf(':');
58+
constexpectedCommitTitle=`${`**${title.slice(0,colonIndex)}`.replace('**Revert "','_**Revert**_ "**')}**${title.slice(colonIndex)}`;
59+
try{
60+
assert(commitList.lastIndexOf(`/${smallSha})] - ${expectedCommitTitle} (`,lineEnd)>lineStart,`Changelog entry doesn't match for ${smallSha}`);
61+
}catch(e){
62+
if(e?.code==='ERR_ASSERTION'){
63+
e.operator='includes';
64+
e.expected=expectedCommitTitle;
65+
e.actual=commitList.slice(lineStart+1,lineEnd);
66+
}
67+
throwe;
68+
}
69+
assert.strictEqual(commitList.slice(lineEnd-prURL.length-2,lineEnd),`(${prURL})`,`when checking ${smallSha}${title}`);
70+
5971
}catch(e){
60-
if(e?.code==='ERR_ASSERTION'){
61-
e.operator='includes';
62-
e.expected=expectedCommitTitle;
63-
e.actual=commitList.slice(lineStart+1,lineEnd);
72+
if(e?.code!=='ERR_ASSERTION'){
73+
throwe;
6474
}
65-
throwe;
75+
letline=1;
76+
for(leti=0;i<lineStart+commitListingStart;i=changelog.indexOf('\n',i+1)){
77+
line++;
78+
}
79+
console.error(`::error file=${CHANGELOG_PATH},line=${line},title=Release proposal linter::${e.message}`);
80+
console.error(e);
81+
process.exitCode||=1;
6682
}
67-
assert.strictEqual(commitList.slice(lineEnd-prURL.length-2,lineEnd),`(${prURL})`,`when checking ${smallSha}${title}`);
68-
6983
expectedNumberOfCommitsLeft--;
7084
console.log(prURL);
7185
}

0 commit comments

Comments
 (0)