Skip to content

Commit

Permalink
feat: support multilines commit message
Browse files Browse the repository at this point in the history
* will now allow user to have a commit description
  • Loading branch information
sirily11 committed Feb 19, 2022
1 parent 7cf1f7a commit 13209e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
build
build
.idea
16 changes: 12 additions & 4 deletions src/client/conventional_commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ export class ConventionalCommit {
return { error: "commit message is empty" };
}

const cleanedMessage = this.cleanMessage(message);

// validate the commit message
if (!this.validateMessage(message)) {
if (!this.validateMessage(cleanedMessage)) {
return {
error: `commit message [${message}] does not follow the conventional commit format`,
error: `commit message [${cleanedMessage}] does not follow the conventional commit format`,
};
}

Expand Down Expand Up @@ -107,6 +109,10 @@ export class ConventionalCommit {
return diffLabels;
}

cleanMessage(message: string) {
return message.split("\n")[0];
}

/**
* Validate commit messages based on the conventional commit format.
* The following rules will be applied:
Expand All @@ -127,8 +133,10 @@ export class ConventionalCommit {
}

// if there is only one message, check if it is equal to the title of the PR
if (messages.length === 1 && messages[0] !== title) {
return `commit message [${messages[0]}] does not equal to the title of the PR [${title}]`;
if (messages.length === 1 && this.cleanMessage(messages[0]) !== title) {
return `commit message [${this.cleanMessage(
messages[0]
)}] does not equal to the title of the PR [${title}]`;
}

// check if the commit messages are valid
Expand Down
5 changes: 5 additions & 0 deletions src/tests/covnentioanl_commit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,9 @@ describe("Given a conventional commit client", () => {
"commit message [fi: hello] does not follow the conventional commit format"
);
});

it("Should return no error", () => {
const error = client.validate(["fix: hello\n* a: fix error"], "fix: hello");
expect(error).toBeUndefined();
});
});

0 comments on commit 13209e0

Please sign in to comment.