-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoftTeamsIntegration.cs
More file actions
107 lines (92 loc) · 3.95 KB
/
MicrosoftTeamsIntegration.cs
File metadata and controls
107 lines (92 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using AzureDevopsTracker.Entities;
using AzureDevopsTracker.Statics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AzureDevopsTracker.Integrations
{
internal class MicrosoftTeamsIntegration : MessageIntegration
{
internal class MicrosoftTeamsMessage
{
public string type { get; set; }
public string context { get; set; }
public string themeColor { get; set; }
public string summary { get; set; }
public string priority { get; set; }
public Section[] sections { get; set; }
}
internal class Section
{
public string activityTitle { get; set; }
public string activitySubtitle { get; set; }
public string activityImage { get; set; }
public string text { get; set; }
public bool markdown { get; set; }
}
internal static class MicrosoftTeamsStatics
{
internal static readonly string Type = "MessageCard";
internal static readonly string Context = "http://schema.org/extensions";
internal static readonly string ThemeColor = "7bd1d7";
internal static readonly int TEXT_SIZE_TO_BREAK_LINE = 100;
internal static readonly int OPENING_DIV_SIZE = 5;
internal static readonly int CLOSING_DIV_SIZE = 6;
}
internal override async Task Send(ChangeLog changeLog)
{
var values = new MicrosoftTeamsMessage()
{
type = MicrosoftTeamsStatics.Type,
context = MicrosoftTeamsStatics.Context,
themeColor = MicrosoftTeamsStatics.ThemeColor,
summary = GetTitle(),
sections = new Section[1]
{
new Section()
{
activityTitle = GetTitle(),
activitySubtitle = GetVersion(changeLog),
activityImage = GetAnnouncementImageUrl(),
text = GetText(changeLog),
markdown = true
}
}
};
await Notify(values);
}
private static string GetText(ChangeLog changeLog)
{
if (changeLog is null || !changeLog.ChangeLogItems.Any()) return string.Empty;
StringBuilder text = new();
text.AppendLine(GetWorkItemsDescriptionSection("Features", changeLog.ChangeLogItems.Where(x => x.WorkItemType != WorkItemStatics.WORKITEM_TYPE_BUG)));
text.AppendLine(GetWorkItemsDescriptionSection("Correções", changeLog.ChangeLogItems.Where(x => x.WorkItemType == WorkItemStatics.WORKITEM_TYPE_BUG)));
text.AppendLine(GetFooter());
return text.ToString();
}
private static string GetWorkItemsDescriptionSection(string sectionName, IEnumerable<ChangeLogItem> changeLogItems)
{
StringBuilder text = new();
if (!changeLogItems.Any()) return string.Empty;
text.AppendLine($"\n# **{sectionName}**\n");
foreach (var workItem in changeLogItems)
text.AppendLine(GetWorkItemDescriptionLine(workItem));
text.AppendLine("\n");
return text.ToString();
}
private static string GetWorkItemDescriptionLine(ChangeLogItem workItem)
{
var description = GetDescription(workItem.Description);
return $"<em>**{workItem.WorkItemId}**</em> - {description} <br>";
}
private static string GetDescription(string description)
{
return description.Replace("<div>", "").Replace("</div>", "").Replace("<br>", "");
}
private static string GetFooter()
{
return $"<br><sup> <img style='width: 16px; height: 16px;' src='{GetLogoTypingHard16x16Url()}' /> {GetNugetVersion()}</sup>";
}
}
}