Skip to content

Commit

Permalink
fix(libraries/tipipeline/vars): add support for feature branch PRs in…
Browse files Browse the repository at this point in the history
… component checkout (#1476)

- default trunk branch set to `master`, but caller can give custom value, as:
```groovy
component.checkout('xxx.git', 'depA', 'feature/abc', '', "", "custom-trunk-branch")
```
  • Loading branch information
wuhuizuo committed Oct 17, 2022
1 parent 9be6fdb commit cd743a7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions libraries/tipipeline/vars/component.groovy
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
def checkout(gitUrl, keyInComment, prTargetBranch, prCommentBody, credentialsId="") {
// - release-6.2
// - release-6.2-20220801
// - 6.2.0-pitr-dev
def releaseOrHotfixBranchReg = /^(release\-)?(\d+\.\d+)(\.\d+\-.+)?/
def checkout(gitUrl, keyInComment, prTargetBranch, prCommentBody, credentialsId="", trunkBranch="master") {
// /run-xxx dep1=release-x.y
def commentBodyReg = /\b${keyInComment}\s*=\s*([^\s\\]+)(\s|\\|$)/
final commentBodyReg = /\b${keyInComment}\s*=\s*([^\s\\]+)(\s|\\|$)/
// - release-6.2
// - release-6.2-20220801
// - 6.2.0-pitr-dev
final releaseOrHotfixBranchReg = /^(release\-)?(\d+\.\d+)(\.\d+\-.+)?/
// - feature/abcd
// - feature_abcd
final featureBranchReg = /^feature[\/_].*/

def componentBranch = prTargetBranch
if (prCommentBody =~ commentBodyReg) {
componentBranch = (prCommentBody =~ commentBodyReg)[0][1]
} else if (prTargetBranch =~ releaseOrHotfixBranchReg) {
componentBranch = String.format('release-%s', (prTargetBranch =~ releaseOrHotfixBranchReg)[0][2])
} else if (prTargetBranch =~ featureBranchReg) {
componentBranch = trunkBranch
}

def pluginSpec = "+refs/heads/*:refs/remotes/origin/*"
Expand Down

0 comments on commit cd743a7

Please sign in to comment.