-
Notifications
You must be signed in to change notification settings - Fork 653
/
GitlabHqHandler.cs
88 lines (79 loc) · 3.23 KB
/
GitlabHqHandler.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Web;
using Kudu.Core.SourceControl;
using Newtonsoft.Json.Linq;
namespace Kudu.Services.ServiceHookHandlers
{
public class GitlabHqHandler : GitHubCompatHandler
{
//{
// "before": "2370e44c850e732d71edd2db36920482558e3fe0",
// "after": "2370e44c850e732d71edd2db36920482558e3fe0",
// "ref": "refs/heads/master",
// "checkout_sha": "2370e44c850e732d71edd2db36920482558e3fe0",
// "user_id": 99630,
// "user_name": "Suwat Bodin",
// "project_id": 171368,
// "repository": {
// "name": "HelloKudu",
// "url": "git@gitlab.com:KuduApps/HelloKudu.git",
// "description": "",
// "homepage": "https://gitlab.com/KuduApps/HelloKudu",
// "git_http_url": "https://gitlab.com/KuduApps/HelloKudu.git",
// "git_ssh_url": "git@gitlab.com:KuduApps/HelloKudu.git",
// "visibility_level": 20
// },
// "commits": [
// {
// "id": "2370e44c850e732d71edd2db36920482558e3fe0",
// "message": "Initial commit\n",
// "timestamp": "2012-02-14T10:45:08-08:00",
// "url": "https://gitlab.com/KuduApps/HelloKudu/commit/2370e44c850e732d71edd2db36920482558e3fe0",
// "author": {
// "name": "David Fowler",
// "email": "davidfowl@gmail.com"
// }
// }
// ],
// "total_commits_count": 1
//}
private const int PublicVisibilityLevel = 20;
protected override GitDeploymentInfo GetDeploymentInfo(HttpRequestBase request, JObject payload, string targetBranch)
{
var repository = payload.Value<JObject>("repository");
if (repository == null)
{
// doesn't look like GitlabHQ
return null;
}
var userid = payload.Value<int?>("user_id");
var username = payload.Value<string>("user_name");
var url = repository.Value<string>("url");
if (userid == null || username == null || url == null)
{
// doesn't look like GitlabHQ
return null;
}
// The format of ref is refs/something/something else
// For master it's normally refs/head/master
string @ref = payload.Value<string>("ref");
if (String.IsNullOrEmpty(@ref))
{
return null;
}
string newRef = payload.Value<string>("after");
if (IsDeleteCommit(newRef))
{
return null;
}
var commits = payload.Value<JArray>("commits");
var info = new GitDeploymentInfo { RepositoryType = RepositoryType.Git };
info.NewRef = payload.Value<string>("after");
info.TargetChangeset = ParseChangeSet(info.NewRef, commits);
var isPrivate = repository.Value<int>("visibility_level") != PublicVisibilityLevel;
info.RepositoryUrl = isPrivate ? repository.Value<string>("git_ssh_url") : repository.Value<string>("git_http_url");
info.Deployer = "GitlabHQ";
return info;
}
}
}