Skip to content
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
18 changes: 14 additions & 4 deletions nbgitpuller/static/js/gitsyncview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FitAddon } from 'xterm-addon-fit';
import { WebLinksAddon } from 'xterm-addon-web-links';

export class GitSyncView{
constructor(termSelector, progressSelector, termToggleSelector, recoverySelector) {
constructor(termSelector, progressSelector, termToggleSelector, containerErrorSelector, copyErrorSelector) {
// Class that encapsulates view rendering as much as possible
this.term = new Terminal({
convertEol: true
Expand All @@ -18,7 +18,8 @@ export class GitSyncView{

this.termToggle = document.querySelector(termToggleSelector);
this.termElement = document.querySelector(termSelector);
this.recovery = document.querySelector(recoverySelector);
this.containerError = document.querySelector(containerErrorSelector);
this.copyError = document.querySelector(copyErrorSelector);

this.termToggle.onclick = () => this.setTerminalVisibility(!this.visible)
}
Expand Down Expand Up @@ -64,9 +65,18 @@ export class GitSyncView{
}
}

setRecoveryLink(isError) {
setContainerError(isError, errorText='') {
if (isError) {
this.recovery.classList.toggle('hidden', !visible);
this.containerError.classList.toggle('hidden', !this.visible);
}
const button = this.copyError;
button.onclick = async () => {
try {
await navigator.clipboard.writeText(errorText);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about what other thing would be useful, can you also copy the nbgitpuller URL itself? that contains important and helpful info about the repo and branch that I think help a lot. But let's just copy the url - base_url (so just /git-sync?query-params) so we don't automatically include the username here, as that could be PII.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion.

Had a look at the query params used in the GitSync class

  this.baseUrl = baseUrl;
  this.repo = repo;
  this.branch = branch;
  this.depth = depth; // not currently used because of shallow clone https://github.com/jupyterhub/nbgitpuller/pull/117
  this.targetpath = targetpath; // optional folder to clone into
  this.redirectUrl = baseUrl + path;
  this._xsrf = xsrf;

and pulled out repo, branch and redirectUrl to insert into the error text. Now the terminal output prints this info in addition to the traceback log, that can be copied to clipboard:

Repository: https://github.com/data-8/textbook
Branch: gh-pages
Redirect URL: /tree/textbook/.

Traceback (most recent call last):
File "/Users/jnywong/Documents/github/nbgitpuller/nbgitpuller/handlers.py", line 87, in get
    gp = GitPuller(repo, repo_dir, branch=branch, depth=depth, parent=self.settings['nbapp'])
File "/Users/jnywong/Documents/github/nbgitpuller/nbgitpuller/pull.py", line 81, in __init__
    raise ValueError(f"Branch: {self.branch_name} -- not found in repo: {self.git_url}")
ValueError: Branch: gh-pages -- not found in repo: https://github.com/data-8/textbook
Screenshot 2025-12-08 at 12 06 29

button.innerHTML = 'Error message copied!';
} catch (err) {
console.error('Failed to copy error text: ', err);
}
}
}
}
11 changes: 8 additions & 3 deletions nbgitpuller/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const gsv = new GitSyncView(
'#status-details',
'#status-panel-title',
'#status-panel-toggle',
'#recovery-link'
'#container-error',
'#copy-error-button',
);

gs.addHandler('syncing', function(data) {
Expand All @@ -46,10 +47,14 @@ gs.addHandler('error', function(data) {
gsv.setProgressValue(100);
gsv.setProgressText('Error: ' + data.message);
gsv.setProgressError(true);
gsv.setRecoveryLink(true);
gsv.setTerminalVisibility(true);
if (data.output) {
gsv.term.write(data.output);
const errorText= `Repository: ${gs.repo}\nBranch: ${gs.branch}\nRedirect URL: ${gs.redirectUrl}\n\n${data.output}\n`;
gsv.term.write(errorText);
gsv.setContainerError(
true,
errorText
);
}
});
gs.start();
Expand Down
20 changes: 17 additions & 3 deletions nbgitpuller/templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% endblock %}

{% block site %}
<div class="container"">
<div class="container">
<div class="page-header">
Synchronizing <a href="{{ repo }}">git repository</a> before sending you to <strong>{{ path }}...</strong>
</div>
Expand All @@ -30,8 +30,15 @@
<div id="status-details"></div>
</div>
</div>
<div id="recovery-link" class="hidden">
<a class="btn btn-warning" href="{{ base_url }}" aria-label="Go to the Jupyter server without synchronizing content">Proceed to server without synchronizing</a>
<div id="container-error" class="container hidden">
<div class="row">
<div id="recovery-link" class="col-xs-6 pull-left">
<a class="btn btn-warning" href="{{ base_url }}" aria-label="Go to the Jupyter server without synchronizing content">Proceed to server without synchronizing</a>
</div>
<div id="copy-error" class="col-xs-6 pull-right text-right">
<button class="btn btn-danger" id="copy-error-button" aria-label="Copy error details to clipboard">Copy error to clipboard</button>
</div>
</div>
</div>
</div>
{% endblock %}
Expand Down Expand Up @@ -74,5 +81,12 @@
width: 100%;
color: black;
}

#container-error {
margin-right: 0px;
padding-left: 0px;
padding-right: 30px;
}

</style>
{% endblock %}