Skip to content

Commit 1401c77

Browse files
committed
fix: make SCM_URL correct
1 parent 27177d6 commit 1401c77

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,12 @@ class GithubScm extends Scm {
279279

280280
// Git clone
281281
command.push(`echo Cloning ${checkoutUrl}, on branch ${config.branch}`);
282-
command.push(`if [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=${sshCheckoutUrl}; `
283-
+ `else export SCM_URL=${checkoutUrl}; fi`); // use url that corresponds to clone type
284-
command.push('if [ $SCM_CLONE_TYPE != ssh ] && ' // for private repos (must use https)
285-
+ '[ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then '
286-
+ 'SCM_URL="$SCM_USERNAME:$SCM_ACCESS_TOKEN@$SCM_URL"; fi');
282+
command.push(`if [[ $SCM_CLONE_TYPE = 'ssh' ]]; then export SCM_URL=${sshCheckoutUrl}; ` +
283+
'elif [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; ' +
284+
`then export SCM_URL=https://$SCM_USERNAME:$SCM_ACCESS_TOKEN@${checkoutUrl}; ` +
285+
`else export SCM_URL=https://${checkoutUrl}; fi`);
287286
command.push(`git clone --quiet --progress --branch ${config.branch} `
288-
+ 'https://$SCM_URL $SD_SOURCE_DIR');
287+
+ '$SCM_URL $SD_SOURCE_DIR');
289288
// Reset to SHA
290289
command.push(`git reset --hard ${checkoutRef}`);
291290
command.push(`echo Reset to ${checkoutRef}`);

test/data/commands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "sd-checkout-code",
3-
"command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; else export SCM_URL=github.com/screwdriver-cd/guide; fi && if [ $SCM_CLONE_TYPE != ssh ] && [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then SCM_URL=\"$SCM_USERNAME:$SCM_ACCESS_TOKEN@$SCM_URL\"; fi && git clone --quiet --progress --branch branchName https://$SCM_URL $SD_SOURCE_DIR && git reset --hard 12345 && echo Reset to 12345 && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd"
3+
"command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [[ $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 && git clone --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR && git reset --hard 12345 && echo Reset to 12345 && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd"
44
}

test/data/customPrCommands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "sd-checkout-code",
3-
"command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; else export SCM_URL=github.com/screwdriver-cd/guide; fi && if [ $SCM_CLONE_TYPE != ssh ] && [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then SCM_URL=\"$SCM_USERNAME:$SCM_ACCESS_TOKEN@$SCM_URL\"; fi && git clone --quiet --progress --branch branchName https://$SCM_URL $SD_SOURCE_DIR && git reset --hard branchName && echo Reset to branchName && echo Setting user name and user email && git config user.name pqrs && git config user.email dev-null@my.email.com && echo Fetching PR and merging with branchName && git fetch origin pull/3/head:pr && git merge --no-edit 12345"
3+
"command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [[ $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 && git clone --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR && git reset --hard branchName && echo Reset to branchName && echo Setting user name and user email && git config user.name pqrs && git config user.email dev-null@my.email.com && echo Fetching PR and merging with branchName && git fetch origin pull/3/head:pr && git merge --no-edit 12345"
44
}

test/data/prCommands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "sd-checkout-code",
3-
"command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [ $SCM_CLONE_TYPE = ssh ]; then export SCM_URL=git@github.com:screwdriver-cd/guide; else export SCM_URL=github.com/screwdriver-cd/guide; fi && if [ $SCM_CLONE_TYPE != ssh ] && [ ! -z $SCM_USERNAME ] && [ ! -z $SCM_ACCESS_TOKEN ]; then SCM_URL=\"$SCM_USERNAME:$SCM_ACCESS_TOKEN@$SCM_URL\"; fi && git clone --quiet --progress --branch branchName https://$SCM_URL $SD_SOURCE_DIR && git reset --hard branchName && echo Reset to branchName && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd && echo Fetching PR and merging with branchName && git fetch origin pull/3/head:pr && git merge --no-edit 12345"
3+
"command": "echo Cloning github.com/screwdriver-cd/guide, on branch branchName && if [[ $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 && git clone --quiet --progress --branch branchName $SCM_URL $SD_SOURCE_DIR && git reset --hard branchName && echo Reset to branchName && echo Setting user name and user email && git config user.name sd-buildbot && git config user.email dev-null@screwdriver.cd && echo Fetching PR and merging with branchName && git fetch origin pull/3/head:pr && git merge --no-edit 12345"
44
}

0 commit comments

Comments
 (0)