3.5 KB103 lines
Blame
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
8import type {TypeaheadResult} from 'isl-components/Types';
9import type {TypeaheadKind} from 'isl/src/CommitInfoView/types';
10import type {
11 ClientToServerMessage,
12 CodeReviewProviderSpecificClientToServerMessages,
13 CommandArg,
14 DiffComment,
15 DiffId,
16 DiffSignalSummary,
17 DiffSummary,
18 Disposable,
19 Hash,
20 LandConfirmationInfo,
21 LandInfo,
22 OperationCommandProgressReporter,
23 Result,
24 RunnableOperation,
25 ServerToClientMessage,
26} from 'isl/src/types';
27
28export type DiffSummaries = Map<DiffId, DiffSummary>;
29/**
30 * API to fetch data from Remote Code Review system, like GitHub and Phabricator.
31 */
32export interface CodeReviewProvider {
33 triggerDiffSummariesFetch(diffs: Array<DiffId>): unknown;
34
35 onChangeDiffSummaries(callback: (result: Result<DiffSummaries>) => unknown): Disposable;
36
37 /** Run a command not handled within sapling, such as a separate submit handler */
38 runExternalCommand?(
39 cwd: string,
40 args: CommandArg[], // Providers may need specific normalization for args
41 onProgress: OperationCommandProgressReporter,
42 signal: AbortSignal,
43 ): Promise<void>;
44
45 /** Run a conf command for configerator operations */
46 runConfCommand?(
47 cwd: string,
48 args: Array<string>,
49 onProgress: OperationCommandProgressReporter,
50 signal: AbortSignal,
51 ): Promise<void>;
52
53 dispose: () => void;
54
55 /** Convert Code Review Provider info into a short summary string, usable in analytics */
56 getSummaryName(): string;
57
58 typeahead?(kind: TypeaheadKind, query: string, cwd: string): Promise<Array<TypeaheadResult>>;
59
60 getDiffUrlMarkdown(diffId: DiffId): string;
61 getCommitHashUrlMarkdown(hash: string): string;
62
63 getRemoteFileURL?(
64 path: string,
65 publicCommitHash: string | null,
66 selectionStart?: {line: number; char: number},
67 selectionEnd?: {line: number; char: number},
68 ): string;
69
70 updateDiffMessage?(diffId: DiffId, newTitle: string, newDescription: string): Promise<void>;
71
72 getSuggestedReviewers?(context: {paths: Array<string>}): Promise<Array<string>>;
73
74 /** Convert usernames/emails to avatar URIs */
75 fetchAvatars?(authors: Array<string>): Promise<Map<string, string>>;
76
77 /** Convert usernames/emails to avatar URIs */
78 fetchComments?(diffId: DiffId): Promise<Array<DiffComment>>;
79
80 renderMarkup?: (markup: string) => Promise<string>;
81
82 fetchLandInfo?(topOfStack: DiffId): Promise<LandInfo>;
83 confirmLand?(landConfirmationInfo: NonNullable<LandConfirmationInfo>): Promise<Result<undefined>>;
84
85 handleClientToServerMessage?(
86 message: ClientToServerMessage,
87 postMessage: (message: ServerToClientMessage) => void,
88 ): message is CodeReviewProviderSpecificClientToServerMessages;
89
90 /** Subscribe to CI/CD build signals with commit messages for client-side matching. */
91 onChangeCanopySignals?(callback: (runs: Array<{commitMessage: string; signal: DiffSignalSummary; runId?: number; commitId?: string}>) => unknown): Disposable;
92
93 /** Trigger a fetch of Canopy CI signals on demand. */
94 triggerCanopySignalsFetch?(): void;
95
96 /** Called after a Sapling operation completes. Allows providers to react (e.g. create diffs after push). */
97 onPostOperation?(
98 operation: RunnableOperation,
99 exitCode: number,
100 getCommitInfo: (rev: string) => Promise<{title: string; description: string; hash: string; parentHash: string} | undefined>,
101 ): Promise<void>;
102}
103