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

Regex Fix - #1820 #1821

Merged
merged 6 commits into from
Jan 5, 2023
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
6 changes: 6 additions & 0 deletions src/jira/util/jira-client-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ describe("Jira util", () => {
fields: {
summary: "Fourth Issue"
}
},
{
key: "TEST1-2021",
fields: {
summary: "Fifth Issue"
}
}
];

Expand Down
4 changes: 2 additions & 2 deletions src/jira/util/jira-client-util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { envVars } from "config/env";
import { getLogger } from "config/logger";
import { JiraIssue } from "interfaces/jira";
import { jiraIssueRegex } from "utils/jira-utils";
import { jiraIssueInSquareBracketsRegex } from "utils/jira-utils";

const logger = getLogger("jira.util");

Expand Down Expand Up @@ -33,7 +33,7 @@ export const getJiraUtil = (jiraClient) => {
};

const addJiraIssueLinks = (text: string, issues: JiraIssue[]): string => {
const referenceRegex = jiraIssueRegex();
const referenceRegex = jiraIssueInSquareBracketsRegex();
const issueMap = issues.reduce((acc, issue) => ({
...acc,
[issue.key]: issue
Expand Down
14 changes: 14 additions & 0 deletions src/util/jira-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ export const jiraIssueRegex = (): RegExp => {
return /(^|[^\p{L}\p{Nd}])([\p{L}][\p{L}\p{Nd}_]{1,255}-\p{Nd}{1,255})/giu;
};

/**
* Same as the `jiraIssueRegex`,
* but this Regex captures only those issue keys that are surrounded by square brackets
* This regex is used when adding links to Jira issues in GitHub PR issue/descriptions.
*/
export const jiraIssueInSquareBracketsRegex = (): RegExp => {
if (issueKeyRegexCharLimitFeature) {
return /(^|[^A-Z\d])\[([A-Z][A-Z\d]{1,255}-[1-9]\d{0,255})\]/giu;
} else if (regexFixFeature) {
return /(^|[^A-Z\d])\[([A-Z][A-Z\d]+-[1-9]\d*)\]/giu;
}

return /(^|[^\p{L}\p{Nd}])\[([\p{L}][\p{L}\p{Nd}_]{1,255}-\p{Nd}{1,255})\]/giu;
};

/**
* Parses strings for Jira issue keys for commit messages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Meanwhile these issues shouldn't have links:
- [A11B22-2020]
- [A11B2C33-2021]

And anything not enclosed inside square brackets won't have any links added.
- KEY-2018
- TEST1-2021

[KEY-2018]: http://example.com/browse/KEY-2018
[A1-2019]: http://example.com/browse/A1-2019
[A1B2-2020]: http://example.com/browse/A1B2-2020
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ These issues must have links:
Meanwhile these issues shouldn't have links:
- [A11-2019]
- [A11B22-2020]
- [A11B2C33-2021]
- [A11B2C33-2021]

And anything not enclosed inside square brackets won't have any links added.
- KEY-2018
- TEST1-2021