-
Notifications
You must be signed in to change notification settings - Fork 652
/
Copy pathExtensionMethods.git.cs
86 lines (70 loc) · 2.65 KB
/
ExtensionMethods.git.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
namespace GitVersion
{
using System;
static partial class ExtensionMethods
{
public static string GetCanonicalBranchName(this string branchName)
{
if (branchName.IsPullRequest())
{
branchName = branchName.Replace("pull-requests", "pull");
branchName = branchName.Replace("pr", "pull");
return string.Format("refs/{0}/head", branchName);
}
return string.Format("refs/heads/{0}", branchName);
}
public static bool IsHotfix(this string branchName)
{
return branchName.StartsWith("hotfix-") || branchName.StartsWith("hotfix/");
}
public static string GetHotfixSuffix(this string branchName)
{
return branchName.TrimStart("hotfix-").TrimStart("hotfix/");
}
public static bool IsRelease(this string branchName)
{
return branchName.StartsWith("release-") || branchName.StartsWith("release/");
}
public static string GetReleaseSuffix(this string branchName)
{
return branchName.TrimStart("release-").TrimStart("release/");
}
public static string GetUnknownBranchSuffix(this string branchName)
{
var unknownBranchSuffix = branchName.Split('-', '/');
if (unknownBranchSuffix.Length == 1)
return branchName;
return unknownBranchSuffix[1];
}
public static string GetSuffix(this string branchName, BranchType branchType)
{
switch (branchType)
{
case BranchType.Hotfix:
return branchName.GetHotfixSuffix();
case BranchType.Release:
return branchName.GetReleaseSuffix();
case BranchType.Unknown:
return branchName.GetUnknownBranchSuffix();
default:
throw new NotSupportedException(string.Format("Unexpected branch type {0}.", branchType));
}
}
public static bool IsDevelop(this string branchName)
{
return branchName == "develop";
}
public static bool IsMaster(this string branchName)
{
return branchName == "master";
}
public static bool IsPullRequest(this string branchName)
{
return branchName.Contains("pull/") || branchName.Contains("pull-requests/") || branchName.Contains("pr/");
}
public static bool IsSupport(this string branchName)
{
return branchName.ToLower().StartsWith("support-");
}
}
}