forked from giuliov/GitPushFilterPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserAlerter.cs
43 lines (40 loc) · 1.5 KB
/
UserAlerter.cs
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
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.Git.Server;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
namespace GitPushFilter
{
static class UserAlerter
{
internal static void InformUserOfFailure(string email
, TeamFoundationRequestContext requestContext, PushNotification pushNotification
, List<Validation> validationResults)
{
var buf = new StringBuilder();
buf.AppendFormat("{0}'s {1} request was refused for the following reasons:"
, requestContext.GetNameToDisplay()
, requestContext.ServiceName
);
buf.AppendLine();
buf.AppendLine();
foreach (var res in validationResults.Where(res => res.Fails))
{
buf.Append(" - ");
buf.AppendLine(res.ReasonMessage);
}
buf.AppendLine();
buf.AppendLine("Additional information:");
buf.Append(requestContext.GetSummary());
buf.AppendLine();
var message = new MailMessage();
message.From = new MailAddress(PluginConfiguration.Instance.EmailSender);
message.To.Add(new MailAddress(email));
message.Subject = "Push refused";
message.Body = buf.ToString();
var smtp = new SmtpClient(PluginConfiguration.Instance.EmailSmtpServer);
smtp.Send(message);
}
}
}