From 6bd27c80f3d42d0723a8ef021a93a2d9d1d9621a Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Thu, 17 Dec 2020 17:27:36 +0530 Subject: [PATCH 1/2] Parse ssh git URLs properly Fixes #101 --- docs/_static/link_gen/link.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/_static/link_gen/link.js b/docs/_static/link_gen/link.js index fc14501e..2c9e14ee 100644 --- a/docs/_static/link_gen/link.js +++ b/docs/_static/link_gen/link.js @@ -117,6 +117,18 @@ function changeTab(div) { } } +/** + * Return name of directory git will clone given repo to. + * + * nbgitpuller needs to redirect users to *inside* the directory it + * just cloned. We copy the logic git itself uses to determine that. + * See https://github.com/git/git/blob/1c52ecf4ba0f4f7af72775695fee653f50737c71/builtin/clone.c#L276 + */ +function generateCloneDirectoryName(gitCloneUrl) { + var lastPart = gitCloneUrl.split('/').slice(-1)[0]; + return lastPart.split(':').slice(-1)[0].replace(/(\.git|\.bundle)?/, ''); +} + function displayLink() { var form = document.getElementById('linkgenerator'); @@ -134,8 +146,7 @@ function displayLink() { if (appName === 'custom') { var urlPath = document.getElementById('urlpath').value; } else { - var repoName = new URL(repoUrl).pathname.split('/').pop().replace(/\.git$/, ''); - var userName = new URL(repoUrl).pathname.split('/')[1]; + var repoName = generateCloneDirectoryName(repoUrl); var urlPath; if (activeTab === "tab-auth-binder") { var contentRepoName = new URL(contentRepoUrl).pathname.split('/').pop().replace(/\.git$/, ''); @@ -154,6 +165,7 @@ function displayLink() { hubUrl, urlPath, repoUrl, branch ); } else if (activeTab === "tab-auth-binder"){ + var userName = new URL(repoUrl).pathname.split('/')[1]; document.getElementById('binder-link').value = generateBinderUrl( hubUrl, userName, repoName, branch, urlPath, contentRepoUrl, contentRepoBranch ); From a9c119a28024cb3a3ac55f662bb731115479d354 Mon Sep 17 00:00:00 2001 From: Yuvi Panda Date: Thu, 17 Dec 2020 19:36:23 +0530 Subject: [PATCH 2/2] Mention that binder doesn't work with ssh urls Co-authored-by: Erik Sundell --- docs/_static/link_gen/link.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/_static/link_gen/link.js b/docs/_static/link_gen/link.js index 2c9e14ee..3d9806a7 100644 --- a/docs/_static/link_gen/link.js +++ b/docs/_static/link_gen/link.js @@ -165,6 +165,9 @@ function displayLink() { hubUrl, urlPath, repoUrl, branch ); } else if (activeTab === "tab-auth-binder"){ + // FIXME: userName parsing using new URL(...) assumes a + // HTTP based repoUrl. Does it make sense to create a + // BinderHub link for SSH URLs? Then let's fix this parsing. var userName = new URL(repoUrl).pathname.split('/')[1]; document.getElementById('binder-link').value = generateBinderUrl( hubUrl, userName, repoName, branch, urlPath, contentRepoUrl, contentRepoBranch