Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for trailing spaces on separator #175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't include additional editor settings files

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"coverage-gutters.coverageReportFileName": ".qodana/**/lcov.info"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ As an example with the separator `:` the following is allowed
AB-1:Initialize Project
```

Note that by specifying a separator the following would not be allowed
Note that to trailing spaces must be explicitly declared with the separator. For example, with the separator `:` the following is not allowed, but with the separator `: ` 
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the grammar in this documentation


```
AB-1: Initialize Project
Expand Down
149 changes: 139 additions & 10 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe("index", () => {
] = "false";
const regex = getRegex();
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(new RegExp(`(^AB-){1}(\\d)+(:)+(\\S)+(.)+`));
expect(regex[0]).toEqual(new RegExp(`(^AB-){1}(\\d)+:(\\S)+(.)+`));
expect(regex[0].test("AB-43: stuff and things")).toBe(false);
expect(regex[0].test("AB-123: PR Title")).toBe(false);
expect(regex[0].test("AB-43:stuff and things")).toBe(true);
Expand All @@ -100,7 +100,7 @@ describe("index", () => {
] = "false";
const regex = getRegex();
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(new RegExp(`(^AB-){1}(\\d)+(_)+(\\S)+(.)+`));
expect(regex[0]).toEqual(new RegExp(`(^AB-){1}(\\d)+_(\\S)+(.)+`));
expect(regex[0].test("AB-43_stuff and things")).toBe(true);
expect(regex[0].test("AB-123_PR Title")).toBe(true);
});
Expand Down Expand Up @@ -130,9 +130,7 @@ describe("index", () => {
] = "true";
const regex = getRegex();
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(
new RegExp(`(.)*(AB-){1}(\\d)+(:)+(\\S)+(.)+`),
);
expect(regex[0]).toEqual(new RegExp(`(.)*(AB-){1}(\\d)+:(\\S)+(.)+`));
expect(regex[0].test("other words AB-43: stuff and things")).toBe(
false,
);
Expand Down Expand Up @@ -182,7 +180,7 @@ describe("index", () => {
const regexes = getRegex();
expect(regexes.length).toEqual(1);
const regex = regexes[0];
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+(:)+(\\S)+(.)+`));
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+:(\\S)+(.)+`));
expect(regex.test("AB-43: stuff and things")).toBe(false);
expect(regex.test("AB-123: PR Title")).toBe(false);
expect(regex.test("AB-43:stuff and things")).toBe(true);
Expand All @@ -202,7 +200,7 @@ describe("index", () => {
const regexes = getRegex();
expect(regexes.length).toEqual(1);
const regex = regexes[0];
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+(_)+(\\S)+(.)+`));
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+_(\\S)+(.)+`));
expect(regex.test("AB-43_stuff and things")).toBe(true);
expect(regex.test("AB-123_PR Title")).toBe(true);
});
Expand Down Expand Up @@ -242,7 +240,7 @@ describe("index", () => {
const regexes = getRegex();
expect(regexes.length).toEqual(1);
const regex = regexes[0];
expect(regex).toEqual(new RegExp(`(.)*(AB-){1}(\\d)+(:)+(\\S)+(.)+`));
expect(regex).toEqual(new RegExp(`(.)*(AB-){1}(\\d)+:(\\S)+(.)+`));
expect(regex.test("other words AB-43: stuff and things")).toBe(false);
expect(regex.test("other words AB-123: PR Title")).toBe(false);
expect(regex.test("other words AB-43:stuff and things")).toBe(true);
Expand All @@ -265,7 +263,7 @@ describe("index", () => {
const regexCollection = getRegex();
regexCollection.forEach((regex: RegExp, index: number) => {
expect(regex).toEqual(
new RegExp(`(^${projectNames[index]}-){1}(\\d)+(:)+(\\S)+(.)+`),
new RegExp(`(^${projectNames[index]}-){1}(\\d)+:(\\S)+(.)+`),
);
expect(
regex.test(`${projectNames[index]}-43: stuff and things`),
Expand Down Expand Up @@ -294,7 +292,7 @@ describe("index", () => {
const regexCollection = getRegex();
regexCollection.forEach((regex: RegExp, index: number) => {
expect(regex).toEqual(
new RegExp(`(^${projectNames[index]}-){1}(\\d)+(:)+(\\S)+(.)+`),
new RegExp(`(^${projectNames[index]}-){1}(\\d)+:(\\S)+(.)+`),
);
expect(
regex.test(`${projectNames[index]}-43: stuff and things`),
Expand Down Expand Up @@ -379,5 +377,136 @@ describe("index", () => {
});
});
});

describe("when a separator with a trailing space is provided", () => {
beforeEach(() => resetEnvironmentVariables());

it("uses a project key and a colon separator with a trailing space if they exist", () => {
process.env[
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = "AB";
process.env[
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = ": ";
process.env[
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}`
] = "false";
const regex = getRegex();
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(new RegExp(`(^AB-){1}(\\d)+: (\\S)+(.)+`));
expect(regex[0].test("AB-43: stuff and things")).toBe(true);
expect(regex[0].test("AB-123: PR Title")).toBe(true);
expect(regex[0].test("AB-43:stuff and things")).toBe(false);
});

it("uses a project key and an underscore separator with a trailing space if they exist", () => {
process.env[
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = "AB";
process.env[
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = "_ ";
process.env[
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}`
] = "false";
const regex = getRegex();
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(new RegExp(`(^AB-){1}(\\d)+_ (\\S)+(.)+`));
expect(regex[0].test("AB-43_ stuff and things")).toBe(true);
expect(regex[0].test("AB-123_ PR Title")).toBe(true);
expect(regex[0].test("AB-43_stuff and things")).toBe(false);
});

it("uses a project key and a colon separator with a trailing space if they exist anywhere in the title", () => {
process.env[
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = "AB";
process.env[
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = ": ";
process.env[
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}`
] = "true";
const regex = getRegex();
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(new RegExp(`(.)*(AB-){1}(\\d)+: (\\S)+(.)+`));
expect(regex[0].test("other words AB-43: stuff and things")).toBe(true);
expect(regex[0].test("other words AB-123: PR Title")).toBe(true);
expect(regex[0].test("other words AB-43:stuff and things")).toBe(false);
});

it("uses a project key and an underscore separator with a trailing space if they exist anywhere in the title", () => {
process.env[
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = "AB";
process.env[
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = "_ ";
process.env[
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}`
] = "true";
const regex = getRegex();
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(new RegExp(`(.)*(AB-){1}(\\d)+_ (\\S)+(.)+`));
expect(regex[0].test("other words AB-43_ stuff and things")).toBe(true);
expect(regex[0].test("other words AB-123_ PR Title")).toBe(true);
expect(regex[0].test("other words AB-43_stuff and things")).toBe(false);
});

it("uses a project key with multiple keys and a separator with a trailing space", () => {
const projectNames: string[] = ["AB", "CD", "EF", "GH"];
process.env[
`INPUT_${projectKeysInputName.replace(/ /g, "_").toUpperCase()}`
] = "AB\nCD\nEF\nGH";
process.env[
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = ": ";
process.env[
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}`
] = "false";
const regexCollection = getRegex();
regexCollection.forEach((regex: RegExp, index: number) => {
expect(regex).toEqual(
new RegExp(`(^${projectNames[index]}-){1}(\\d)+: (\\S)+(.)+`),
);
expect(
regex.test(`${projectNames[index]}-43: stuff and things`),
).toBe(true);
expect(regex.test(`${projectNames[index]}-123: PR Title`)).toBe(true);
expect(regex.test(`${projectNames[index]}-43:stuff and things`)).toBe(
false,
);
});
});

it("uses a project key with multiple keys and a separator with a trailing space anywhere in the title", () => {
const projectNames: string[] = ["AB", "CD", "EF"];
process.env[
`INPUT_${projectKeysInputName.replace(/ /g, "_").toUpperCase()}`
] = "AB\nCD\nEF";
process.env[
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}`
] = ": ";
process.env[
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}`
] = "true";
const regexCollection = getRegex();
regexCollection.forEach((regex: RegExp, index: number) => {
expect(regex).toEqual(
new RegExp(`(.)*(${projectNames[index]}-){1}(\\d)+: (\\S)+(.)+`),
);
expect(
regex.test(
`other words ${projectNames[index]}-43: stuff and things`,
),
).toBe(true);
expect(
regex.test(
`other words ${projectNames[index]}-43:stuff and things`,
),
).toBe(false);
});
});
});
});
});
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inputs:
description: 'A list of Jira Project Keys that must be included.'
required: false
separator:
description: 'Character that should be used to separate the Jira Project Key and Issue Number from the rest of the title'
description: 'String that should be used to separate the Jira Project Key and Issue Number from the rest of the title'
required: false
keyAnywhereInTitle:
description: 'Allows the Jira Project Key and Issue Number to be anywhere in the title'
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not commit build files, I build the project before releases.

Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ const getRegex = () => {
const projectKeysInput = core.getMultilineInput("projectKeys", {
required: false,
});
const separator = core.getInput("separator", { required: false });
const separator = core.getInput("separator", {
required: false,
trimWhitespace: false,
});
const keyAnywhereInTitle = core.getBooleanInput("keyAnywhereInTitle", {
required: false,
});
core.debug(`Project Key ${projectKeyInput}`);
core.debug(`Project Keys ${projectKeysInput}`);
core.debug(`Separator ${separator}`);
core.debug(`Separator "${separator}"`);
core.debug(`Key Anywhere In Title ${keyAnywhereInTitle}`);
if (stringIsNullOrWhitespace(projectKeyInput) && projectKeysInput.length < 1)
return [getDefaultJiraIssueRegex()];
Expand Down Expand Up @@ -116,7 +119,7 @@ const getDefaultJiraIssueRegex = () => new RegExp("(?<=^|[a-z]-|[\\s\\p{P}&[^\\-
const isValidProjectKey = (projectKey) => /(?<=^|[a-z]-|[\s\p{P}&[^-])([A-Z][A-Z0-9_]*)/u.test(projectKey);
const getRegexWithProjectKeyAndKeyAnywhereInTitle = (projectKey, keyAnywhereInTitle) => `${keyAnywhereInTitle ? "(.)*" : ""}(${keyAnywhereInTitle ? "" : "^"}${projectKey}-){1}`;
const getRegexWithProjectKey = (projectKey, keyAnywhereInTitle) => new RegExp(`${getRegexWithProjectKeyAndKeyAnywhereInTitle(projectKey, keyAnywhereInTitle)}(\\d)+(\\s)+(.)+`);
const getRegexWithProjectKeyAndSeparator = (projectKey, separator, keyAnywhereInTitle) => new RegExp(`${getRegexWithProjectKeyAndKeyAnywhereInTitle(projectKey, keyAnywhereInTitle)}(\\d)+(${separator})+(\\S)+(.)+`);
const getRegexWithProjectKeyAndSeparator = (projectKey, separator, keyAnywhereInTitle) => new RegExp(`${getRegexWithProjectKeyAndKeyAnywhereInTitle(projectKey, keyAnywhereInTitle)}(\\d)+${separator}(\\S)+(.)+`);
const stringIsNullOrWhitespace = (str) => str == null || str.trim() === "";
//# sourceMappingURL=main.js.map

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not commit build files, I build the project before releases.

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/main.js
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not commit build files, I build the project before releases.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading