-
Notifications
You must be signed in to change notification settings - Fork 653
/
CodebaseHqHandler.cs
41 lines (35 loc) · 1.49 KB
/
CodebaseHqHandler.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
using System;
using System.Web;
using Newtonsoft.Json.Linq;
using Kudu.Contracts.SourceControl;
namespace Kudu.Services.ServiceHookHandlers
{
public class CodebaseHqHandler : GitHubCompatHandler
{
public CodebaseHqHandler(IRepositoryFactory repositoryFactory)
: base(repositoryFactory)
{
}
protected override bool ParserMatches(HttpRequestBase request, JObject payload, string targetBranch)
{
return (request.UserAgent != null && request.UserAgent.StartsWith("Codebasehq", StringComparison.OrdinalIgnoreCase));
}
protected override bool IsNoop(HttpRequestBase request, JObject payload, string targetBranch)
{
// FIXME if githubcompathandler failed to parse the body => NOOP
return !(base.ParserMatches(request, payload, targetBranch)) || base.IsNoop(request, payload, targetBranch);
}
protected override string DetermineSecurityProtocol(JObject payload)
{
// CodebaseHq format, see http://support.codebasehq.com/kb/howtos/repository-push-commit-notifications
var repository = payload.Value<JObject>("repository");
var urls = repository.Value<JObject>("clone_urls");
var isPrivate = repository.Value<bool>("private");
return isPrivate ? urls.Value<string>("ssh") : urls.Value<string>("http");
}
protected override string GetDeployer()
{
return "CodebaseHQ";
}
}
}