| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import {atom} from 'jotai'; |
| 9 | import {atomFamilyWeak} from '../../jotaiUtils'; |
| 10 | import {repositoryInfo} from '../../serverAPIState'; |
| 11 | |
| 12 | /** |
| 13 | * Configured pull request domain to view associated pull requests, such as reviewstack.dev. |
| 14 | */ |
| 15 | export const pullRequestDomain = atom<string | undefined>(get => { |
| 16 | const info = get(repositoryInfo); |
| 17 | return info?.pullRequestDomain; |
| 18 | }); |
| 19 | |
| 20 | export const openerUrlForDiffUrl = atomFamilyWeak((url?: string) => { |
| 21 | return atom(get => { |
| 22 | if (!url) { |
| 23 | return url; |
| 24 | } |
| 25 | const newDomain = get(pullRequestDomain); |
| 26 | if (newDomain) { |
| 27 | return url.replace( |
| 28 | /^https:\/\/[^/]+/, |
| 29 | newDomain.startsWith('https://') ? newDomain : `https://${newDomain}`, |
| 30 | ); |
| 31 | } |
| 32 | return url; |
| 33 | }); |
| 34 | }); |
| 35 | |