-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsourcecontrol.cake
84 lines (70 loc) · 2.81 KB
/
sourcecontrol.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
76
77
78
79
80
81
82
83
84
// Customize this file when using a different source controls
#l "sourcecontrol-github.cake"
//-------------------------------------------------------------
public interface ISourceControl
{
Task MarkBuildAsPendingAsync(string context, string description);
Task MarkBuildAsFailedAsync(string context, string description);
Task MarkBuildAsSucceededAsync(string context, string description);
}
//-------------------------------------------------------------
public class SourceControlIntegration : IntegrationBase
{
private readonly List<ISourceControl> _sourceControls = new List<ISourceControl>();
public SourceControlIntegration(BuildContext buildContext)
: base(buildContext)
{
_sourceControls.Add(new GitHubSourceControl(buildContext));
}
public async Task MarkBuildAsPendingAsync(string context, string description = null)
{
BuildContext.CakeContext.LogSeparator($"Marking build as pending: '{description ?? string.Empty}'");
context = context ?? "default";
description = description ?? "Build pending";
foreach (var sourceControl in _sourceControls)
{
try
{
await sourceControl.MarkBuildAsPendingAsync(context, description);
}
catch (Exception ex)
{
BuildContext.CakeContext.Warning($"Failed to update status: {ex.Message}");
}
}
}
public async Task MarkBuildAsFailedAsync(string context, string description = null)
{
BuildContext.CakeContext.LogSeparator($"Marking build as failed: '{description ?? string.Empty}'");
context = context ?? "default";
description = description ?? "Build failed";
foreach (var sourceControl in _sourceControls)
{
try
{
await sourceControl.MarkBuildAsFailedAsync(context, description);
}
catch (Exception ex)
{
BuildContext.CakeContext.Warning($"Failed to update status: {ex.Message}");
}
}
}
public async Task MarkBuildAsSucceededAsync(string context, string description = null)
{
BuildContext.CakeContext.LogSeparator($"Marking build as succeeded: '{description ?? string.Empty}'");
context = context ?? "default";
description = description ?? "Build succeeded";
foreach (var sourceControl in _sourceControls)
{
try
{
await sourceControl.MarkBuildAsSucceededAsync(context, description);
}
catch (Exception ex)
{
BuildContext.CakeContext.Warning($"Failed to update status: {ex.Message}");
}
}
}
}