-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgithub-pages-variables.cake
89 lines (72 loc) · 2.7 KB
/
github-pages-variables.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
85
86
87
88
89
#l "buildserver.cake"
//-------------------------------------------------------------
public class GitHubPagesContext : BuildContextWithItemsBase
{
public GitHubPagesContext(IBuildContext parentBuildContext)
: base(parentBuildContext)
{
}
public string RepositoryUrl { get; set; }
public string BranchName { get; set; }
public string Email { get; set; }
public string UserName { get; set; }
public string ApiToken { get; set; }
protected override void ValidateContext()
{
if (Items.Count == 0)
{
return;
}
if (string.IsNullOrWhiteSpace(RepositoryUrl))
{
throw new Exception("GitHubPagesRepositoryUrl must be defined");
}
if (string.IsNullOrWhiteSpace(BranchName))
{
throw new Exception("GitHubPagesBranchName must be defined");
}
if (string.IsNullOrWhiteSpace(Email))
{
throw new Exception("GitHubPagesEmail must be defined");
}
if (string.IsNullOrWhiteSpace(UserName))
{
throw new Exception("GitHubPagesUserName must be defined");
}
if (string.IsNullOrWhiteSpace(ApiToken))
{
throw new Exception("GitHubPagesApiToken must be defined");
}
}
protected override void LogStateInfoForContext()
{
CakeContext.Information($"Found '{Items.Count}' GitHub pages projects");
}
}
//-------------------------------------------------------------
private GitHubPagesContext InitializeGitHubPagesContext(BuildContext buildContext, IBuildContext parentBuildContext)
{
var data = new GitHubPagesContext(parentBuildContext)
{
Items = GitHubPages ?? new List<string>(),
RepositoryUrl = buildContext.BuildServer.GetVariable("GitHubPagesRepositoryUrl", ((BuildContext)parentBuildContext).General.Repository.Url, showValue: true),
BranchName = buildContext.BuildServer.GetVariable("GitHubPagesRepositoryUrl", "gh-pages", showValue: true),
Email = buildContext.BuildServer.GetVariable("GitHubPagesEmail", showValue: true),
UserName = buildContext.BuildServer.GetVariable("GitHubPagesUserName", showValue: true),
ApiToken = buildContext.BuildServer.GetVariable("GitHubPagesApiToken", showValue: false),
};
return data;
}
//-------------------------------------------------------------
List<string> _gitHubPages;
public List<string> GitHubPages
{
get
{
if (_gitHubPages is null)
{
_gitHubPages = new List<string>();
}
return _gitHubPages;
}
}