From ae09aa218315319d8111f7be1dcf7663793283e8 Mon Sep 17 00:00:00 2001 From: duynguyen Date: Mon, 27 Apr 2026 14:53:17 +0700 Subject: [PATCH] feat: add strategy closure methods to BranchStrategy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors company BasePipeline pattern — each strategy method executes the closure only when the branch matches. Co-Authored-By: Claude Sonnet 4.6 --- .../fireflylab/pipeline/BranchStrategy.groovy | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/vn/fireflylab/pipeline/BranchStrategy.groovy b/src/vn/fireflylab/pipeline/BranchStrategy.groovy index 2410d11..6d2a460 100644 --- a/src/vn/fireflylab/pipeline/BranchStrategy.groovy +++ b/src/vn/fireflylab/pipeline/BranchStrategy.groovy @@ -9,15 +9,8 @@ class BranchStrategy implements Serializable { static boolean isRelease(String branch) { branch ==~ /^release\/\d+\.\d+\.\d+$/ } static boolean isHotfix(String branch) { branch ==~ /^hotfix\/.+/ } - // Build + push on all branches except PRs - static boolean shouldBuildImage(String branch) { - return !isPR(branch) - } - - // Helm bump + git commit/push only on feature branches - static boolean shouldBumpChart(String branch) { - return false - } + static boolean shouldBuildImage(String branch) { return !isPR(branch) } + static boolean shouldBumpChart(String branch) { return false } static String imageTag(String branch) { if (isRelease(branch)) return branch.replaceFirst('release/', '') @@ -25,7 +18,14 @@ class BranchStrategy implements Serializable { if (isMain(branch)) return "main-${shortId}" if (isDevelop(branch)) return "dev-${shortId}" if (isHotfix(branch)) return "hotfix-${shortId}" - // feature/* and anything else: sanitize branch name + random suffix 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() } }