Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(2952): Allow colon to be used in root directory #220

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ class GithubScm extends Scm {
* @return {Promise} Resolves to an object containing repository-related information
*/
async lookupScmUri({ scmUri, scmRepo, token }) {
const [scmHost, scmId, scmBranch, rootDir] = scmUri.split(':');
const parts = scmUri.split(':');
const [scmHost, scmId, scmBranch, ...rootDirParts] = parts;
const rootDir = rootDirParts.join(':');

let repoFullName;
let defaultBranch;
Expand Down
2 changes: 1 addition & 1 deletion test/data/specialCharacterRootDirCommands.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' ] || [ ${SD_HAB_ENABLED:-false} = 'false' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && if [ ! -z $SD_SCM_DEPLOY_KEY ]; then export SCM_CLONE_TYPE=ssh; 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 && if [ ! -z $SD_SCM_DEPLOY_KEY ] && [ $SCM_CLONE_TYPE = ssh ]; then echo $SD_SCM_DEPLOY_KEY | base64 -d > /tmp/git_key && echo \"\" >> /tmp/git_key && chmod 600 /tmp/git_key && export GIT_SSH_COMMAND=\"ssh -i /tmp/git_key\" && mkdir -p ~/.ssh/ && printf \"%s\n\" \"CiAgICAgICAgSG9zdCBnaXRodWIuY29tCiAgICAgICAgICAgIFN0cmljdEhvc3RLZXlDaGVja2luZyBubwogICAgICAgIA==\" | base64 -d >> ~/.ssh/config; fi && 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 '12345' --\" && echo 'Reset to 12345' && export GIT_BRANCH='origin/branchName' && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\" && cd '!\"#$%&'\\''()-=|@`{;+]},<.> 🚗'"
"command": "export SD_GIT_WRAPPER=\"$(if [ `uname` = 'Darwin' ] || [ ${SD_HAB_ENABLED:-false} = 'false' ]; then echo 'eval'; else echo 'sd-step exec core/git'; fi)\" && if [ ! -z $SD_SCM_DEPLOY_KEY ]; then export SCM_CLONE_TYPE=ssh; 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 && if [ ! -z $SD_SCM_DEPLOY_KEY ] && [ $SCM_CLONE_TYPE = ssh ]; then echo $SD_SCM_DEPLOY_KEY | base64 -d > /tmp/git_key && echo \"\" >> /tmp/git_key && chmod 600 /tmp/git_key && export GIT_SSH_COMMAND=\"ssh -i /tmp/git_key\" && mkdir -p ~/.ssh/ && printf \"%s\n\" \"CiAgICAgICAgSG9zdCBnaXRodWIuY29tCiAgICAgICAgICAgIFN0cmljdEhvc3RLZXlDaGVja2luZyBubwogICAgICAgIA==\" | base64 -d >> ~/.ssh/config; fi && 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 '12345' --\" && echo 'Reset to 12345' && export GIT_BRANCH='origin/branchName' && $SD_GIT_WRAPPER \"git submodule init\" && $SD_GIT_WRAPPER \"git submodule update --recursive\" && cd '!\"#$%&'\\''()-=|@`{:;+]},<.> 🚗'"
}
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('index', function() {
});

it('promises to get the checkout command when rootDir with special characters is passed in', () => {
config.rootDir = '!"#$%&\'()-=|@`{;+]},<.> 🚗';
config.rootDir = '!"#$%&\'()-=|@`{:;+]},<.> 🚗';

return scm.getCheckoutCommand(config).then(command => {
assert.deepEqual(command, testSpecialCharacterRootDirCommands);
Expand Down