Skip to content

Add targetPath to link generator. #368

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 20 additions & 7 deletions docs/_static/link_gen/link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Pure function that generates an nbgitpuller URL
function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch) {
function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch, targetPath) {

// assume hubUrl is a valid URL
var url = new URL(hubUrl);
Expand All @@ -14,6 +14,10 @@ function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch) {
url.searchParams.set('branch', branch);
}

if (targetPath) {
url.searchParams.set('targetPath', targetPath);
}

if (!url.pathname.endsWith('/')) {
url.pathname += '/'
}
Expand All @@ -27,7 +31,7 @@ function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch) {
return url.toString();
}

function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch, targetPath) {
// assume hubUrl is a valid URL
var url = new URL(hubUrl);

Expand All @@ -43,6 +47,10 @@ function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
nextUrlParams.append('branch', branch);
}

if (targetPath) {
nextUrlParams.append('targetPath', targetPath);
}

var nextUrl = '/hub/user-redirect/git-pull?' + nextUrlParams.toString();

if (!url.pathname.endsWith('/')) {
Expand All @@ -55,7 +63,7 @@ function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
}

function generateBinderUrl(hubUrl, userName, repoName, branch, urlPath,
contentRepoUrl, contentRepoBranch) {
contentRepoUrl, contentRepoBranch, targetPath) {

var url = new URL(hubUrl);

Expand All @@ -71,6 +79,10 @@ function generateBinderUrl(hubUrl, userName, repoName, branch, urlPath,
nextUrlParams.append('branch', contentRepoBranch);
}

if (targetPath) {
nextUrlParams.append('targetPath', targetPath);
}

var nextUrl = 'git-pull?' + nextUrlParams.toString();

var path = '/v2/gh/';
Expand Down Expand Up @@ -168,6 +180,7 @@ function displayLink() {
var server = document.getElementById('server').value;
var appName = form.querySelector('input[name="app"]:checked').value;
var activeTab = document.querySelector(".nav-link.active").id;
var targetPath = document.getElementById('targetPath').value;

if (appName === 'custom') {
var urlPath = document.getElementById('urlpath').value;
Expand All @@ -184,19 +197,19 @@ function displayLink() {

if (activeTab === "tab-auth-default") {
document.getElementById('default-link').value = generateRegularUrl(
hubUrl, server, urlPath, repoUrl, branch
hubUrl, server, urlPath, repoUrl, branch, targetPath
);
} else if (activeTab === "tab-auth-canvas"){
document.getElementById('canvas-link').value = generateCanvasUrl(
hubUrl, urlPath, repoUrl, branch
hubUrl, urlPath, repoUrl, branch, targetPath
);
} 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
hubUrl, userName, repoName, branch, urlPath, contentRepoUrl, contentRepoBranch, targetPath
);
}
}
Expand Down Expand Up @@ -289,4 +302,4 @@ function copyLink(elementId) {
copyText.select();
copyText.setSelectionRange(0, copyText.value.length);
navigator.clipboard.writeText(copyText.value);
}
}
11 changes: 11 additions & 0 deletions docs/link.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ Use the following form to create your own ``nbgitpuller`` links.
</div>
</div>

<div class="form-group row">
<label for="targetPath" class="col-sm-2 col-form-label">Target Path</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="targetPath" placeholder="(optional) Directory to clone into"
oninput="displayLink()">
<small class="form-text text-muted">
Directory to clone the repository into. If left blank, the repo will be cloned into a directory named after the repository.
</small>
</div>
</div>

<div class="form-group row" id="server-container">
<label for="server" class="col-sm-2 col-form-label">Named Server to open</label>
<div class="col-sm-10">
Expand Down