Skip to content

Commit

Permalink
Fix broken markdown links
Browse files Browse the repository at this point in the history
  • Loading branch information
Bardin08 committed May 10, 2024
1 parent 6e21ee9 commit 606b013
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
12 changes: 12 additions & 0 deletions EduAutomation/Application/Helpers/MarkdownHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.RegularExpressions;

namespace EduAutomation.Application.Helpers;

public static partial class MarkdownHelpers
{
public static string NormalizeLinkText(this string text)
=> BracketsRegex().Replace(text, "");

[GeneratedRegex(@"\[(.*?)\]")]
private static partial Regex BracketsRegex();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using EduAutomation.Application.Helpers;
using EduAutomation.Domain.GitHub.Events;

namespace EduAutomation.Application.Telegram.Formatters;
Expand Down Expand Up @@ -28,10 +29,10 @@ private string GetRepoCreatedCard(RepoCreated? repoCreated, Dictionary<string, s
var builder = new StringBuilder();

builder.AppendLine("**Repo Created**");
builder.AppendLine($"* **Repository:** [{repoCreated.Repo.Name}]({repoCreated.Repo.Url})");
builder.AppendLine($"* **Organization:** [{repoCreated.Org.Name}]({repoCreated.Org.Url})");
builder.AppendLine($"* **Created By:** [{repoCreated.Sender.Login}]({repoCreated.Sender.Url})");
builder.AppendLine($"* **Date:** {DateTime.Now.ToString("MMMM dd, yyyy")}");
builder.AppendLine($"**Repository:** [{repoCreated.Repo.Name}]({repoCreated.Repo.Url})");
builder.AppendLine($"**Organization:** [{repoCreated.Org.Name}]({repoCreated.Org.Url})");
builder.AppendLine($"**Created By:** [{repoCreated.Sender.Login.NormalizeLinkText()}]({repoCreated.Sender.Url})");
builder.AppendLine($"**Date:** {DateTime.Now.ToString("MMMM dd, yyyy")}");

TryAddAssignees(builder, paramsBag);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using EduAutomation.Application.Helpers;
using EduAutomation.Domain.GitHub.Events;
using EduAutomation.Domain.Trello;

Expand Down Expand Up @@ -42,7 +43,7 @@ private TrelloCard GetRepoCreatedCard(RepoCreated? e, Dictionary<string, string>
// Organization and Creator
builder.AppendLine("**Organization and Creator**");
builder.AppendLine($"- **Organization:** [{e.Org.Name}](https://github.com/{e.Org.Name})");
builder.AppendLine($"- **Creator:** [{NormalizedSenderLogin(e)}]({e.Sender.Url})");
builder.AppendLine($"- **Creator:** [{e.Sender.Login.NormalizeLinkText()}]({e.Sender.Url})");
builder.AppendLine();

// Assignment
Expand Down Expand Up @@ -84,9 +85,4 @@ private static void TryAddMentor(StringBuilder builder, Dictionary<string, strin
builder.AppendLine($"**Mentor:** {mentorName}");
}
}

private string NormalizedSenderLogin(RepoCreated? e)
{
return e.Sender.Login.Replace("[bot]", "_bot");
}
}

0 comments on commit 606b013

Please sign in to comment.