mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
ensure both changeset short link matchers are using the same regex
This commit is contained in:
@@ -25,26 +25,27 @@
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
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 linkRegExp = "([A-Za-z0-9\.\-_]+)\/([A-Za-z0-9\.\-_]+)@([a-f0-9]+)";
|
||||
const matches = value.match(new RegExp(linkRegExp, "g"));
|
||||
if (!matches) {
|
||||
return [];
|
||||
const regex = new RegExp(changesetShortLinkRegex, "g")
|
||||
|
||||
const replacements: Replacement[] = [];
|
||||
|
||||
let m = regex.exec(value);
|
||||
while (m) {
|
||||
const namespace = m[1];
|
||||
const name = m[2];
|
||||
const revision = m[3];
|
||||
const link = `/repo/${namespace}/${name}/code/changeset/${revision}`;
|
||||
replacements.push({
|
||||
textToReplace: m[0],
|
||||
replacement: <Link to={link}>{m[0]}</Link>
|
||||
});
|
||||
m = regex.exec(value);
|
||||
}
|
||||
return matches.map(value => {
|
||||
const groups = value.match(new RegExp(linkRegExp));
|
||||
const namespace = groups[1];
|
||||
const name = groups[2];
|
||||
const revision = groups[3];
|
||||
const link = `/repo/${namespace}/${name}/changeset/${revision}`;
|
||||
const replacement: Replacement = {
|
||||
textToReplace: value,
|
||||
replacement: <Link to={link}>{value}</Link>
|
||||
};
|
||||
return replacement;
|
||||
});
|
||||
|
||||
return replacements;
|
||||
};
|
||||
|
||||
export default ChangesetShortLink;
|
||||
|
||||
Reference in New Issue
Block a user