Package: jupyterlab-gitlab
JupyterLab GitLabA JupyterLab extension for browsing GitLab repositories (in read-only mode).This extension is based onjupyterlab-github.
All credit to the JupyterLab team, and especiallyIan Rose, for the github extension!Thanks as well toMark Ghiorsofor thejupyterlab_gitlabextension where I took some inspiration. It didn't fit my needs (no server extension) so I decided to create my own based on a recent
version of jupyterlab-github instead (v0.10.0).This extension is composed of a Python package namedjupyterlab_gitlabfor the server extension and a NPM package namedjupyterlab-gitlabfor the frontend extension.The purpose of the server extension is to add GitLab credentials that you will need to acquire
fromhttps://gitlab.com/profile/personal_access_tokens, and then to proxy your request to GitLab.
Note that OAuth2 token are also supported.IntroductionWhat this extension isWhen you install this extension, an additional filebrowser tab will be added
to the left area of JupyterLab. This filebrowser allows you to select GitLab
groups and users, browse their repositories, and open the files in those
repositories. If those files are notebooks, you can run them just as you would
any other notebook. You can also attach a kernel to text files and run those.
Basically, you should be able to open any file in a repository that JupyterLab can handle.WARNING! Subgroups are currently not supported.Here is a screenshot of the plugin opening this very file on GitLab:What this extension is notThis is not an extension that provides full GitLab access, such as
saving files, making commits, forking repositories, etc.If you want to use git from JupyterLab, you should look at thejupyterlab-gitextension.RequirementsJupyterLab >= 4.0JupyterLab 1.x for version 1.xJupyterLab 2.x for version 2.xJupyterLab 3.x for version 3.xJupyterLab 4.x for version 4.xA GitLab account for the server extensionInstallationInstall the server and lab extensionFor Jupyterlab >= 3.0, both extensions are installed from the Python package:pipinstalljupyterlab-gitlabFor Jupyterlab < 3.0, you have to install the server and lab extensions separately:jupyterlabextensioninstalljupyterlab-gitlab
pipinstalljupyterlab-gitlabGetting your credentials from GitLabGo tohttps://gitlab.com/profile/personal_access_tokensor from GitLab, go to yourSettings>Access Tokens.UnderName, enter a short description, to identify the purpose
of this token. I recommend something like:jupyterlab-gitlab.Under Scopes, check theapiscope.ClickCreate personal access token. You will see your new personal access token (a 21 characters string).
Click on the copy to clipboard icon and and paste it locally in a text file for now.
If you have a password manager like 1password, use that.This is the only time you'll see this token in GitLab. If you lose it, you'll
need to create another one.You should now add the credentials you got from GitLab to your notebook configuration file.
Instructions for generating a configuration file can be foundhere.
Once you have identified this file, add the following line to it:c.GitLabConfig.access_token="< YOUR_ACCESS_TOKEN >"where< YOUR_ACCESS_TOKEN >is the string value you obtained above.
It can also be an OAuth2 token.CustomizationCustomizing the server extensionYou saw how to add youraccess_tokento the notebook configuration file.
There are other parameters than you can modify using that file.
Those are the default values:c.GitLabConfig.allow_client_side_access_token=Falsec.GitLabConfig.url="https://gitlab.com"c.GitLabConfig.validate_cert=TrueIf you run your own GitLab instance for example, updatec.GitLabConfig.urlto point to it.Customizing the lab extensionYou can set the plugin to start showing a particular repository at launch time.
Open the "Advanced Settings" editor in the JupyterLab Settings menu,
and under the GitLab settings add{"baseUrl":"https://gitlab.com","defaultRepo":"owner/repository"}whereowneris the GitLab user or group,
andrepositoryis the name of the repository you want to open.ThebaseUrlcan also be updated to point to your own GitLab instance.
If you use the server extension, this url is only used for theOpen this repository on GitLabbutton.TroubleshootIf you are seeing the frontend extension, but it is not working, check
that the server extension is enabled:jupyterserverextensionlistIf the server extension is installed and enabled, but you are not seeing
the frontend extension, check the frontend extension is installed:jupyterlabextensionlistContributingDevelopment installNote: You will need NodeJS to build the extension package.Thejlpmcommand is JupyterLab's pinned version ofyarnthat is installed with JupyterLab. You may useyarnornpmin lieu ofjlpmbelow.# Clone the repo to your local environment# Change directory to the jupyterlab-gitlab directory# Install package in development modepipinstall-e.# Link your development version of the extension with JupyterLabjupyterlabextensiondevelop.--overwrite# Rebuild extension Typescript source after making changesjlpmrunbuildYou can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.# Watch the source directory in one terminal, automatically rebuilding when neededjlpmrunwatch# Run JupyterLab in another terminaljupyterlabWith the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).By default, thejlpm run buildcommand generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:jupyterlabbuild--minimize=FalseUninstallpipuninstalljupyterlab-gitlabFor JupyterLab < 3, you will also need to run the following command after removing the Python package:jupyterlabextensionuninstalljupyterlab-gitlab