Created
May 14, 2020 14:24
-
-
Save wololock/94e1ca3579486fdc6468f1fc9646a8b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.transform.Field | |
@Field | |
def profiles = [ | |
prod: ["master", /release\/.*/], | |
dev: ["develop", /PR-.*/] | |
] | |
String getProfileForBranchName(String branchName, String defaultProfile = "default") { | |
return profiles.findResult { profile, candidates -> candidates.any { branchName ==~ it } ? profile : null } ?: defaultProfile | |
} | |
["PR-123", "master", "release/1.0.0", "foo", "develop"].each { branchName -> | |
println "Profile for branch $branchName is ${getProfileForBranchName(branchName)}" | |
} | |
// Output: | |
// Profile for branch PR-123 is dev | |
// Profile for branch master is prod | |
// Profile for branch release/1.0.0 is prod | |
// Profile for branch foo is default | |
// Profile for branch develop is dev | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot! It was a super helpful example. I did not exactly use this code but I used to play around and it helped me to come up with a good idea :) lets see if it works...