Skip to content

Commit e58eec9

Browse files
committed
Generate Discord message
1 parent a76c710 commit e58eec9

File tree

3 files changed

+112
-22
lines changed

3 files changed

+112
-22
lines changed
Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,113 @@
11
using AzureDevopsTracker.Entities;
2+
using Newtonsoft.Json;
23
using System;
34
using System.Collections.Generic;
4-
using System.Text;
5+
using System.Linq;
56

67
namespace AzureDevopsTracker.Integrations
78
{
89
internal class DiscordIntegration : MessageIntegration
910
{
1011
internal override void Send(ChangeLog changeLog)
1112
{
12-
//Formatar o texto com o MarkdownHelper
13+
var embedsDTO = new EmbedsDTO
14+
{
15+
Embeds = new List<Embed>
16+
{
17+
new Embed()
18+
{
19+
Author = new Author() { Name = $"{GetTitle()} - {GetVersion(changeLog)} \nData: {DateTime.Now:dd/MM/yyyy}" },
20+
Footer = new Footer() { Text = $"Powered by Typing Hard • nuget version {GetNugetVersion()}", IconUrl = GetLogoTypingHard16x16Url() },
21+
Thumbnail = new Thumbnail() { Url = GetAnnouncementImageUrl() },
22+
Fields = GetText(changeLog)
23+
}
24+
},
25+
};
1326

14-
//Faz o Post com a URL
15-
var url = MessageConfig.URL;
27+
Notify(embedsDTO);
28+
}
29+
30+
public class EmbedsDTO
31+
{
32+
public EmbedsDTO()
33+
{
34+
Embeds = new List<Embed>();
35+
}
36+
37+
[JsonProperty("embeds")]
38+
public IEnumerable<Embed> Embeds { get; set; }
39+
}
40+
41+
public class Embed
42+
{
43+
[JsonProperty("author")]
44+
public Author Author { get; set; }
45+
46+
[JsonProperty("footer")]
47+
public Footer Footer { get; set; }
48+
49+
[JsonProperty("thumbnail")]
50+
public Thumbnail Thumbnail { get; set; }
51+
52+
[JsonProperty("Description")]
53+
public string Description { get; set; }
54+
55+
[JsonProperty("title")]
56+
public string Title { get; set; }
57+
58+
[JsonProperty("color")]
59+
public ulong? Color { get; set; }
60+
61+
[JsonProperty("fields")]
62+
public IEnumerable<Field> Fields { get; set; }
63+
}
64+
65+
public class Author
66+
{
67+
[JsonProperty("name")]
68+
public string Name { get; set; }
69+
}
70+
71+
public class Footer
72+
{
73+
[JsonProperty("text")]
74+
public string Text { get; set; }
75+
76+
[JsonProperty("icon_url")]
77+
public string IconUrl { get; set; }
78+
}
79+
80+
public class Thumbnail
81+
{
82+
[JsonProperty("url")]
83+
public string Url { get; set; }
84+
}
85+
86+
public class Field
87+
{
88+
[JsonProperty("name")]
89+
public string Name { get; set; }
90+
91+
[JsonProperty("value")]
92+
public string Value { get; set; }
93+
94+
[JsonProperty("inline")]
95+
public bool IsInline { get; set; }
96+
}
97+
98+
private IEnumerable<Field> GetText(ChangeLog changeLog)
99+
{
100+
var changeLogItemsAgrupado = changeLog.ChangeLogItems.GroupBy(d => d.WorkItemType);
101+
102+
var listFields = new List<Field>();
103+
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();
16106

17-
//Seta o retorno no ChangeLog
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 });
18109

19-
//Retorna o ChangeLog
110+
return listFields;
20111
}
21112
}
22-
}
113+
}

AzureDevopsTracker/Integrations/MessageIntegration.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public abstract class MessageIntegration
1313
private static readonly string MEGAFONE_GIF = "megafone.gif";
1414
private static readonly string LOGO_TYPINGHARD_16X16 = "logo-typinghard-16x16.png";
1515

16-
protected internal string GetTitle(ChangeLog changeLog)
16+
protected internal string GetTitle()
1717
{
1818
return $"Nova atualização da plataforma";
1919
}
2020

2121
protected internal string GetVersion(ChangeLog changeLog)
2222
{
23-
return $"Versao: { changeLog.Number}";
23+
return $"Versão: {changeLog.Number}";
2424
}
2525

2626
protected internal string GetAnnouncementImageUrl()
@@ -33,11 +33,16 @@ protected internal string GetLogoTypingHard16x16Url()
3333
return $"{CDN_URL}{LOGO_TYPINGHARD_16X16}";
3434
}
3535

36-
protected internal string GetNugetVersion()
36+
protected internal string GetFileVersion()
3737
{
3838
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
3939
System.Diagnostics.FileVersionInfo fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
40-
return $"Powered by **Typing Hard** • nuget version { fileVersionInfo.FileVersion }";
40+
return fileVersionInfo.FileVersion;
41+
}
42+
43+
protected internal string GetNugetVersion()
44+
{
45+
return $"Powered by **Typing Hard** • nuget version { GetFileVersion() }";
4146
}
4247

4348
protected internal HttpResponseMessage Notify(object body)

AzureDevopsTracker/Integrations/MicrosoftTeamsIntegration.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,26 @@ internal static class MicrosoftTeamsStrings
3737

3838
internal override void Send(ChangeLog changeLog)
3939
{
40-
//Formatar o texto com o MicrosoftTeamsHelper
41-
4240
var values = new MicrosoftTeamsMessage()
4341
{
4442
type = MicrosoftTeamsStrings.Type,
4543
context = MicrosoftTeamsStrings.Context,
4644
themeColor = MicrosoftTeamsStrings.ThemeColor,
47-
summary = GetTitle(changeLog),
45+
summary = GetTitle(),
4846
sections = new Section[1]
4947
{
5048
new Section()
5149
{
52-
activityTitle = GetTitle(changeLog),
53-
activitySubtitle = $"Versão: { changeLog.Number }",
50+
activityTitle = GetTitle(),
51+
activitySubtitle = GetVersion(changeLog),
5452
activityImage = GetAnnouncementImageUrl(),
5553
text = GetText(changeLog),
5654
markdown = true
5755
}
5856
}
5957
};
6058

61-
var response = Notify(values);
62-
63-
//Seta o retorno no ChangeLog
64-
65-
//Retorna o ChangeLog
59+
Notify(values);
6660
}
6761

6862
private string GetText(ChangeLog changeLog)
@@ -103,7 +97,7 @@ private string GetWorkItemDescriptionLine(ChangeLogItem workItem)
10397

10498
private string GetFooter()
10599
{
106-
return $"<br><sup> <img src='{ GetLogoTypingHard16x16Url() }' />{ GetNugetVersion() }</sup>";
100+
return $"<br><sup> <img src='{ GetLogoTypingHard16x16Url() }' /> { GetNugetVersion() }</sup>";
107101
}
108102
}
109103
}

0 commit comments

Comments
 (0)