ensure both changeset short link matchers are using the same regex

This commit is contained in:
Sebastian Sdorra
2020-07-02 11:30:26 +02:00
parent 3a393f6238
commit e08f2f2260
2 changed files with 19 additions and 17 deletions

View File

@@ -79,6 +79,7 @@ export { default as CardColumn } from "./CardColumn";
export { default as CardColumnSmall } from "./CardColumnSmall"; export { default as CardColumnSmall } from "./CardColumnSmall";
export { default as CommaSeparatedList } from "./CommaSeparatedList"; export { default as CommaSeparatedList } from "./CommaSeparatedList";
export { default as SplitAndReplace, Replacement } from "./SplitAndReplace"; export { default as SplitAndReplace, Replacement } from "./SplitAndReplace";
export { regExpPattern as changesetShortLinkRegex } from "./remarkChangesetShortLinkParser";
export { default as comparators } from "./comparators"; export { default as comparators } from "./comparators";

View File

@@ -25,26 +25,27 @@
import React from "react"; import React from "react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { Changeset } from "@scm-manager/ui-types"; import { Changeset } from "@scm-manager/ui-types";
import { Replacement } from "@scm-manager/ui-components"; import { Replacement, changesetShortLinkRegex } from "@scm-manager/ui-components";
const ChangesetShortLink: (changeset: Changeset, value: string) => Replacement[] = (changeset, value) => { const ChangesetShortLink: (changeset: Changeset, value: string) => Replacement[] = (changeset, value) => {
const linkRegExp = "([A-Za-z0-9\.\-_]+)\/([A-Za-z0-9\.\-_]+)@([a-f0-9]+)"; const regex = new RegExp(changesetShortLinkRegex, "g")
const matches = value.match(new RegExp(linkRegExp, "g"));
if (!matches) { const replacements: Replacement[] = [];
return [];
} let m = regex.exec(value);
return matches.map(value => { while (m) {
const groups = value.match(new RegExp(linkRegExp)); const namespace = m[1];
const namespace = groups[1]; const name = m[2];
const name = groups[2]; const revision = m[3];
const revision = groups[3]; const link = `/repo/${namespace}/${name}/code/changeset/${revision}`;
const link = `/repo/${namespace}/${name}/changeset/${revision}`; replacements.push({
const replacement: Replacement = { textToReplace: m[0],
textToReplace: value, replacement: <Link to={link}>{m[0]}</Link>
replacement: <Link to={link}>{value}</Link>
};
return replacement;
}); });
m = regex.exec(value);
}
return replacements;
}; };
export default ChangesetShortLink; export default ChangesetShortLink;