Skip to content

Commit

Permalink
[fix] Fix check-changelog script
Browse files Browse the repository at this point in the history
It needs an update since the repository name has changed in favor of
sirius-web

Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
  • Loading branch information
gcoutable committed Aug 16, 2023
1 parent c9344e8 commit 964e832
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions scripts/check-changelog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -10,8 +10,8 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
const childProcess = require('child_process');
const fs = require('fs');
const childProcess = require("child_process");
const fs = require("fs");

const workspace = process.env.GITHUB_WORKSPACE;
const event = process.env.GITHUB_EVENT;
Expand All @@ -21,36 +21,43 @@ const baseSHA = body.pull_request.base.sha;
const headSHA = body.pull_request.head.sha;

const gitLogCommand = `git log --format=format:%H ${baseSHA}..${headSHA}`;
const result = childProcess.execSync(gitLogCommand, { encoding: 'utf8' });
const result = childProcess.execSync(gitLogCommand, { encoding: "utf8" });
const lines = result.split(/\r?\n/);

console.log('The following commits will be reviewed:')
console.log("The following commits will be reviewed:");
console.log(lines);
console.log();

const changelog = fs.readFileSync(`${workspace}/CHANGELOG.adoc`, { encoding: 'utf8' });
const changelog = fs.readFileSync(`${workspace}/CHANGELOG.adoc`, {
encoding: "utf8",
});

const invalidContent = changelog.includes('<<<<<<<') || changelog.includes('=======') || changelog.includes('>>>>>>>');
const invalidContent =
changelog.includes("<<<<<<<") ||
changelog.includes("=======") ||
changelog.includes(">>>>>>>");

const missingIssuesInChangelog = [];
for (let index = 0; index < lines.length; index++) {
const line = lines[index];
const gitShowCommand = `git rev-list --format=%B --max-count=1 ${line}`;
const commitMessage = childProcess.execSync(gitShowCommand, { encoding: 'utf8' });
const commitMessage = childProcess.execSync(gitShowCommand, {
encoding: "utf8",
});
const commitMessageLines = commitMessage.split(/\r?\n/);

if (commitMessageLines.length > 1) {
// Skip the first line which only contains the hash of the commit
const title = commitMessageLines[1];
const tagStartIndex = title.indexOf('[');
const tagEndIndex = title.indexOf(']', tagStartIndex);

const tagStartIndex = title.indexOf("[");
const tagEndIndex = title.indexOf("]", tagStartIndex);
if (tagStartIndex >= 0 && tagStartIndex < tagEndIndex) {
const tag = title.substring(tagStartIndex + '['.length, tagEndIndex);
const tag = title.substring(tagStartIndex + "[".length, tagEndIndex);

const tagAsNumber = Number(tag);
if (!isNaN(tagAsNumber)) {
const issueURL = `https://github.com/eclipse-sirius/sirius-components/issues/${tagAsNumber}`;
const issueURL = `https://github.com/eclipse-sirius/sirius-web/issues/${tagAsNumber}`;

if (!changelog.includes(issueURL)) {
missingIssuesInChangelog.push(issueURL);
Expand All @@ -61,10 +68,14 @@ for (let index = 0; index < lines.length; index++) {
}

if (missingIssuesInChangelog.length > 0) {
console.log('The following issues should appear in the CHANGELOG with some documentation');
console.log(
"The following issues should appear in the CHANGELOG with some documentation"
);
console.log(missingIssuesInChangelog);
process.exit(1);
} else if (invalidContent) {
console.log('The CHANGELOG seems to contain Git conflict markers like "<<<<<<<", "=======" or ">>>>>>>"')
console.log(
'The CHANGELOG seems to contain Git conflict markers like "<<<<<<<", "=======" or ">>>>>>>"'
);
process.exit(1);
}
}

0 comments on commit 964e832

Please sign in to comment.