-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsourcecontrol-github.cake
75 lines (59 loc) · 2.59 KB
/
sourcecontrol-github.cake
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
#addin "nuget:?package=Cake.GitHub&version=1.0.0"
#addin "nuget:?package=Octokit&version=14.0.0"
//-------------------------------------------------------------
public class GitHubSourceControl : ISourceControl
{
public GitHubSourceControl(BuildContext buildContext)
{
BuildContext = buildContext;
ApiKey = buildContext.BuildServer.GetVariable("GitHubApiKey", buildContext.General.Repository.Password, showValue: false);
OwnerName = buildContext.BuildServer.GetVariable("GitHubOwnerName", buildContext.General.Copyright.Company, showValue: true);
ProjectName = buildContext.BuildServer.GetVariable("GitHubProjectName", buildContext.General.Solution.Name, showValue: true);
if (!string.IsNullOrWhiteSpace(ApiKey) &&
!string.IsNullOrWhiteSpace(OwnerName) &&
!string.IsNullOrWhiteSpace(ProjectName))
{
IsAvailable = true;
}
}
public BuildContext BuildContext { get; private set; }
public string ApiKey { get; set; }
public string OwnerName { get; set; }
public string ProjectName { get; set; }
public string OwnerAndProjectName
{
get { return $"{OwnerName}/{ProjectName}"; }
}
public bool IsAvailable { get; private set; }
public async Task MarkBuildAsPendingAsync(string context, string description)
{
UpdateStatus(GitHubStatusState.Pending, context, description);
}
public async Task MarkBuildAsFailedAsync(string context, string description)
{
UpdateStatus(GitHubStatusState.Failure, context, description);
}
public async Task MarkBuildAsSucceededAsync(string context, string description)
{
UpdateStatus(GitHubStatusState.Success, context, description);
}
private void UpdateStatus(GitHubStatusState state, string context, string description)
{
// Disabled for now
return;
if (!IsAvailable)
{
return;
}
BuildContext.CakeContext.Information("Updating GitHub status to '{0}' | '{1}'", state, description);
var commitSha = BuildContext.General.Repository.CommitId;
// Note: UserName is not really required, use string.Empty, then only api key is needed
BuildContext.CakeContext.GitHubStatus(string.Empty, ApiKey, OwnerName, ProjectName, commitSha, new GitHubStatusSettings
{
State = state,
TargetUrl = null,// "url-to-build-server",
Description = description,
Context = $"Cake - {context}"
});
}
}