From 7ba2c849559ea07bf1d26f6af2d0d422a2219eaa Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Tue, 10 Oct 2023 11:56:22 -0700 Subject: [PATCH] Allow passing buildOnly param to the server from the js client --- js/packages/binderhub-client/lib/index.js | 7 ++++++- js/packages/binderhub-client/tests/index.test.js | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/js/packages/binderhub-client/lib/index.js b/js/packages/binderhub-client/lib/index.js index 37e05a5d0..e138c0f0e 100644 --- a/js/packages/binderhub-client/lib/index.js +++ b/js/packages/binderhub-client/lib/index.js @@ -13,8 +13,9 @@ export class BinderRepository { * @param {string} providerSpec Spec of the form // to pass to the binderhub API. * @param {URL} buildEndpointUrl API URL of the build endpoint to talk to * @param {string} buildToken Optional JWT based build token if this binderhub installation requires using build tokens + * @param {boolean} buildOnly Opt out of launching built image by default by passing `build_only` param */ - constructor(providerSpec, buildEndpointUrl, buildToken) { + constructor(providerSpec, buildEndpointUrl, buildToken, buildOnly) { this.providerSpec = providerSpec; // Make sure that buildEndpointUrl is a real URL - this ensures hostname is properly set if (!(buildEndpointUrl instanceof URL)) { @@ -36,6 +37,10 @@ export class BinderRepository { this.buildUrl.searchParams.append("build_token", buildToken); } + if (buildOnly) { + this.buildUrl.searchParams.append("build_only", "true"); + } + this.eventIteratorQueue = null; } diff --git a/js/packages/binderhub-client/tests/index.test.js b/js/packages/binderhub-client/tests/index.test.js index dc1362c03..1dd189459 100644 --- a/js/packages/binderhub-client/tests/index.test.js +++ b/js/packages/binderhub-client/tests/index.test.js @@ -16,6 +16,14 @@ test("Invalid URL errors out", () => { }).toThrow(TypeError); }); +test("Passing buildOnly flag works", () => { + const buildEndpointUrl = new URL("https://test-binder.org/build"); + const br = new BinderRepository("gh/test/test", buildEndpointUrl, null, true); + expect(br.buildUrl.toString()).toEqual( + "https://test-binder.org/build/gh/test/test?build_only=true", + ); +}); + test("Trailing slash added if needed", () => { const buildEndpointUrl = new URL("https://test-binder.org/build"); const br = new BinderRepository("gh/test/test", buildEndpointUrl);