From 7b16daddfe5751ec42983844a361817fbae135ee Mon Sep 17 00:00:00 2001 From: Dan Wilson Date: Mon, 24 Oct 2022 16:37:35 +0100 Subject: [PATCH] bug: [DRON-433]: fix new build query logic --- src/pages/repo/repo.jsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pages/repo/repo.jsx b/src/pages/repo/repo.jsx index 435d2748..95054338 100644 --- a/src/pages/repo/repo.jsx +++ b/src/pages/repo/repo.jsx @@ -96,16 +96,18 @@ const Repo = ({ user }) => { const handleNewBuildClick = toggleModal; const handleNewBuildSubmit = useCallback(async (values) => { - let endpoint = `/api/repos/${namespace}/${name}/builds`; + const queryParams = new URLSearchParams(); if (values.target) { - endpoint = `${endpoint}?branch=${values.target}`; - if (values.commit) { - endpoint = `${endpoint}&commit=${values.commit}`; - } - if (values.parameters?.length) { - endpoint = `${endpoint}&${values.parameters.map((param) => `${param.key}=${param.value}`).join('&')}`; - } + queryParams.set('branch', values.target); } + if (values.commit) { + queryParams.set('commit', values.commit); + } + if (values.parameters?.length) { + values.parameters.forEach((param) => { queryParams.set(param.key, param.value); }); + } + const queryString = queryParams.toString(); + const endpoint = `/api/repos/${namespace}/${name}/builds${queryString.length ? `?${queryString}` : ''}`; try { const newBuild = await axiosWrapper(endpoint, { method: 'POST',