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

Parse ssh git URLs properly #163

Merged
merged 2 commits into from
Dec 17, 2020
Merged
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions docs/_static/link_gen/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
return lastPart.split(':').slice(-1)[0].replace(/(\.git|\.bundle)?/, '');
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
}

consideRatio marked this conversation as resolved.
Show resolved Hide resolved
function displayLink() {
var form = document.getElementById('linkgenerator');

Expand All @@ -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$/, '');
Expand All @@ -154,6 +165,7 @@ function displayLink() {
hubUrl, urlPath, repoUrl, branch
);
} else if (activeTab === "tab-auth-binder"){
var userName = new URL(repoUrl).pathname.split('/')[1];
yuvipanda marked this conversation as resolved.
Show resolved Hide resolved
document.getElementById('binder-link').value = generateBinderUrl(
hubUrl, userName, repoName, branch, urlPath, contentRepoUrl, contentRepoBranch
);
Expand Down