|
| 1 | +/*! |
| 2 | + * Copyright 2025 - Swiss Data Science Center (SDSC) |
| 3 | + * A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and |
| 4 | + * Eidgenössische Technische Hochschule Zürich (ETHZ). |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import { safeNewUrl } from "~/utils/helpers/safeNewUrl.utils"; |
| 20 | +import type { Provider } from "./api/connectedServices.api"; |
| 21 | + |
| 22 | +type GetSettingsUrlArgs = Pick<Provider, "app_slug" | "url">; |
| 23 | + |
| 24 | +export function getSettingsUrl({ |
| 25 | + app_slug, |
| 26 | + url, |
| 27 | +}: GetSettingsUrlArgs): URL | null { |
| 28 | + if (!app_slug) { |
| 29 | + return null; |
| 30 | + } |
| 31 | + |
| 32 | + const parsedUrl = safeNewUrl(url); |
| 33 | + if (parsedUrl?.hostname.toLowerCase() === "github.com") { |
| 34 | + return safeNewUrl(`apps/${app_slug}/installations/select_target`, url); |
| 35 | + } |
| 36 | + |
| 37 | + return safeNewUrl(`github-apps/${app_slug}/installations/select_target`, url); |
| 38 | +} |
0 commit comments