Skip to content

Commit 9e0c9ab

Browse files
committed
Fix discord message integration
1 parent 09e5729 commit 9e0c9ab

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

AzureDevopsTracker/AzureDevopsTracker.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<PackageLicenseFile>LICENSE.md.txt</PackageLicenseFile>
1919
<Description>A NuGet that allows you to use a Azure DevOps Service Hook to track workitems changes in a simply and detailed way.</Description>
2020
<AssemblyVersion>5.0.0.0</AssemblyVersion>
21-
<FileVersion>5.0.2</FileVersion>
22-
<Version>5.0.2</Version>
21+
<FileVersion>5.0.3</FileVersion>
22+
<Version>5.0.3</Version>
2323
<PackageReleaseNotes>Add ChangeLog Feature</PackageReleaseNotes>
2424
</PropertyGroup>
2525

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
2+
using System.Text.RegularExpressions;
43

54
namespace AzureDevopsTracker.Helpers
65
{
76
internal static class RawTextHelper
87
{
8+
public static string HtmlToRawText(this string source)
9+
{
10+
source = source.Replace("</div>", "\n");
11+
source = source.Replace("<li>", "\n• ");
12+
source = Regex.Replace(source, "<.*?>|&.*?;", string.Empty, RegexOptions.Compiled, TimeSpan.FromMilliseconds(250));
13+
source = source.Trim().EndsWith(".") ? source[0..^1] : source.Trim();
14+
15+
return source;
16+
}
917
}
1018
}

AzureDevopsTracker/Integrations/DiscordIntegration.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using AzureDevopsTracker.Entities;
2+
using AzureDevopsTracker.Helpers;
3+
using AzureDevopsTracker.Statics;
24
using Newtonsoft.Json;
35
using System;
46
using System.Collections.Generic;
@@ -101,11 +103,14 @@ private IEnumerable<Field> GetText(ChangeLog changeLog)
101103

102104
var listFields = new List<Field>();
103105

104-
var features = changeLogItemsAgrupado.Where(x => !x.Key.Equals("bug")).SelectMany(x => x).Select(x => x).ToList();
105-
var bugFixes = changeLogItemsAgrupado.Where(x => x.Key.Equals("bug")).SelectMany(x => x).Select(x => x).ToList();
106+
var features = changeLogItemsAgrupado.Where(x => !x.Key.Equals(WorkItemStatics.WORKITEM_TYPE_BUG)).SelectMany(x => x).Select(x => x).ToList();
107+
var bugFixes = changeLogItemsAgrupado.Where(x => x.Key.Equals(WorkItemStatics.WORKITEM_TYPE_BUG)).SelectMany(x => x).Select(x => x).ToList();
106108

107-
listFields.Add(new Field() { Name = "Atualizações", Value = string.Join("\n", features.Select(d => string.Format(" {0} - {1}.", d.WorkItemId, d.Description))), IsInline = false });
108-
listFields.Add(new Field() { Name = "Correções", Value = string.Join("\n", bugFixes.Select(d => string.Format(" {0} - {1}.", d.WorkItemId, d.Description))), IsInline = false });
109+
if (features.Any())
110+
listFields.Add(new Field() { Name = "Atualizações", Value = string.Join("\n", features.Select(d => string.Format("\n{0} - {1}", d.WorkItemId, d.Description.HtmlToRawText()))), IsInline = false });
111+
112+
if (bugFixes.Any())
113+
listFields.Add(new Field() { Name = "Correções", Value = string.Join("\n", bugFixes.Select(d => string.Format("\n{0} - {1}", d.WorkItemId, d.Description.HtmlToRawText()))), IsInline = false });
109114

110115
return listFields;
111116
}

AzureDevopsTracker/Statics/WorkItemStatics.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace AzureDevopsTracker.Statics
1+
namespace AzureDevopsTracker.Statics
62
{
73
internal class WorkItemStatics
84
{

0 commit comments

Comments
 (0)