addons/isl/src/BrowseRepo.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Comparison} from 'shared/Comparison';
b69ab319import type {Hash, RepoRelativePath} from './types';
b69ab3110
b69ab3111import {revsetForComparison} from 'shared/Comparison';
b69ab3112import serverAPI from './ClientToServerAPI';
b69ab3113import {configBackedAtom} from './jotaiUtils';
b69ab3114import platform from './platform';
b69ab3115import {copyAndShowToast, showToast} from './toast';
b69ab3116
b69ab3117export const supportsBrowseUrlForHash = configBackedAtom(
b69ab3118 'fbcodereview.code-browser-url',
b69ab3119 /* default */ false,
b69ab3120 /* readonly */ true,
b69ab3121 /* use raw value */ true,
b69ab3122);
b69ab3123
b69ab3124export async function openBrowseUrlForHash(hash: Hash) {
b69ab3125 serverAPI.postMessage({type: 'getRepoUrlAtHash', revset: hash});
b69ab3126 const msg = await serverAPI.nextMessageMatching('gotRepoUrlAtHash', () => true);
b69ab3127
b69ab3128 const url = msg.url;
b69ab3129 if (url.error) {
b69ab3130 showToast('Failed to get repo URL to browse', {durationMs: 5000});
b69ab3131 return;
b69ab3132 } else if (url.value == null) {
b69ab3133 return;
b69ab3134 }
b69ab3135 platform.openExternalLink(url.value);
b69ab3136}
b69ab3137
b69ab3138export async function copyUrlForFile(path: RepoRelativePath, comparison: Comparison) {
b69ab3139 const revset = revsetForComparison(comparison);
b69ab3140 serverAPI.postMessage({type: 'getRepoUrlAtHash', revset, path});
b69ab3141 const msg = await serverAPI.nextMessageMatching('gotRepoUrlAtHash', () => true);
b69ab3142
b69ab3143 const url = msg.url;
b69ab3144 if (url.error) {
b69ab3145 showToast('Failed to get repo URL to copy', {durationMs: 5000});
b69ab3146 return;
b69ab3147 } else if (url.value == null) {
b69ab3148 return;
b69ab3149 }
b69ab3150 copyAndShowToast(url.value, undefined);
b69ab3151}