-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommitListener.cs
70 lines (66 loc) · 2.21 KB
/
CommitListener.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
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using ServiceStack.Text;
namespace WCellUtilityBot
{
public class FisheyeWebHookData
{
public Repository Repository { get; set; }
public Changeset Changeset { get; set; }
}
public class Repository
{
public string Name { get; set; }
}
public class Changeset
{
public string Csid { get; set; }
public string Displayid { get; set; }
public string Author { get; set; }
public string Comment { get; set; }
public string Date { get; set; }
public string[] Branches { get; set; }
public string[] Tags { get; set; }
public string[] Parents { get; set; }
}
static class CommitListener
{
public static void StartListener()
{
var listener = new HttpListener();
listener.Start();
listener.Prefixes.Add(Properties.Settings.Default.CommitListenerAddress);
while (true)
{
var context = listener.GetContext();
var obj = JsonSerializer.DeserializeFromStream<FisheyeWebHookData>(context.Request.InputStream);
context.Response.StatusCode = (int) HttpStatusCode.OK;
context.Response.Close();
IrcConnection.Irc.CommandHandler.Msg(Properties.Settings.Default.CommitNotificationChannel, string.Format("Commit-> Project: {0} Author: {1} Branch: {2} Commit Note: {3}", obj.Repository.Name, StripEmailFromAuthor(obj.Changeset.Author), obj.Changeset.Branches[0], obj.Changeset.Comment));
}
}
private static string StripEmailFromAuthor(string author)
{
try
{
if (author.Contains("@"))
{
var start = author.IndexOf('<');
var end = author.Length - start;
return author.Remove(start, end);
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
return author;
}
return author;
}
}
}