mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 04:45:02 +00:00
Automod: add include_words/exclude_words and include_regex/exclude_regex to match_links trigger
This commit is contained in:
parent
e67816ec7b
commit
b30df3f8d4
3 changed files with 57 additions and 13 deletions
|
@ -390,18 +390,21 @@ export async function findRelevantAuditLogEntry(
|
|||
const urlRegex = /(\S+\.\S+)/g;
|
||||
const protocolRegex = /^[a-z]+:\/\//;
|
||||
|
||||
export function getUrlsInString(str: string, unique = false): url.URL[] {
|
||||
interface MatchedURL extends url.URL {
|
||||
input: string;
|
||||
}
|
||||
|
||||
export function getUrlsInString(str: string, unique = false): MatchedURL[] {
|
||||
let matches = str.match(urlRegex) || [];
|
||||
if (unique) matches = Array.from(new Set(matches));
|
||||
|
||||
return matches.reduce((urls, match) => {
|
||||
if (!protocolRegex.test(match)) {
|
||||
match = `https://${match}`;
|
||||
}
|
||||
const withProtocol = protocolRegex.test(match) ? match : `https://${match}`;
|
||||
|
||||
let matchUrl: url.URL;
|
||||
let matchUrl: MatchedURL;
|
||||
try {
|
||||
matchUrl = new url.URL(match);
|
||||
matchUrl = new url.URL(withProtocol) as MatchedURL;
|
||||
matchUrl.input = match;
|
||||
} catch (e) {
|
||||
return urls;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue