Skip to content

Commit

Permalink
fix: enforce single line commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
quant-eagle committed Dec 21, 2020
1 parent 9edb02e commit 133266e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6048,12 +6048,25 @@ const createCommitCategories = (mapping) => {
*/
const obtainTemplate = (filePath) => {
if (!filePath) {
return fs.readFileSync(`${workspace}/CHANGELOG.tpl.md`, "utf8");
return fs.readFileSync("CHANGELOG.tpl.md", "utf8");
} else {
return fs.readFileSync(`${workspace}/${templateFilePath}`, "utf8");
}
};

/**
* Given a message as a string, check whether it is a multiline string.
* If so, cut the rest of the string after first new line.
* Else return the string in it's original form.
*/
const createSingleLineMessage = (message) => {
if (message.indexOf("\n") == -1) {
return message;
} else {
return message.substring(0, message.indexOf("\n"));
}
};

/**
* Based on the given version and range of commits for the given version.
*
Expand All @@ -6072,7 +6085,7 @@ const changelogGenerator = (version, commitData) => {
core.info("creating changelog template");
const templateCategories = new Map();
commitData.forEach((val) => {
const commit = val.commit.message;
const commit = createSingleLineMessage(val.commit.message);
const category = categories.find((value) => {
if (commit.indexOf(value.type) != -1) {
return value;
Expand Down
17 changes: 15 additions & 2 deletions src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,25 @@ const createCommitCategories = (mapping) => {
*/
const obtainTemplate = (filePath) => {
if (!filePath) {
return fs.readFileSync(`CHANGELOG.tpl.md`, "utf8");
return fs.readFileSync("CHANGELOG.tpl.md", "utf8");
} else {
return fs.readFileSync(`${workspace}/${templateFilePath}`, "utf8");
}
};

/**
* Given a message as a string, check whether it is a multiline string.
* If so, cut the rest of the string after first new line.
* Else return the string in it's original form.
*/
const createSingleLineMessage = (message) => {
if (message.indexOf("\n") == -1) {
return message;
} else {
return message.substring(0, message.indexOf("\n"));
}
};

/**
* Based on the given version and range of commits for the given version.
*
Expand All @@ -52,7 +65,7 @@ const changelogGenerator = (version, commitData) => {
core.info("creating changelog template");
const templateCategories = new Map();
commitData.forEach((val) => {
const commit = val.commit.message;
const commit = createSingleLineMessage(val.commit.message);
const category = categories.find((value) => {
if (commit.indexOf(value.type) != -1) {
return value;
Expand Down

0 comments on commit 133266e

Please sign in to comment.