Skip to content

Commit 5b2df7f

Browse files
authored
Merge pull request #368 from ryanlovett/form-targetpath
Add targetPath to link generator.
2 parents e80374a + de96006 commit 5b2df7f

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

docs/_static/link_gen/link.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Pure function that generates an nbgitpuller URL
2-
function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch) {
2+
function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch, targetPath) {
33

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

17+
if (targetPath) {
18+
url.searchParams.set('targetPath', targetPath);
19+
}
20+
1721
if (!url.pathname.endsWith('/')) {
1822
url.pathname += '/'
1923
}
@@ -27,7 +31,7 @@ function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch) {
2731
return url.toString();
2832
}
2933

30-
function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
34+
function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch, targetPath) {
3135
// assume hubUrl is a valid URL
3236
var url = new URL(hubUrl);
3337

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

50+
if (targetPath) {
51+
nextUrlParams.append('targetPath', targetPath);
52+
}
53+
4654
var nextUrl = '/hub/user-redirect/git-pull?' + nextUrlParams.toString();
4755

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

5765
function generateBinderUrl(hubUrl, userName, repoName, branch, urlPath,
58-
contentRepoUrl, contentRepoBranch) {
66+
contentRepoUrl, contentRepoBranch, targetPath) {
5967

6068
var url = new URL(hubUrl);
6169

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

82+
if (targetPath) {
83+
nextUrlParams.append('targetPath', targetPath);
84+
}
85+
7486
var nextUrl = 'git-pull?' + nextUrlParams.toString();
7587

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

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

185198
if (activeTab === "tab-auth-default") {
186199
document.getElementById('default-link').value = generateRegularUrl(
187-
hubUrl, server, urlPath, repoUrl, branch
200+
hubUrl, server, urlPath, repoUrl, branch, targetPath
188201
);
189202
} else if (activeTab === "tab-auth-canvas"){
190203
document.getElementById('canvas-link').value = generateCanvasUrl(
191-
hubUrl, urlPath, repoUrl, branch
204+
hubUrl, urlPath, repoUrl, branch, targetPath
192205
);
193206
} else if (activeTab === "tab-auth-binder"){
194207
// FIXME: userName parsing using new URL(...) assumes a
195208
// HTTP based repoUrl. Does it make sense to create a
196209
// BinderHub link for SSH URLs? Then let's fix this parsing.
197210
var userName = new URL(repoUrl).pathname.split('/')[1];
198211
document.getElementById('binder-link').value = generateBinderUrl(
199-
hubUrl, userName, repoName, branch, urlPath, contentRepoUrl, contentRepoBranch
212+
hubUrl, userName, repoName, branch, urlPath, contentRepoUrl, contentRepoBranch, targetPath
200213
);
201214
}
202215
}
@@ -289,4 +302,4 @@ function copyLink(elementId) {
289302
copyText.select();
290303
copyText.setSelectionRange(0, copyText.value.length);
291304
navigator.clipboard.writeText(copyText.value);
292-
}
305+
}

docs/link.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ Use the following form to create your own ``nbgitpuller`` links.
180180
</div>
181181
</div>
182182

183+
<div class="form-group row">
184+
<label for="targetPath" class="col-sm-2 col-form-label">Target Path</label>
185+
<div class="col-sm-10">
186+
<input class="form-control" type="text" id="targetPath" placeholder="(optional) Directory to clone into"
187+
oninput="displayLink()">
188+
<small class="form-text text-muted">
189+
Directory to clone the repository into. If left blank, the repo will be cloned into a directory named after the repository.
190+
</small>
191+
</div>
192+
</div>
193+
183194
<div class="form-group row" id="server-container">
184195
<label for="server" class="col-sm-2 col-form-label">Named Server to open</label>
185196
<div class="col-sm-10">

0 commit comments

Comments
 (0)