Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 4d279c5

Browse files
committed
🐛 fix Pipelines for repos with / in name
1 parent 2366e32 commit 4d279c5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/bot.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,25 @@ client.once('ready', () => {
1616
WebhookEvent.on('post', async (post: Message) => {
1717
console.log(post);
1818

19-
const regexInner = `.+(?: \\/ .+)*?(?=]\\(https:\\/\\/gitlab\\.com\\/${process.env.GITLAB_ORG_NAME.toLowerCase()}\\/[a-z\\-\\/]+\\)`;
19+
const regexInner = `.+(?: \\/ .+)*?(?=]\\(https:\\/\\/gitlab\\.com\\/${process.env.GITLAB_ORG_NAME.toLowerCase()}\\/([a-z\\-\\/]+)\\)`;
2020
const regex = new RegExp(`(?<=\\[${process.env.GITLAB_ORG_NAME} / )${regexInner})|(?<=\\[)${regexInner}: Pipeline)`);
2121

2222
const matches = post.embeds[0].description.match(regex);
2323

2424
if (!matches) return;
2525

26-
if (post.embeds[0].description.match(/Pipeline/)) {
26+
matches[0] = matches[0].replace(new RegExp(`${process.env.GITLAB_ORG_NAME} /(?: .*? \\/)* `), '').replace(/\//g, '–');
27+
28+
const urlify = string => string.toLowerCase().replace(/ /g, '-').replace(/-+/g, '-').replace(/-*-*/, '/');
29+
30+
const isPipeline = post.embeds[0].description.match(/Pipeline/);
31+
32+
if (isPipeline) {
2733
if (post.embeds[0].description.match(/passed/)) post.embeds[0].color = 123456;
2834
else if (post.embeds[0].description.match(/failed/)) post.embeds[0].color = 16711680;
35+
matches[0] = urlify(matches[2]);
2936
}
3037

31-
matches[0] = matches[0].replace(new RegExp(`${process.env.GITLAB_ORG_NAME} /(?: .*? \\/)* `), '').replace(/\//g, '–');
32-
3338
const channel = (await client.channels.fetch(
3439
process.env.CHANNEL_ID
3540
)) as TextChannel;
@@ -40,7 +45,7 @@ WebhookEvent.on('post', async (post: Message) => {
4045
(await channel.threads.fetchArchived({ fetchAll: true }, false)).threads
4146
);
4247

43-
let thread = allThreads.find((th) => th.name === matches[0]);
48+
let thread = allThreads.find((th) => (isPipeline ? urlify(th.name) : th.name) === matches[0]);
4449

4550
thread ??= await channel.threads.create({
4651
name: matches[0],

0 commit comments

Comments
 (0)