mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
ensure both changeset short link matchers are using the same regex
This commit is contained in:
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user