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
5 changes: 5 additions & 0 deletions src/__tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ISettingRegistry, SettingRegistry } from '@jupyterlab/settingregistry';
import { JupyterLab } from '@jupyterlab/application';
import { showErrorMessage } from '@jupyterlab/apputils';
import { URLExt } from '@jupyterlab/coreutils';
import { ServerConnection } from '@jupyterlab/services';
import { Signal } from '@lumino/signaling';
import {
defaultMockedResponses,
Expand All @@ -30,6 +31,10 @@ describe('plugin', () => {

beforeAll(() => {
app = new JupyterLab() as jest.Mocked<JupyterLab>;
// Add the serviceManager.serverSettings mock
(app as any).serviceManager = {
serverSettings: ServerConnection.makeSettings()
};
browserFactory = {
defaultBrowser: {
model: { pathChanged: new Signal(null), restored: Promise.resolve() }
Expand Down
10 changes: 6 additions & 4 deletions src/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ServerConnection } from '@jupyterlab/services';
import { ReadonlyJSONObject } from '@lumino/coreutils';
import { Git } from '../tokens';

Expand Down Expand Up @@ -44,8 +45,7 @@ export const defaultMockedResponses: {
stash: {
body: () => ({
code: 0,
message: '',
command: ''
stashes: []
})
},
status: {
Expand All @@ -68,13 +68,15 @@ export function mockedRequestAPI(
endPoint?: string,
method?: string,
body?: ReadonlyJSONObject | null,
namespace?: string
namespace?: string,
serverSettings?: ServerConnection.ISettings
) => Promise<any> {
const mockedImplementation = (
url?: string,
method?: string,
body?: ReadonlyJSONObject | null,
namespace?: string
namespace?: string,
serverSettings?: ServerConnection.ISettings
) => {
mockedResponses = mockedResponses ?? {};
const path = mockedResponses.path ?? DEFAULT_REPOSITORY_PATH;
Expand Down
6 changes: 4 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @param method HTML method; default 'GET'
* @param body JSON object to be passed as body or null; default null
* @param namespace API namespace; default 'git'
* @param serverSettings Optional server connection settings; if not provided, uses ServerConnection.makeSettings()
* @returns The response body interpreted as JSON
*
* @throws {Git.GitResponseError} If the server response is not ok
Expand All @@ -29,10 +30,11 @@
endPoint = '',
method = 'GET',
body: Partial<ReadonlyJSONObject> | null = null,
namespace = 'git'
namespace = 'git',
serverSettings?: ServerConnection.ISettings
): Promise<T> {
// Make request to Jupyter API
const settings = ServerConnection.makeSettings();
const settings = serverSettings ?? ServerConnection.makeSettings();
const requestUrl = URLExt.join(
settings.baseUrl,
namespace, // API Namespace
Expand All @@ -57,7 +59,7 @@
try {
data = JSON.parse(data);
isJSON = true;
} catch (error) {

Check warning on line 62 in src/git.ts

View workflow job for this annotation

GitHub Actions / Test Python 3.13

'error' is defined but never used

Check warning on line 62 in src/git.ts

View workflow job for this annotation

GitHub Actions / Test Python 3.10

'error' is defined but never used

Check warning on line 62 in src/git.ts

View workflow job for this annotation

GitHub Actions / Test Python 3.9

'error' is defined but never used
console.log('Not a JSON response body.', response);
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function activate(
translator: ITranslator | null
): Promise<IGitExtension> {
let settings: ISettingRegistry.ISettings | undefined = undefined;
let serverSettings: Git.IServerSettings;
let gitServerSettings: Git.IServerSettings;
translator = translator ?? nullTranslator;
const trans = translator.load('jupyterlab_git');

Expand All @@ -98,9 +98,10 @@ async function activate(
trans.__('Failed to load settings for the Git Extension.\n%1', error)
);
}
const serverSettings = app.serviceManager.serverSettings;
try {
serverSettings = await getServerSettings(trans);
const { frontendVersion, gitVersion, serverVersion } = serverSettings;
gitServerSettings = await getServerSettings(trans, serverSettings);
const { frontendVersion, gitVersion, serverVersion } = gitServerSettings;

// Version validation
if (!gitVersion) {
Expand Down Expand Up @@ -145,7 +146,12 @@ async function activate(
return null;
}
// Create the Git model
const gitExtension = new GitExtension(docmanager, app.docRegistry, settings);
const gitExtension = new GitExtension(
docmanager,
app.docRegistry,
settings,
serverSettings
);

const onPathChanged = (
model: FileBrowserModel,
Expand Down
Loading
Loading