Skip to content

Commit

Permalink
fix(2153): Add PR_BASE_BRANCH_NAME env var (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Jul 15, 2020
1 parent 90325e6 commit 9a7279f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ class GithubScm extends Scm {
command.push(`echo 'Fetching PR and merging with ${branch}'`);
command.push(`$SD_GIT_WRAPPER "git fetch origin ${prRef}"`);

command.push(`export PR_BASE_BRANCH_NAME='${branch}'`);
command.push(`export PR_BRANCH_NAME='${baseRepo}/${config.prBranchName}'`);

// Merge a pull request with pipeline branch
Expand Down
2 changes: 1 addition & 1 deletion test/data/customPrCommands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "export SD_GIT_WRAPPER=\"$(if [ `uname` = 'Darwin' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && echo Exporting environment variables && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Setting user name and user email && $SD_GIT_WRAPPER \"git config --global user.name pqrs\" && $SD_GIT_WRAPPER \"git config --global user.email dev-null@my.email.com\" && export SD_CHECKOUT_DIR_FINAL=$SD_SOURCE_DIR && if [ ! -z $SD_CHECKOUT_DIR ]; then export SD_CHECKOUT_DIR_FINAL=$SD_CHECKOUT_DIR; fi && echo 'Cloning github.com/screwdriver-cd/guide, on branch branchName' && if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; then $SD_GIT_WRAPPER \"git clone --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; else if [ ! -z \"$GIT_SHALLOW_CLONE_SINCE\" ]; then export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--shallow-since='$GIT_SHALLOW_CLONE_SINCE'\"; else if [ -z $GIT_SHALLOW_CLONE_DEPTH ]; then export GIT_SHALLOW_CLONE_DEPTH=50; fi; export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--depth=$GIT_SHALLOW_CLONE_DEPTH\"; fi; export GIT_SHALLOW_CLONE_BRANCH=\"--no-single-branch\"; if [ \"$GIT_SHALLOW_CLONE_SINGLE_BRANCH\" = true ]; then export GIT_SHALLOW_CLONE_BRANCH=\"\"; fi; $SD_GIT_WRAPPER \"git clone $GIT_SHALLOW_CLONE_DEPTH_OPTION $GIT_SHALLOW_CLONE_BRANCH --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; fi && $SD_GIT_WRAPPER \"git reset --hard 'branchName' --\" && echo 'Reset to branchName' && echo 'Fetching PR and merging with branchName' && $SD_GIT_WRAPPER \"git fetch origin pull/3/head:pr\" && export PR_BRANCH_NAME='origin/prBranchName' && $SD_GIT_WRAPPER \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\""
"command": "export SD_GIT_WRAPPER=\"$(if [ `uname` = 'Darwin' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && echo Exporting environment variables && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Setting user name and user email && $SD_GIT_WRAPPER \"git config --global user.name pqrs\" && $SD_GIT_WRAPPER \"git config --global user.email dev-null@my.email.com\" && export SD_CHECKOUT_DIR_FINAL=$SD_SOURCE_DIR && if [ ! -z $SD_CHECKOUT_DIR ]; then export SD_CHECKOUT_DIR_FINAL=$SD_CHECKOUT_DIR; fi && echo 'Cloning github.com/screwdriver-cd/guide, on branch branchName' && if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; then $SD_GIT_WRAPPER \"git clone --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; else if [ ! -z \"$GIT_SHALLOW_CLONE_SINCE\" ]; then export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--shallow-since='$GIT_SHALLOW_CLONE_SINCE'\"; else if [ -z $GIT_SHALLOW_CLONE_DEPTH ]; then export GIT_SHALLOW_CLONE_DEPTH=50; fi; export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--depth=$GIT_SHALLOW_CLONE_DEPTH\"; fi; export GIT_SHALLOW_CLONE_BRANCH=\"--no-single-branch\"; if [ \"$GIT_SHALLOW_CLONE_SINGLE_BRANCH\" = true ]; then export GIT_SHALLOW_CLONE_BRANCH=\"\"; fi; $SD_GIT_WRAPPER \"git clone $GIT_SHALLOW_CLONE_DEPTH_OPTION $GIT_SHALLOW_CLONE_BRANCH --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; fi && $SD_GIT_WRAPPER \"git reset --hard 'branchName' --\" && echo 'Reset to branchName' && echo 'Fetching PR and merging with branchName' && $SD_GIT_WRAPPER \"git fetch origin pull/3/head:pr\" && export PR_BASE_BRANCH_NAME='branchName' && export PR_BRANCH_NAME='origin/prBranchName' && $SD_GIT_WRAPPER \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\""
}
2 changes: 1 addition & 1 deletion test/data/forkPrCommands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "export SD_GIT_WRAPPER=\"$(if [ `uname` = 'Darwin' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && echo Exporting environment variables && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Setting user name and user email && $SD_GIT_WRAPPER \"git config --global user.name sd-buildbot\" && $SD_GIT_WRAPPER \"git config --global user.email dev-null@screwdriver.cd\" && export SD_CHECKOUT_DIR_FINAL=$SD_SOURCE_DIR && if [ ! -z $SD_CHECKOUT_DIR ]; then export SD_CHECKOUT_DIR_FINAL=$SD_CHECKOUT_DIR; fi && echo 'Cloning github.com/screwdriver-cd/guide, on branch branchName' && if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; then $SD_GIT_WRAPPER \"git clone --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; else if [ ! -z \"$GIT_SHALLOW_CLONE_SINCE\" ]; then export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--shallow-since='$GIT_SHALLOW_CLONE_SINCE'\"; else if [ -z $GIT_SHALLOW_CLONE_DEPTH ]; then export GIT_SHALLOW_CLONE_DEPTH=50; fi; export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--depth=$GIT_SHALLOW_CLONE_DEPTH\"; fi; export GIT_SHALLOW_CLONE_BRANCH=\"--no-single-branch\"; if [ \"$GIT_SHALLOW_CLONE_SINGLE_BRANCH\" = true ]; then export GIT_SHALLOW_CLONE_BRANCH=\"\"; fi; $SD_GIT_WRAPPER \"git clone $GIT_SHALLOW_CLONE_DEPTH_OPTION $GIT_SHALLOW_CLONE_BRANCH --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; fi && $SD_GIT_WRAPPER \"git reset --hard 'branchName' --\" && echo 'Reset to branchName' && echo 'Fetching PR and merging with branchName' && $SD_GIT_WRAPPER \"git fetch origin pull/3/head:pr\" && export PR_BRANCH_NAME='upstream/prBranchName' && $SD_GIT_WRAPPER \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\""
"command": "export SD_GIT_WRAPPER=\"$(if [ `uname` = 'Darwin' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && echo Exporting environment variables && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Setting user name and user email && $SD_GIT_WRAPPER \"git config --global user.name sd-buildbot\" && $SD_GIT_WRAPPER \"git config --global user.email dev-null@screwdriver.cd\" && export SD_CHECKOUT_DIR_FINAL=$SD_SOURCE_DIR && if [ ! -z $SD_CHECKOUT_DIR ]; then export SD_CHECKOUT_DIR_FINAL=$SD_CHECKOUT_DIR; fi && echo 'Cloning github.com/screwdriver-cd/guide, on branch branchName' && if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; then $SD_GIT_WRAPPER \"git clone --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; else if [ ! -z \"$GIT_SHALLOW_CLONE_SINCE\" ]; then export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--shallow-since='$GIT_SHALLOW_CLONE_SINCE'\"; else if [ -z $GIT_SHALLOW_CLONE_DEPTH ]; then export GIT_SHALLOW_CLONE_DEPTH=50; fi; export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--depth=$GIT_SHALLOW_CLONE_DEPTH\"; fi; export GIT_SHALLOW_CLONE_BRANCH=\"--no-single-branch\"; if [ \"$GIT_SHALLOW_CLONE_SINGLE_BRANCH\" = true ]; then export GIT_SHALLOW_CLONE_BRANCH=\"\"; fi; $SD_GIT_WRAPPER \"git clone $GIT_SHALLOW_CLONE_DEPTH_OPTION $GIT_SHALLOW_CLONE_BRANCH --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; fi && $SD_GIT_WRAPPER \"git reset --hard 'branchName' --\" && echo 'Reset to branchName' && echo 'Fetching PR and merging with branchName' && $SD_GIT_WRAPPER \"git fetch origin pull/3/head:pr\" && export PR_BASE_BRANCH_NAME='branchName' && export PR_BRANCH_NAME='upstream/prBranchName' && $SD_GIT_WRAPPER \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\""
}
2 changes: 1 addition & 1 deletion test/data/prCommands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "sd-checkout-code",
"command": "export SD_GIT_WRAPPER=\"$(if [ `uname` = 'Darwin' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && echo Exporting environment variables && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Setting user name and user email && $SD_GIT_WRAPPER \"git config --global user.name sd-buildbot\" && $SD_GIT_WRAPPER \"git config --global user.email dev-null@screwdriver.cd\" && export SD_CHECKOUT_DIR_FINAL=$SD_SOURCE_DIR && if [ ! -z $SD_CHECKOUT_DIR ]; then export SD_CHECKOUT_DIR_FINAL=$SD_CHECKOUT_DIR; fi && echo 'Cloning github.com/screwdriver-cd/guide, on branch branchName' && if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; then $SD_GIT_WRAPPER \"git clone --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; else if [ ! -z \"$GIT_SHALLOW_CLONE_SINCE\" ]; then export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--shallow-since='$GIT_SHALLOW_CLONE_SINCE'\"; else if [ -z $GIT_SHALLOW_CLONE_DEPTH ]; then export GIT_SHALLOW_CLONE_DEPTH=50; fi; export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--depth=$GIT_SHALLOW_CLONE_DEPTH\"; fi; export GIT_SHALLOW_CLONE_BRANCH=\"--no-single-branch\"; if [ \"$GIT_SHALLOW_CLONE_SINGLE_BRANCH\" = true ]; then export GIT_SHALLOW_CLONE_BRANCH=\"\"; fi; $SD_GIT_WRAPPER \"git clone $GIT_SHALLOW_CLONE_DEPTH_OPTION $GIT_SHALLOW_CLONE_BRANCH --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; fi && $SD_GIT_WRAPPER \"git reset --hard 'branchName' --\" && echo 'Reset to branchName' && echo 'Fetching PR and merging with branchName' && $SD_GIT_WRAPPER \"git fetch origin pull/3/head:pr\" && export PR_BRANCH_NAME='origin/prBranchName' && $SD_GIT_WRAPPER \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\""
"command": "export SD_GIT_WRAPPER=\"$(if [ `uname` = 'Darwin' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && echo Exporting environment variables && if [ ! -z $SCM_CLONE_TYPE ] && [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@github.com/screwdriver-cd/guide; else export SCM_URL=https://github.com/screwdriver-cd/guide; fi && export GIT_URL=$SCM_URL.git && export GIT_MERGE_AUTOEDIT=no && echo Setting user name and user email && $SD_GIT_WRAPPER \"git config --global user.name sd-buildbot\" && $SD_GIT_WRAPPER \"git config --global user.email dev-null@screwdriver.cd\" && export SD_CHECKOUT_DIR_FINAL=$SD_SOURCE_DIR && if [ ! -z $SD_CHECKOUT_DIR ]; then export SD_CHECKOUT_DIR_FINAL=$SD_CHECKOUT_DIR; fi && echo 'Cloning github.com/screwdriver-cd/guide, on branch branchName' && if [ ! -z $GIT_SHALLOW_CLONE ] && [ $GIT_SHALLOW_CLONE = false ]; then $SD_GIT_WRAPPER \"git clone --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; else if [ ! -z \"$GIT_SHALLOW_CLONE_SINCE\" ]; then export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--shallow-since='$GIT_SHALLOW_CLONE_SINCE'\"; else if [ -z $GIT_SHALLOW_CLONE_DEPTH ]; then export GIT_SHALLOW_CLONE_DEPTH=50; fi; export GIT_SHALLOW_CLONE_DEPTH_OPTION=\"--depth=$GIT_SHALLOW_CLONE_DEPTH\"; fi; export GIT_SHALLOW_CLONE_BRANCH=\"--no-single-branch\"; if [ \"$GIT_SHALLOW_CLONE_SINGLE_BRANCH\" = true ]; then export GIT_SHALLOW_CLONE_BRANCH=\"\"; fi; $SD_GIT_WRAPPER \"git clone $GIT_SHALLOW_CLONE_DEPTH_OPTION $GIT_SHALLOW_CLONE_BRANCH --recursive --quiet --progress --branch 'branchName' $SCM_URL $SD_CHECKOUT_DIR_FINAL\"; fi && $SD_GIT_WRAPPER \"git reset --hard 'branchName' --\" && echo 'Reset to branchName' && echo 'Fetching PR and merging with branchName' && $SD_GIT_WRAPPER \"git fetch origin pull/3/head:pr\" && export PR_BASE_BRANCH_NAME='branchName' && export PR_BRANCH_NAME='origin/prBranchName' && $SD_GIT_WRAPPER \"git merge 12345\" && export GIT_BRANCH=origin/refs/pull/3/head:pr && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\""
}
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('index', function () {
});
});

it('promises to get the checkout command for a repo manfiest file', () => {
it('promises to get the checkout command for a repo manifest file', () => {
config.manifest = 'git@github.com:org/repo.git/default.xml';

return scm.getCheckoutCommand(config)
Expand Down

0 comments on commit 9a7279f

Please sign in to comment.