Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions @commitlint/rules/src/signed-off-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Signed-off-by:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
`,

withSignoffAndCherryPick: `test: subject

message body

Signed-off-by:

(cherry picked from commit 1234567aB)
`,
Comment thread
mzedel marked this conversation as resolved.
};

Expand All @@ -26,6 +35,7 @@ const parsed = {
inSubject: parse(messages.inSubject),
inBody: parse(messages.inBody),
withSignoffAndComments: parse(messages.withSignoffAndComments),
withSignoffAndCherryPick: parse(messages.withSignoffAndCherryPick),
};

test('empty against "always signed-off-by" should fail', async () => {
Expand Down Expand Up @@ -109,3 +119,23 @@ test('inBody against "never signed-off-by" should succeed', async () => {
const expected = true;
expect(actual).toEqual(expected);
});

test("cherry pick marker should be ignored", async () => {
const [actual] = signedOffBy(
await parsed.withSignoffAndCherryPick,
"always",
"Signed-off-by:",
);
const expected = true;
expect(actual).toEqual(expected);
});
Comment thread
mzedel marked this conversation as resolved.

test('cherry pick marker with "never signed-off-by" should fail', async () => {
const [actual] = signedOffBy(
await parsed.withSignoffAndCherryPick,
"never",
"Signed-off-by:",
);
const expected = false;
expect(actual).toEqual(expected);
});
4 changes: 4 additions & 0 deletions @commitlint/rules/src/signed-off-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import message from "@commitlint/message";
import toLines from "@commitlint/to-lines";
import { SyncRule } from "@commitlint/types";

const CHERRY_PICK_REGEX = /^\(cherry picked from commit [0-9a-f]{7,64}\)$/i;

export const signedOffBy: SyncRule<string> = (
parsed,
when = "always",
Expand All @@ -11,6 +13,8 @@ export const signedOffBy: SyncRule<string> = (
(ln) =>
// skip comments
!ln.startsWith("#") &&
// skip cherry pick commits
!CHERRY_PICK_REGEX.test(ln.trim()) &&
// ignore empty lines
Boolean(ln),
Comment thread
escapedcat marked this conversation as resolved.
);
Expand Down