From b3d8a0a7ee27499b4fc488064bee7925144e377a Mon Sep 17 00:00:00 2001 From: Sheni Hamitaj Date: Tue, 10 May 2022 12:51:43 +0200 Subject: [PATCH 1/4] --add: regex to retrieve branches This is a feature proposition to add regex option to selecting branches like GitHub already has them on actions. --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index 2f5bee2..cbdae67 100644 --- a/index.js +++ b/index.js @@ -63,6 +63,18 @@ const createProcfile = ({ procfile, appdir }) => { } }; +const getBranchViaRegex = (branch) => { + const branchName = execSync( + 'git branch -a | grep -m 1 "' + branch + '"' + ).toString(); + + // return original name on no branch found + // error case already present at deployment + return !!branchName + ? branchName + : branch; +} + const deploy = ({ dontuseforce, app_name, @@ -72,6 +84,7 @@ const deploy = ({ dockerBuildArgs, appdir, }) => { + branch = getBranchViaRegex(branch); const force = !dontuseforce ? "--force" : ""; if (usedocker) { execSync( From 5c3fb661faf12b919ae9a220aeed1fc98050bb38 Mon Sep 17 00:00:00 2001 From: Sheni Hamitaj Date: Tue, 10 May 2022 13:16:54 +0200 Subject: [PATCH 2/4] --fix: wrap with try catch and apply trimming --- index.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index cbdae67..c029ca4 100644 --- a/index.js +++ b/index.js @@ -64,15 +64,20 @@ const createProcfile = ({ procfile, appdir }) => { }; const getBranchViaRegex = (branch) => { - const branchName = execSync( - 'git branch -a | grep -m 1 "' + branch + '"' - ).toString(); + try { + let branchName = execSync( + 'git branch -a | grep -m 1 "' + branch + '"' + ).toString(); - // return original name on no branch found - // error case already present at deployment - return !!branchName - ? branchName - : branch; + if (!!branchName) { + branchName = branchName.replace('*', '').trim(); + return branchName; + } + } catch(e) { + console.error('No branch found'); + } + + return branch; } const deploy = ({ From c676b568de0bb20fcba90285ae2e2a0153b0d9c5 Mon Sep 17 00:00:00 2001 From: Sheni Hamitaj Date: Tue, 10 May 2022 13:22:33 +0200 Subject: [PATCH 3/4] --fix: return empty on empty branch --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index c029ca4..9fd02c1 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,8 @@ const createProcfile = ({ procfile, appdir }) => { }; const getBranchViaRegex = (branch) => { + if (!branch) return branch; + try { let branchName = execSync( 'git branch -a | grep -m 1 "' + branch + '"' From 6727d353acab43930e8c45e1684921df3eda1798 Mon Sep 17 00:00:00 2001 From: Sheni Hamitaj Date: Tue, 10 May 2022 13:24:55 +0200 Subject: [PATCH 4/4] --fix: identation --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 9fd02c1..62b67b7 100644 --- a/index.js +++ b/index.js @@ -67,18 +67,18 @@ const getBranchViaRegex = (branch) => { if (!branch) return branch; try { - let branchName = execSync( - 'git branch -a | grep -m 1 "' + branch + '"' - ).toString(); + let branchName = execSync( + 'git branch -a | grep -m 1 "' + branch + '"' + ).toString(); - if (!!branchName) { - branchName = branchName.replace('*', '').trim(); - return branchName; - } + if (!!branchName) { + branchName = branchName.replace('*', '').trim(); + return branchName; + } } catch(e) { console.error('No branch found'); - } - + } + return branch; }