feat: add strategy closure methods to BranchStrategy
Mirrors company BasePipeline pattern — each strategy method executes the closure only when the branch matches. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,15 +9,8 @@ class BranchStrategy implements Serializable {
|
|||||||
static boolean isRelease(String branch) { branch ==~ /^release\/\d+\.\d+\.\d+$/ }
|
static boolean isRelease(String branch) { branch ==~ /^release\/\d+\.\d+\.\d+$/ }
|
||||||
static boolean isHotfix(String branch) { branch ==~ /^hotfix\/.+/ }
|
static boolean isHotfix(String branch) { branch ==~ /^hotfix\/.+/ }
|
||||||
|
|
||||||
// Build + push on all branches except PRs
|
static boolean shouldBuildImage(String branch) { return !isPR(branch) }
|
||||||
static boolean shouldBuildImage(String branch) {
|
static boolean shouldBumpChart(String branch) { return false }
|
||||||
return !isPR(branch)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helm bump + git commit/push only on feature branches
|
|
||||||
static boolean shouldBumpChart(String branch) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
static String imageTag(String branch) {
|
static String imageTag(String branch) {
|
||||||
if (isRelease(branch)) return branch.replaceFirst('release/', '')
|
if (isRelease(branch)) return branch.replaceFirst('release/', '')
|
||||||
@@ -25,7 +18,14 @@ class BranchStrategy implements Serializable {
|
|||||||
if (isMain(branch)) return "main-${shortId}"
|
if (isMain(branch)) return "main-${shortId}"
|
||||||
if (isDevelop(branch)) return "dev-${shortId}"
|
if (isDevelop(branch)) return "dev-${shortId}"
|
||||||
if (isHotfix(branch)) return "hotfix-${shortId}"
|
if (isHotfix(branch)) return "hotfix-${shortId}"
|
||||||
// feature/* and anything else: sanitize branch name + random suffix
|
|
||||||
return "${branch.replaceAll('[^a-zA-Z0-9._-]', '-')}-${shortId}"
|
return "${branch.replaceAll('[^a-zA-Z0-9._-]', '-')}-${shortId}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strategy methods — execute body only when branch matches
|
||||||
|
static void prStrategy(String branch, Closure body) { if (isPR(branch)) body() }
|
||||||
|
static void featureStrategy(String branch, Closure body) { if (isFeature(branch)) body() }
|
||||||
|
static void developStrategy(String branch, Closure body) { if (isDevelop(branch)) body() }
|
||||||
|
static void mainStrategy(String branch, Closure body) { if (isMain(branch)) body() }
|
||||||
|
static void releaseStrategy(String branch, Closure body) { if (isRelease(branch)) body() }
|
||||||
|
static void hotfixStrategy(String branch, Closure body) { if (isHotfix(branch)) body() }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user