| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {TypeaheadResult} from 'isl-components/Types'; |
| b69ab31 | | | 9 | import type {Serializable} from 'isl/src/serialize'; |
| b69ab31 | | | 10 | import type { |
| b69ab31 | | | 11 | ChangedFile, |
| b69ab31 | | | 12 | ClientToServerMessage, |
| b69ab31 | | | 13 | CodeReviewProviderSpecificClientToServerMessages, |
| b69ab31 | | | 14 | Disposable, |
| b69ab31 | | | 15 | FetchedCommits, |
| b69ab31 | | | 16 | FetchedUncommittedChanges, |
| b69ab31 | | | 17 | FileABugProgress, |
| b69ab31 | | | 18 | LandInfo, |
| b69ab31 | | | 19 | MergeConflicts, |
| b69ab31 | | | 20 | PlatformSpecificClientToServerMessages, |
| b69ab31 | | | 21 | RepositoryError, |
| b69ab31 | | | 22 | Result, |
| b69ab31 | | | 23 | ServerToClientMessage, |
| b69ab31 | | | 24 | StableLocationData, |
| b69ab31 | | | 25 | SubmodulesByRoot, |
| b69ab31 | | | 26 | } from 'isl/src/types'; |
| b69ab31 | | | 27 | import type {EjecaError, EjecaReturn} from 'shared/ejeca'; |
| 6c9fcae | | | 28 | import {ejeca} from 'shared/ejeca'; |
| b69ab31 | | | 29 | import type {ExportStack, ImportedStack} from 'shared/types/stack'; |
| b69ab31 | | | 30 | import type {ClientConnection} from '.'; |
| b69ab31 | | | 31 | import type {RepositoryReference} from './RepositoryCache'; |
| b69ab31 | | | 32 | import type {ServerSideTracker} from './analytics/serverSideTracker'; |
| b69ab31 | | | 33 | import type {Logger} from './logger'; |
| b69ab31 | | | 34 | import type {ServerPlatform} from './serverPlatform'; |
| b69ab31 | | | 35 | import type {RepositoryContext} from './serverTypes'; |
| b69ab31 | | | 36 | |
| b69ab31 | | | 37 | import type {InternalTypes} from 'isl/src/InternalTypes'; |
| b69ab31 | | | 38 | import {deserializeFromString, serializeToString} from 'isl/src/serialize'; |
| b69ab31 | | | 39 | import type {PartiallySelectedDiffCommit} from 'isl/src/stackEdit/diffSplitTypes'; |
| b69ab31 | | | 40 | import {Readable} from 'node:stream'; |
| b69ab31 | | | 41 | import path from 'path'; |
| b69ab31 | | | 42 | import {beforeRevsetForComparison} from 'shared/Comparison'; |
| b69ab31 | | | 43 | import {base64Decode, notEmpty, randomId} from 'shared/utils'; |
| b69ab31 | | | 44 | import {generatedFilesDetector} from './GeneratedFiles'; |
| b69ab31 | | | 45 | import {Internal} from './Internal'; |
| 6c9fcae | | | 46 | import {Repository, absolutePathForFileInRepo, readGroveConfig} from './Repository'; |
| b69ab31 | | | 47 | import {repositoryCache} from './RepositoryCache'; |
| b69ab31 | | | 48 | import {firstOfIterable, parseExecJson} from './utils'; |
| b69ab31 | | | 49 | |
| b69ab31 | | | 50 | export type IncomingMessage = ClientToServerMessage; |
| b69ab31 | | | 51 | export type OutgoingMessage = ServerToClientMessage; |
| b69ab31 | | | 52 | |
| b69ab31 | | | 53 | type GeneralMessage = IncomingMessage & |
| b69ab31 | | | 54 | ( |
| b69ab31 | | | 55 | | {type: 'heartbeat'} |
| b69ab31 | | | 56 | | {type: 'stress'} |
| b69ab31 | | | 57 | | {type: 'changeCwd'} |
| b69ab31 | | | 58 | | {type: 'requestRepoInfo'} |
| b69ab31 | | | 59 | | {type: 'requestApplicationInfo'} |
| b69ab31 | | | 60 | | {type: 'fileBugReport'} |
| b69ab31 | | | 61 | | {type: 'track'} |
| b69ab31 | | | 62 | | {type: 'clientReady'} |
| 6c9fcae | | | 63 | | {type: 'fetchGroveOwners'} |
| 6c9fcae | | | 64 | | {type: 'createGroveRepo'} |
| b69ab31 | | | 65 | ); |
| b69ab31 | | | 66 | type WithRepoMessage = Exclude<IncomingMessage, GeneralMessage>; |
| b69ab31 | | | 67 | |
| b69ab31 | | | 68 | /** |
| b69ab31 | | | 69 | * Message passing channel built on top of ClientConnection. |
| b69ab31 | | | 70 | * Use to send and listen for well-typed events with the client |
| b69ab31 | | | 71 | * |
| b69ab31 | | | 72 | * Note: you must set the current repository to start sending data back to the client. |
| b69ab31 | | | 73 | */ |
| b69ab31 | | | 74 | export default class ServerToClientAPI { |
| b69ab31 | | | 75 | private listenersByType = new Map< |
| b69ab31 | | | 76 | string, |
| b69ab31 | | | 77 | Set<(message: IncomingMessage) => void | Promise<void>> |
| b69ab31 | | | 78 | >(); |
| b69ab31 | | | 79 | private incomingListener: Disposable; |
| b69ab31 | | | 80 | |
| b69ab31 | | | 81 | /** Disposables that must be disposed whenever the current repo is changed */ |
| b69ab31 | | | 82 | private repoDisposables: Array<Disposable> = []; |
| b69ab31 | | | 83 | private subscriptions = new Map<string, Disposable>(); |
| b69ab31 | | | 84 | private activeRepoRef: RepositoryReference | undefined; |
| b69ab31 | | | 85 | |
| b69ab31 | | | 86 | private queuedMessages: Array<IncomingMessage> = []; |
| b69ab31 | | | 87 | private currentState: |
| b69ab31 | | | 88 | | {type: 'loading'} |
| b69ab31 | | | 89 | | {type: 'repo'; repo: Repository; ctx: RepositoryContext} |
| b69ab31 | | | 90 | | {type: 'error'; error: RepositoryError} = {type: 'loading'}; |
| b69ab31 | | | 91 | |
| b69ab31 | | | 92 | private pageId = randomId(); |
| b69ab31 | | | 93 | |
| b69ab31 | | | 94 | constructor( |
| b69ab31 | | | 95 | private platform: ServerPlatform, |
| b69ab31 | | | 96 | private connection: ClientConnection, |
| b69ab31 | | | 97 | private tracker: ServerSideTracker, |
| b69ab31 | | | 98 | private logger: Logger, |
| b69ab31 | | | 99 | ) { |
| b69ab31 | | | 100 | this.incomingListener = this.connection.onDidReceiveMessage(buf => { |
| b69ab31 | | | 101 | const message = buf.toString('utf-8'); |
| b69ab31 | | | 102 | const data = deserializeFromString(message) as IncomingMessage; |
| b69ab31 | | | 103 | |
| b69ab31 | | | 104 | // When the client is connected, we want to immediately start listening to messages. |
| b69ab31 | | | 105 | // However, we can't properly respond to these messages until we have a repository set up. |
| b69ab31 | | | 106 | // Queue up messages until a repository is set. |
| b69ab31 | | | 107 | if (this.currentState.type === 'loading') { |
| b69ab31 | | | 108 | this.queuedMessages.push(data); |
| b69ab31 | | | 109 | } else { |
| b69ab31 | | | 110 | try { |
| b69ab31 | | | 111 | this.handleIncomingMessage(data); |
| b69ab31 | | | 112 | } catch (err) { |
| b69ab31 | | | 113 | connection.logger?.error('error handling incoming message: ', data, err); |
| b69ab31 | | | 114 | } |
| b69ab31 | | | 115 | } |
| b69ab31 | | | 116 | }); |
| b69ab31 | | | 117 | } |
| b69ab31 | | | 118 | |
| b69ab31 | | | 119 | private setRepoError(error: RepositoryError) { |
| b69ab31 | | | 120 | this.disposeRepoDisposables(); |
| b69ab31 | | | 121 | |
| b69ab31 | | | 122 | this.currentState = {type: 'error', error}; |
| b69ab31 | | | 123 | |
| b69ab31 | | | 124 | this.tracker.context.setRepo(undefined); |
| b69ab31 | | | 125 | |
| b69ab31 | | | 126 | this.processQueuedMessages(); |
| b69ab31 | | | 127 | } |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | private setCurrentRepo(repo: Repository, ctx: RepositoryContext) { |
| b69ab31 | | | 130 | this.disposeRepoDisposables(); |
| b69ab31 | | | 131 | |
| b69ab31 | | | 132 | this.currentState = {type: 'repo', repo, ctx}; |
| b69ab31 | | | 133 | |
| b69ab31 | | | 134 | this.tracker.context.setRepo(repo); |
| b69ab31 | | | 135 | |
| b69ab31 | | | 136 | if (repo.codeReviewProvider != null) { |
| b69ab31 | | | 137 | this.repoDisposables.push( |
| b69ab31 | | | 138 | repo.codeReviewProvider.onChangeDiffSummaries(value => { |
| b69ab31 | | | 139 | this.postMessage({type: 'fetchedDiffSummaries', summaries: value}); |
| b69ab31 | | | 140 | }), |
| b69ab31 | | | 141 | ); |
| 083fd5f | | | 142 | if (repo.codeReviewProvider.onChangeCanopySignals) { |
| 083fd5f | | | 143 | this.repoDisposables.push( |
| 083fd5f | | | 144 | repo.codeReviewProvider.onChangeCanopySignals(runs => { |
| 083fd5f | | | 145 | this.postMessage({type: 'fetchedCanopySignals', runs}); |
| 083fd5f | | | 146 | }), |
| 083fd5f | | | 147 | ); |
| 083fd5f | | | 148 | } |
| b69ab31 | | | 149 | } |
| b69ab31 | | | 150 | |
| b69ab31 | | | 151 | repo.ref(); |
| b69ab31 | | | 152 | this.repoDisposables.push({dispose: () => repo.unref()}); |
| b69ab31 | | | 153 | |
| 4fe1f34 | | | 154 | // Send initial watchman status and subscribe to changes |
| 4fe1f34 | | | 155 | this.postMessage({type: 'watchmanStatus', status: repo.watchForChanges.watchman.status}); |
| 4fe1f34 | | | 156 | repo.watchForChanges.onWatchmanStatusChange = status => { |
| 4fe1f34 | | | 157 | this.postMessage({type: 'watchmanStatus', status}); |
| 4fe1f34 | | | 158 | }; |
| 4fe1f34 | | | 159 | this.repoDisposables.push({dispose: () => { |
| 4fe1f34 | | | 160 | repo.watchForChanges.onWatchmanStatusChange = undefined; |
| 4fe1f34 | | | 161 | }}); |
| 4fe1f34 | | | 162 | |
| b69ab31 | | | 163 | repo.fetchAndSetRecommendedBookmarks(async bookmarks => { |
| b69ab31 | | | 164 | await this.connection.readySignal?.promise; |
| b69ab31 | | | 165 | this.postMessage({type: 'fetchedRecommendedBookmarks', bookmarks}); |
| b69ab31 | | | 166 | }); |
| b69ab31 | | | 167 | |
| b69ab31 | | | 168 | repo.fetchAndSetHiddenMasterConfig(async (config, odType) => { |
| b69ab31 | | | 169 | await this.connection.readySignal?.promise; |
| b69ab31 | | | 170 | this.postMessage({ |
| b69ab31 | | | 171 | type: 'fetchedHiddenMasterBranchConfig', |
| b69ab31 | | | 172 | config, |
| b69ab31 | | | 173 | odType, |
| b69ab31 | | | 174 | cwd: ctx.cwd, |
| b69ab31 | | | 175 | }); |
| b69ab31 | | | 176 | }); |
| b69ab31 | | | 177 | |
| b69ab31 | | | 178 | this.processQueuedMessages(); |
| b69ab31 | | | 179 | } |
| b69ab31 | | | 180 | |
| b69ab31 | | | 181 | postMessage(message: OutgoingMessage) { |
| b69ab31 | | | 182 | this.connection.postMessage(serializeToString(message)); |
| b69ab31 | | | 183 | } |
| b69ab31 | | | 184 | |
| b69ab31 | | | 185 | /** Get a repository reference for a given cwd, and set that as the active repo. */ |
| b69ab31 | | | 186 | setActiveRepoForCwd(newCwd: string) { |
| b69ab31 | | | 187 | if (this.activeRepoRef !== undefined) { |
| b69ab31 | | | 188 | this.activeRepoRef.unref(); |
| b69ab31 | | | 189 | } |
| b69ab31 | | | 190 | this.logger.info(`Setting active repo cwd to ${newCwd}`); |
| b69ab31 | | | 191 | // Set as loading right away while we determine the new cwd's repo |
| b69ab31 | | | 192 | // This ensures new messages coming in will be queued and handled only with the new repository |
| b69ab31 | | | 193 | this.currentState = {type: 'loading'}; |
| b69ab31 | | | 194 | const command = this.connection.command ?? 'sl'; |
| b69ab31 | | | 195 | const ctx: RepositoryContext = { |
| b69ab31 | | | 196 | cwd: newCwd, |
| b69ab31 | | | 197 | cmd: command, |
| b69ab31 | | | 198 | logger: this.logger, |
| b69ab31 | | | 199 | tracker: this.tracker, |
| b69ab31 | | | 200 | }; |
| b69ab31 | | | 201 | this.activeRepoRef = repositoryCache.getOrCreate(ctx); |
| b69ab31 | | | 202 | this.activeRepoRef.promise.then(repoOrError => { |
| b69ab31 | | | 203 | if (repoOrError instanceof Repository) { |
| b69ab31 | | | 204 | this.setCurrentRepo(repoOrError, ctx); |
| b69ab31 | | | 205 | } else { |
| b69ab31 | | | 206 | this.setRepoError(repoOrError); |
| b69ab31 | | | 207 | } |
| b69ab31 | | | 208 | }); |
| b69ab31 | | | 209 | } |
| b69ab31 | | | 210 | |
| b69ab31 | | | 211 | dispose() { |
| b69ab31 | | | 212 | this.incomingListener.dispose(); |
| b69ab31 | | | 213 | this.disposeRepoDisposables(); |
| b69ab31 | | | 214 | |
| b69ab31 | | | 215 | if (this.activeRepoRef !== undefined) { |
| b69ab31 | | | 216 | this.activeRepoRef.unref(); |
| b69ab31 | | | 217 | } |
| b69ab31 | | | 218 | } |
| b69ab31 | | | 219 | |
| b69ab31 | | | 220 | private disposeRepoDisposables() { |
| b69ab31 | | | 221 | this.repoDisposables.forEach(disposable => disposable.dispose()); |
| b69ab31 | | | 222 | this.repoDisposables = []; |
| b69ab31 | | | 223 | |
| b69ab31 | | | 224 | this.subscriptions.forEach(sub => sub.dispose()); |
| b69ab31 | | | 225 | this.subscriptions.clear(); |
| b69ab31 | | | 226 | } |
| b69ab31 | | | 227 | |
| b69ab31 | | | 228 | private processQueuedMessages() { |
| b69ab31 | | | 229 | for (const message of this.queuedMessages) { |
| b69ab31 | | | 230 | try { |
| b69ab31 | | | 231 | this.handleIncomingMessage(message); |
| b69ab31 | | | 232 | } catch (err) { |
| b69ab31 | | | 233 | this.connection.logger?.error('error handling queued message: ', message, err); |
| b69ab31 | | | 234 | } |
| b69ab31 | | | 235 | } |
| b69ab31 | | | 236 | this.queuedMessages = []; |
| b69ab31 | | | 237 | } |
| b69ab31 | | | 238 | |
| b69ab31 | | | 239 | private handleIncomingMessage(data: IncomingMessage) { |
| b69ab31 | | | 240 | this.handleIncomingGeneralMessage(data as GeneralMessage); |
| b69ab31 | | | 241 | const {currentState} = this; |
| b69ab31 | | | 242 | switch (currentState.type) { |
| b69ab31 | | | 243 | case 'repo': { |
| b69ab31 | | | 244 | const {repo, ctx} = currentState; |
| b69ab31 | | | 245 | this.handleIncomingMessageWithRepo(data as WithRepoMessage, repo, ctx); |
| b69ab31 | | | 246 | break; |
| b69ab31 | | | 247 | } |
| b69ab31 | | | 248 | |
| b69ab31 | | | 249 | // If the repo is in the loading or error state, the client may still send |
| b69ab31 | | | 250 | // platform messages such as `platform/openExternal` that should be processed. |
| b69ab31 | | | 251 | case 'loading': |
| b69ab31 | | | 252 | case 'error': |
| b69ab31 | | | 253 | if (data.type.startsWith('platform/')) { |
| b69ab31 | | | 254 | this.platform.handleMessageFromClient( |
| b69ab31 | | | 255 | /*repo=*/ undefined, |
| b69ab31 | | | 256 | // even if we don't have a repo, we can still make a RepositoryContext to execute commands |
| b69ab31 | | | 257 | { |
| b69ab31 | | | 258 | cwd: this.connection.cwd, |
| b69ab31 | | | 259 | cmd: this.connection.command ?? 'sl', |
| b69ab31 | | | 260 | logger: this.logger, |
| b69ab31 | | | 261 | tracker: this.tracker, |
| b69ab31 | | | 262 | }, |
| b69ab31 | | | 263 | data as PlatformSpecificClientToServerMessages, |
| b69ab31 | | | 264 | message => this.postMessage(message), |
| b69ab31 | | | 265 | (dispose: () => unknown) => { |
| b69ab31 | | | 266 | this.repoDisposables.push({dispose}); |
| b69ab31 | | | 267 | }, |
| b69ab31 | | | 268 | ); |
| b69ab31 | | | 269 | this.notifyListeners(data); |
| b69ab31 | | | 270 | } |
| b69ab31 | | | 271 | break; |
| b69ab31 | | | 272 | } |
| b69ab31 | | | 273 | } |
| b69ab31 | | | 274 | |
| b69ab31 | | | 275 | /** |
| b69ab31 | | | 276 | * Handle messages which can be handled regardless of if a repo was successfully created or not |
| b69ab31 | | | 277 | */ |
| b69ab31 | | | 278 | private handleIncomingGeneralMessage(data: GeneralMessage) { |
| b69ab31 | | | 279 | switch (data.type) { |
| b69ab31 | | | 280 | case 'heartbeat': { |
| b69ab31 | | | 281 | this.postMessage({type: 'heartbeat', id: data.id}); |
| b69ab31 | | | 282 | break; |
| b69ab31 | | | 283 | } |
| b69ab31 | | | 284 | case 'stress': { |
| b69ab31 | | | 285 | this.postMessage(data); |
| b69ab31 | | | 286 | break; |
| b69ab31 | | | 287 | } |
| b69ab31 | | | 288 | case 'track': { |
| b69ab31 | | | 289 | this.tracker.trackData(data.data); |
| b69ab31 | | | 290 | break; |
| b69ab31 | | | 291 | } |
| b69ab31 | | | 292 | case 'clientReady': { |
| b69ab31 | | | 293 | this.connection.readySignal?.resolve(); |
| b69ab31 | | | 294 | break; |
| b69ab31 | | | 295 | } |
| b69ab31 | | | 296 | case 'changeCwd': { |
| b69ab31 | | | 297 | this.setActiveRepoForCwd(data.cwd); |
| b69ab31 | | | 298 | break; |
| b69ab31 | | | 299 | } |
| b69ab31 | | | 300 | case 'requestRepoInfo': { |
| b69ab31 | | | 301 | switch (this.currentState.type) { |
| b69ab31 | | | 302 | case 'repo': |
| b69ab31 | | | 303 | this.postMessage({ |
| b69ab31 | | | 304 | type: 'repoInfo', |
| b69ab31 | | | 305 | info: this.currentState.repo.info, |
| b69ab31 | | | 306 | cwd: this.currentState.ctx.cwd, |
| b69ab31 | | | 307 | }); |
| b69ab31 | | | 308 | break; |
| b69ab31 | | | 309 | case 'error': |
| b69ab31 | | | 310 | this.postMessage({type: 'repoInfo', info: this.currentState.error}); |
| b69ab31 | | | 311 | break; |
| b69ab31 | | | 312 | } |
| b69ab31 | | | 313 | break; |
| b69ab31 | | | 314 | } |
| b69ab31 | | | 315 | case 'requestApplicationInfo': { |
| b69ab31 | | | 316 | this.postMessage({ |
| b69ab31 | | | 317 | type: 'applicationInfo', |
| b69ab31 | | | 318 | info: { |
| b69ab31 | | | 319 | platformName: this.platform.platformName, |
| b69ab31 | | | 320 | version: this.connection.version, |
| b69ab31 | | | 321 | logFilePath: this.connection.logFileLocation ?? '(no log file, logging to stdout)', |
| 4bb999b | | | 322 | readOnly: this.connection.readOnly ?? false, |
| b69ab31 | | | 323 | }, |
| b69ab31 | | | 324 | }); |
| b69ab31 | | | 325 | break; |
| b69ab31 | | | 326 | } |
| b69ab31 | | | 327 | case 'fileBugReport': { |
| b69ab31 | | | 328 | const maybeRepo = this.currentState.type === 'repo' ? this.currentState.repo : undefined; |
| b69ab31 | | | 329 | const ctx: RepositoryContext = |
| b69ab31 | | | 330 | this.currentState.type === 'repo' |
| b69ab31 | | | 331 | ? this.currentState.ctx |
| b69ab31 | | | 332 | : { |
| b69ab31 | | | 333 | // cwd is only needed to run graphql query, here it's just best-effort |
| b69ab31 | | | 334 | cwd: maybeRepo?.initialConnectionContext.cwd ?? process.cwd(), |
| b69ab31 | | | 335 | cmd: this.connection.command ?? 'sl', |
| b69ab31 | | | 336 | logger: this.logger, |
| b69ab31 | | | 337 | tracker: this.tracker, |
| b69ab31 | | | 338 | }; |
| b69ab31 | | | 339 | Internal.fileABug?.( |
| b69ab31 | | | 340 | ctx, |
| b69ab31 | | | 341 | this.platform.platformName, |
| b69ab31 | | | 342 | data.data, |
| b69ab31 | | | 343 | data.uiState, |
| b69ab31 | | | 344 | // Use repo for rage, if available. |
| b69ab31 | | | 345 | maybeRepo, |
| b69ab31 | | | 346 | data.collectRage, |
| b69ab31 | | | 347 | (progress: FileABugProgress) => { |
| b69ab31 | | | 348 | this.connection.logger?.info('file a bug progress: ', JSON.stringify(progress)); |
| b69ab31 | | | 349 | this.postMessage({type: 'fileBugReportProgress', ...progress}); |
| b69ab31 | | | 350 | }, |
| b69ab31 | | | 351 | ); |
| b69ab31 | | | 352 | break; |
| b69ab31 | | | 353 | } |
| 6c9fcae | | | 354 | case 'fetchGroveOwners': { |
| 6c9fcae | | | 355 | const groveConfig = readGroveConfig(this.logger); |
| 6c9fcae | | | 356 | if (!groveConfig.hub || !groveConfig.token) { |
| 6c9fcae | | | 357 | this.postMessage({type: 'fetchedGroveOwners', owners: []}); |
| 6c9fcae | | | 358 | break; |
| 6c9fcae | | | 359 | } |
| 6c9fcae | | | 360 | (async () => { |
| 6c9fcae | | | 361 | try { |
| 6c9fcae | | | 362 | const owners: Array<{name: string; type: 'user' | 'org'}> = []; |
| 6c9fcae | | | 363 | if (groveConfig.username) { |
| 6c9fcae | | | 364 | owners.push({name: groveConfig.username, type: 'user'}); |
| 6c9fcae | | | 365 | } |
| 6c9fcae | | | 366 | const res = await fetch(`${groveConfig.hub}/api/orgs`, { |
| 6c9fcae | | | 367 | headers: {Authorization: `Bearer ${groveConfig.token}`}, |
| 6c9fcae | | | 368 | }); |
| 6c9fcae | | | 369 | if (res.ok) { |
| 6c9fcae | | | 370 | const data = (await res.json()) as {orgs: Array<{name: string}>}; |
| 6c9fcae | | | 371 | for (const org of data.orgs) { |
| 6c9fcae | | | 372 | owners.push({name: org.name, type: 'org'}); |
| 6c9fcae | | | 373 | } |
| 6c9fcae | | | 374 | } |
| 6c9fcae | | | 375 | this.postMessage({type: 'fetchedGroveOwners', owners}); |
| 6c9fcae | | | 376 | } catch (err) { |
| 6c9fcae | | | 377 | this.logger.error('Failed to fetch Grove owners:', err); |
| 6c9fcae | | | 378 | this.postMessage({type: 'fetchedGroveOwners', owners: []}); |
| 6c9fcae | | | 379 | } |
| 6c9fcae | | | 380 | })(); |
| 6c9fcae | | | 381 | break; |
| 6c9fcae | | | 382 | } |
| 6c9fcae | | | 383 | case 'createGroveRepo': { |
| 6c9fcae | | | 384 | const groveConfig = readGroveConfig(this.logger); |
| 6c9fcae | | | 385 | if (!groveConfig.hub || !groveConfig.token) { |
| 6c9fcae | | | 386 | this.postMessage({ |
| 6c9fcae | | | 387 | type: 'createdGroveRepo', |
| 6c9fcae | | | 388 | result: {error: new Error('Not logged in to Grove. Run `grove auth login` first.')}, |
| 6c9fcae | | | 389 | }); |
| 6c9fcae | | | 390 | break; |
| 6c9fcae | | | 391 | } |
| 6c9fcae | | | 392 | const owner = data.owner ?? groveConfig.username; |
| 6c9fcae | | | 393 | if (!owner) { |
| 6c9fcae | | | 394 | this.postMessage({ |
| 6c9fcae | | | 395 | type: 'createdGroveRepo', |
| 6c9fcae | | | 396 | result: {error: new Error('No owner specified and no username found in Grove config.')}, |
| 6c9fcae | | | 397 | }); |
| 6c9fcae | | | 398 | break; |
| 6c9fcae | | | 399 | } |
| 6c9fcae | | | 400 | const repoName = data.name; |
| 6c9fcae | | | 401 | (async () => { |
| 6c9fcae | | | 402 | try { |
| 6c9fcae | | | 403 | // Create the repo on Grove |
| 6c9fcae | | | 404 | const res = await fetch(`${groveConfig.hub}/api/repos`, { |
| 6c9fcae | | | 405 | method: 'POST', |
| 6c9fcae | | | 406 | headers: { |
| 6c9fcae | | | 407 | Authorization: `Bearer ${groveConfig.token}`, |
| 6c9fcae | | | 408 | 'Content-Type': 'application/json', |
| 6c9fcae | | | 409 | }, |
| 6c9fcae | | | 410 | body: JSON.stringify({name: repoName, owner}), |
| 6c9fcae | | | 411 | }); |
| 6c9fcae | | | 412 | if (!res.ok) { |
| 6c9fcae | | | 413 | const body = await res.text(); |
| 6c9fcae | | | 414 | throw new Error(`Failed to create repository: ${res.status} ${body}`); |
| 6c9fcae | | | 415 | } |
| 6c9fcae | | | 416 | |
| 6c9fcae | | | 417 | const cwd = this.connection.cwd; |
| 6c9fcae | | | 418 | const cmd = this.connection.command ?? 'sl'; |
| 6c9fcae | | | 419 | const homedir = process.env.HOME ?? process.env.USERPROFILE ?? ''; |
| 0542c45 | | | 420 | |
| 0542c45 | | | 421 | // If sl init created a git-backed repo, re-init with correct format |
| 0542c45 | | | 422 | const fs = await import('fs'); |
| 0542c45 | | | 423 | const storeRequires = path.join(cwd, '.sl', 'store', 'requires'); |
| 0542c45 | | | 424 | try { |
| 0542c45 | | | 425 | const requires = fs.readFileSync(storeRequires, 'utf8'); |
| 0542c45 | | | 426 | if (requires.includes('git')) { |
| 0542c45 | | | 427 | this.logger.info( |
| 0542c45 | | | 428 | 'Re-initializing repo: current store is git-backed, need native format for Grove', |
| 0542c45 | | | 429 | ); |
| 0542c45 | | | 430 | fs.rmSync(path.join(cwd, '.sl'), {recursive: true, force: true}); |
| 0542c45 | | | 431 | await ejeca( |
| 0542c45 | | | 432 | cmd, |
| 0542c45 | | | 433 | [ |
| 0542c45 | | | 434 | 'init', |
| 0542c45 | | | 435 | '--config', |
| 0542c45 | | | 436 | 'init.prefer-git=false', |
| 0542c45 | | | 437 | '--config', |
| 0542c45 | | | 438 | 'format.use-remotefilelog=true', |
| 0542c45 | | | 439 | cwd, |
| 0542c45 | | | 440 | ], |
| 0542c45 | | | 441 | {cwd}, |
| 0542c45 | | | 442 | ); |
| 0542c45 | | | 443 | } |
| 0542c45 | | | 444 | } catch { |
| 0542c45 | | | 445 | // No .sl/store/requires means no repo yet — init fresh |
| 0542c45 | | | 446 | if (!fs.existsSync(path.join(cwd, '.sl'))) { |
| 0542c45 | | | 447 | await ejeca( |
| 0542c45 | | | 448 | cmd, |
| 0542c45 | | | 449 | [ |
| 0542c45 | | | 450 | 'init', |
| 0542c45 | | | 451 | '--config', |
| 0542c45 | | | 452 | 'init.prefer-git=false', |
| 0542c45 | | | 453 | '--config', |
| 0542c45 | | | 454 | 'format.use-remotefilelog=true', |
| 0542c45 | | | 455 | cwd, |
| 0542c45 | | | 456 | ], |
| 0542c45 | | | 457 | {cwd}, |
| 0542c45 | | | 458 | ); |
| 0542c45 | | | 459 | } |
| 0542c45 | | | 460 | } |
| 0542c45 | | | 461 | |
| 0542c45 | | | 462 | // Configure sapling remote |
| 6c9fcae | | | 463 | const configPairs = [ |
| 6c9fcae | | | 464 | ['paths.default', `mononoke://grove.host:8443/${repoName}`], |
| 6c9fcae | | | 465 | ['remotefilelog.reponame', repoName], |
| 6c9fcae | | | 466 | ['grove.owner', owner], |
| 6c9fcae | | | 467 | ['edenapi.url', 'https://grove.host:8443/edenapi/'], |
| 6c9fcae | | | 468 | ['web.cacerts', `${homedir}/.grove/tls/ca.crt`], |
| 6c9fcae | | | 469 | ['auth.grove.prefix', 'https://grove.host'], |
| 6c9fcae | | | 470 | ['auth.grove.cert', `${homedir}/.grove/tls/client.crt`], |
| 6c9fcae | | | 471 | ['auth.grove.key', `${homedir}/.grove/tls/client.key`], |
| 6c9fcae | | | 472 | ['auth.grove.cacerts', `${homedir}/.grove/tls/ca.crt`], |
| 6c9fcae | | | 473 | ['auth.grove-mononoke.prefix', 'mononoke://grove.host'], |
| 6c9fcae | | | 474 | ['auth.grove-mononoke.cert', `${homedir}/.grove/tls/client.crt`], |
| 6c9fcae | | | 475 | ['auth.grove-mononoke.key', `${homedir}/.grove/tls/client.key`], |
| 6c9fcae | | | 476 | ['auth.grove-mononoke.cacerts', `${homedir}/.grove/tls/ca.crt`], |
| 6c9fcae | | | 477 | ['clone.use-commit-graph', 'true'], |
| 6c9fcae | | | 478 | ['remotenames.selectivepulldefault', 'main'], |
| 6c9fcae | | | 479 | ['push.edenapi', 'true'], |
| 6c9fcae | | | 480 | ['push.to', 'main'], |
| 6c9fcae | | | 481 | ]; |
| 6c9fcae | | | 482 | for (const [key, value] of configPairs) { |
| 6c9fcae | | | 483 | await ejeca(cmd, ['config', '--local', key, value], {cwd}); |
| 6c9fcae | | | 484 | } |
| 6c9fcae | | | 485 | |
| 0542c45 | | | 486 | // Pull the seed commit and check out main |
| 0542c45 | | | 487 | try { |
| 0542c45 | | | 488 | await ejeca(cmd, ['pull'], {cwd}); |
| 0542c45 | | | 489 | await ejeca(cmd, ['goto', 'main'], {cwd}); |
| 0542c45 | | | 490 | } catch (pullErr) { |
| 0542c45 | | | 491 | this.logger.info('Pull after repo creation failed (may not be seeded yet):', pullErr); |
| 0542c45 | | | 492 | } |
| 0542c45 | | | 493 | |
| 6c9fcae | | | 494 | // Re-detect repo info and send it to the client |
| 6c9fcae | | | 495 | const ctx = { |
| 6c9fcae | | | 496 | cwd, |
| 6c9fcae | | | 497 | cmd, |
| 6c9fcae | | | 498 | logger: this.logger, |
| 6c9fcae | | | 499 | tracker: this.tracker, |
| 6c9fcae | | | 500 | }; |
| 6c9fcae | | | 501 | const newInfo = await Repository.getRepoInfo(ctx); |
| 6c9fcae | | | 502 | this.postMessage({type: 'repoInfo', info: newInfo, cwd}); |
| 6c9fcae | | | 503 | |
| 6c9fcae | | | 504 | // Also re-initialize the repo in the cache so subscriptions work |
| 6c9fcae | | | 505 | this.setActiveRepoForCwd(cwd); |
| 6c9fcae | | | 506 | |
| 6c9fcae | | | 507 | this.postMessage({ |
| 6c9fcae | | | 508 | type: 'createdGroveRepo', |
| 6c9fcae | | | 509 | result: {value: {owner, repo: repoName}}, |
| 6c9fcae | | | 510 | }); |
| 6c9fcae | | | 511 | } catch (err) { |
| 6c9fcae | | | 512 | this.logger.error('Failed to create Grove repo:', err); |
| 6c9fcae | | | 513 | this.postMessage({ |
| 6c9fcae | | | 514 | type: 'createdGroveRepo', |
| 6c9fcae | | | 515 | result: {error: err instanceof Error ? err : new Error(String(err))}, |
| 6c9fcae | | | 516 | }); |
| 6c9fcae | | | 517 | } |
| 6c9fcae | | | 518 | })(); |
| 6c9fcae | | | 519 | break; |
| 6c9fcae | | | 520 | } |
| b69ab31 | | | 521 | } |
| b69ab31 | | | 522 | } |
| b69ab31 | | | 523 | |
| b69ab31 | | | 524 | private handleMaybeForgotOperation(operationId: string, repo: Repository) { |
| b69ab31 | | | 525 | if (repo.getRunningOperation()?.id !== operationId) { |
| b69ab31 | | | 526 | this.postMessage({type: 'operationProgress', id: operationId, kind: 'forgot'}); |
| b69ab31 | | | 527 | } |
| b69ab31 | | | 528 | } |
| b69ab31 | | | 529 | |
| b69ab31 | | | 530 | /** |
| b69ab31 | | | 531 | * Handle messages which require a repository to have been successfully set up to run |
| b69ab31 | | | 532 | */ |
| b69ab31 | | | 533 | private handleIncomingMessageWithRepo( |
| b69ab31 | | | 534 | data: WithRepoMessage, |
| b69ab31 | | | 535 | repo: Repository, |
| b69ab31 | | | 536 | ctx: RepositoryContext, |
| b69ab31 | | | 537 | ) { |
| b69ab31 | | | 538 | const {cwd, logger} = ctx; |
| b69ab31 | | | 539 | switch (data.type) { |
| b69ab31 | | | 540 | case 'subscribe': { |
| b69ab31 | | | 541 | const {subscriptionID, kind} = data; |
| b69ab31 | | | 542 | switch (kind) { |
| b69ab31 | | | 543 | case 'uncommittedChanges': { |
| b69ab31 | | | 544 | const postUncommittedChanges = (result: FetchedUncommittedChanges) => { |
| b69ab31 | | | 545 | this.postMessage({ |
| b69ab31 | | | 546 | type: 'subscriptionResult', |
| b69ab31 | | | 547 | kind: 'uncommittedChanges', |
| b69ab31 | | | 548 | subscriptionID, |
| b69ab31 | | | 549 | data: result, |
| b69ab31 | | | 550 | }); |
| b69ab31 | | | 551 | }; |
| b69ab31 | | | 552 | |
| b69ab31 | | | 553 | const uncommittedChanges = repo.getUncommittedChanges(); |
| b69ab31 | | | 554 | if (uncommittedChanges != null) { |
| b69ab31 | | | 555 | postUncommittedChanges(uncommittedChanges); |
| b69ab31 | | | 556 | } |
| b69ab31 | | | 557 | const disposables: Array<Disposable> = []; |
| b69ab31 | | | 558 | |
| b69ab31 | | | 559 | // send changes as they come in from watchman |
| b69ab31 | | | 560 | disposables.push(repo.subscribeToUncommittedChanges(postUncommittedChanges)); |
| b69ab31 | | | 561 | // trigger a fetch on startup |
| b69ab31 | | | 562 | repo.fetchUncommittedChanges(); |
| b69ab31 | | | 563 | |
| b69ab31 | | | 564 | disposables.push( |
| b69ab31 | | | 565 | repo.subscribeToUncommittedChangesBeginFetching(() => |
| b69ab31 | | | 566 | this.postMessage({type: 'beganFetchingUncommittedChangesEvent'}), |
| b69ab31 | | | 567 | ), |
| b69ab31 | | | 568 | ); |
| b69ab31 | | | 569 | this.subscriptions.set(subscriptionID, { |
| b69ab31 | | | 570 | dispose: () => { |
| b69ab31 | | | 571 | disposables.forEach(d => d.dispose()); |
| b69ab31 | | | 572 | }, |
| b69ab31 | | | 573 | }); |
| b69ab31 | | | 574 | break; |
| b69ab31 | | | 575 | } |
| b69ab31 | | | 576 | case 'smartlogCommits': { |
| b69ab31 | | | 577 | const postSmartlogCommits = (result: FetchedCommits) => { |
| b69ab31 | | | 578 | this.postMessage({ |
| b69ab31 | | | 579 | type: 'subscriptionResult', |
| b69ab31 | | | 580 | kind: 'smartlogCommits', |
| b69ab31 | | | 581 | subscriptionID, |
| b69ab31 | | | 582 | data: result, |
| b69ab31 | | | 583 | }); |
| b69ab31 | | | 584 | }; |
| b69ab31 | | | 585 | |
| b69ab31 | | | 586 | const smartlogCommits = repo.getSmartlogCommits(); |
| b69ab31 | | | 587 | if (smartlogCommits != null) { |
| b69ab31 | | | 588 | postSmartlogCommits(smartlogCommits); |
| b69ab31 | | | 589 | } |
| b69ab31 | | | 590 | const disposables: Array<Disposable> = []; |
| b69ab31 | | | 591 | // send changes as they come from file watcher |
| b69ab31 | | | 592 | disposables.push(repo.subscribeToSmartlogCommitsChanges(postSmartlogCommits)); |
| b69ab31 | | | 593 | |
| b69ab31 | | | 594 | // trigger fetch on startup |
| b69ab31 | | | 595 | repo.fetchSmartlogCommits(); |
| b69ab31 | | | 596 | |
| b69ab31 | | | 597 | disposables.push( |
| b69ab31 | | | 598 | repo.subscribeToSmartlogCommitsBeginFetching(() => |
| b69ab31 | | | 599 | this.postMessage({type: 'beganFetchingSmartlogCommitsEvent'}), |
| b69ab31 | | | 600 | ), |
| b69ab31 | | | 601 | ); |
| b69ab31 | | | 602 | |
| b69ab31 | | | 603 | this.subscriptions.set(subscriptionID, { |
| b69ab31 | | | 604 | dispose: () => { |
| b69ab31 | | | 605 | disposables.forEach(d => d.dispose()); |
| b69ab31 | | | 606 | }, |
| b69ab31 | | | 607 | }); |
| b69ab31 | | | 608 | break; |
| b69ab31 | | | 609 | } |
| b69ab31 | | | 610 | case 'mergeConflicts': { |
| b69ab31 | | | 611 | const postMergeConflicts = (conflicts: MergeConflicts | undefined) => { |
| b69ab31 | | | 612 | this.postMessage({ |
| b69ab31 | | | 613 | type: 'subscriptionResult', |
| b69ab31 | | | 614 | kind: 'mergeConflicts', |
| b69ab31 | | | 615 | subscriptionID, |
| b69ab31 | | | 616 | data: conflicts, |
| b69ab31 | | | 617 | }); |
| b69ab31 | | | 618 | }; |
| b69ab31 | | | 619 | |
| b69ab31 | | | 620 | const mergeConflicts = repo.getMergeConflicts(); |
| b69ab31 | | | 621 | if (mergeConflicts != null) { |
| b69ab31 | | | 622 | postMergeConflicts(mergeConflicts); |
| b69ab31 | | | 623 | } |
| b69ab31 | | | 624 | |
| b69ab31 | | | 625 | this.subscriptions.set(subscriptionID, repo.onChangeConflictState(postMergeConflicts)); |
| b69ab31 | | | 626 | break; |
| b69ab31 | | | 627 | } |
| b69ab31 | | | 628 | case 'submodules': { |
| b69ab31 | | | 629 | const postSubmodules = (submodulesByRoot: SubmodulesByRoot) => { |
| b69ab31 | | | 630 | this.postMessage({ |
| b69ab31 | | | 631 | type: 'subscriptionResult', |
| b69ab31 | | | 632 | kind: 'submodules', |
| b69ab31 | | | 633 | subscriptionID, |
| b69ab31 | | | 634 | data: submodulesByRoot, |
| b69ab31 | | | 635 | }); |
| b69ab31 | | | 636 | }; |
| b69ab31 | | | 637 | const submoduleMap = repo.getSubmoduleMap(); |
| b69ab31 | | | 638 | if (submoduleMap !== undefined) { |
| b69ab31 | | | 639 | postSubmodules(submoduleMap); |
| b69ab31 | | | 640 | } |
| b69ab31 | | | 641 | repo.fetchSubmoduleMap(); |
| b69ab31 | | | 642 | |
| b69ab31 | | | 643 | const disposable = repo.subscribeToSubmodulesChanges(postSubmodules); |
| b69ab31 | | | 644 | this.subscriptions.set(subscriptionID, { |
| b69ab31 | | | 645 | dispose: () => { |
| b69ab31 | | | 646 | disposable.dispose(); |
| b69ab31 | | | 647 | }, |
| b69ab31 | | | 648 | }); |
| b69ab31 | | | 649 | break; |
| b69ab31 | | | 650 | } |
| b69ab31 | | | 651 | case 'subscribedFullRepoBranches': { |
| b69ab31 | | | 652 | const fullRepoBranchModule = repo.fullRepoBranchModule; |
| b69ab31 | | | 653 | if (fullRepoBranchModule == null) { |
| b69ab31 | | | 654 | return; |
| b69ab31 | | | 655 | } |
| b69ab31 | | | 656 | |
| b69ab31 | | | 657 | const postSubscribedFullRepoBranches = ( |
| b69ab31 | | | 658 | result: Array<InternalTypes['FullRepoBranch']>, |
| b69ab31 | | | 659 | ) => { |
| b69ab31 | | | 660 | this.postMessage({ |
| b69ab31 | | | 661 | type: 'subscriptionResult', |
| b69ab31 | | | 662 | kind: 'subscribedFullRepoBranches', |
| b69ab31 | | | 663 | subscriptionID, |
| b69ab31 | | | 664 | data: result, |
| b69ab31 | | | 665 | }); |
| b69ab31 | | | 666 | }; |
| b69ab31 | | | 667 | |
| b69ab31 | | | 668 | const subscribedFullRepoBranches = fullRepoBranchModule.getSubscribedFullRepoBranches(); |
| b69ab31 | | | 669 | if (subscribedFullRepoBranches != null) { |
| b69ab31 | | | 670 | postSubscribedFullRepoBranches(subscribedFullRepoBranches); |
| b69ab31 | | | 671 | } |
| b69ab31 | | | 672 | const disposables: Array<Disposable> = []; |
| b69ab31 | | | 673 | // send changes as they come from file watcher |
| b69ab31 | | | 674 | disposables.push( |
| b69ab31 | | | 675 | fullRepoBranchModule.subscribeToSubscribedFullRepoBranchesChanges( |
| b69ab31 | | | 676 | postSubscribedFullRepoBranches, |
| b69ab31 | | | 677 | ), |
| b69ab31 | | | 678 | ); |
| b69ab31 | | | 679 | // trigger a fetch on startup |
| b69ab31 | | | 680 | fullRepoBranchModule.pullSubscribedFullRepoBranches(); |
| b69ab31 | | | 681 | |
| b69ab31 | | | 682 | disposables.push( |
| b69ab31 | | | 683 | fullRepoBranchModule.subscribeToSubscribedFullRepoBranchesBeginFetching(() => |
| b69ab31 | | | 684 | this.postMessage({type: 'beganFetchingSubscribedFullRepoBranchesEvent'}), |
| b69ab31 | | | 685 | ), |
| b69ab31 | | | 686 | ); |
| b69ab31 | | | 687 | |
| b69ab31 | | | 688 | this.subscriptions.set(subscriptionID, { |
| b69ab31 | | | 689 | dispose: () => { |
| b69ab31 | | | 690 | disposables.forEach(d => d.dispose()); |
| b69ab31 | | | 691 | }, |
| b69ab31 | | | 692 | }); |
| b69ab31 | | | 693 | break; |
| b69ab31 | | | 694 | } |
| b69ab31 | | | 695 | } |
| b69ab31 | | | 696 | break; |
| b69ab31 | | | 697 | } |
| b69ab31 | | | 698 | case 'unsubscribe': { |
| b69ab31 | | | 699 | const subscription = this.subscriptions.get(data.subscriptionID); |
| b69ab31 | | | 700 | subscription?.dispose(); |
| b69ab31 | | | 701 | this.subscriptions.delete(data.subscriptionID); |
| b69ab31 | | | 702 | break; |
| b69ab31 | | | 703 | } |
| b69ab31 | | | 704 | case 'runOperation': { |
| 4bb999b | | | 705 | if (this.connection.readOnly) { |
| 4bb999b | | | 706 | const {operation} = data; |
| 4bb999b | | | 707 | this.postMessage({ |
| 4bb999b | | | 708 | type: 'operationProgress', |
| 4bb999b | | | 709 | kind: 'exit', |
| 4bb999b | | | 710 | exitCode: 1, |
| 4bb999b | | | 711 | id: operation.id, |
| 4bb999b | | | 712 | timestamp: Date.now() / 1000, |
| 4bb999b | | | 713 | }); |
| 4bb999b | | | 714 | break; |
| 4bb999b | | | 715 | } |
| b69ab31 | | | 716 | const {operation} = data; |
| b69ab31 | | | 717 | repo.runOrQueueOperation(ctx, operation, progress => { |
| b69ab31 | | | 718 | this.postMessage({type: 'operationProgress', ...progress}); |
| b69ab31 | | | 719 | if (progress.kind === 'queue') { |
| b69ab31 | | | 720 | this.tracker.track('QueueOperation', {extras: {operation: operation.trackEventName}}); |
| b69ab31 | | | 721 | } |
| b69ab31 | | | 722 | }); |
| b69ab31 | | | 723 | break; |
| b69ab31 | | | 724 | } |
| b69ab31 | | | 725 | case 'abortRunningOperation': { |
| 4bb999b | | | 726 | if (this.connection.readOnly) { |
| 4bb999b | | | 727 | break; |
| 4bb999b | | | 728 | } |
| b69ab31 | | | 729 | const {operationId} = data; |
| b69ab31 | | | 730 | repo.abortRunningOperation(operationId); |
| b69ab31 | | | 731 | this.handleMaybeForgotOperation(operationId, repo); |
| b69ab31 | | | 732 | break; |
| b69ab31 | | | 733 | } |
| b69ab31 | | | 734 | case 'getConfig': { |
| b69ab31 | | | 735 | repo |
| b69ab31 | | | 736 | .getConfig(ctx, data.name) |
| b69ab31 | | | 737 | .catch(() => undefined) |
| b69ab31 | | | 738 | .then(value => { |
| b69ab31 | | | 739 | logger.info('got config', data.name, value); |
| b69ab31 | | | 740 | this.postMessage({type: 'gotConfig', name: data.name, value}); |
| b69ab31 | | | 741 | }); |
| b69ab31 | | | 742 | break; |
| b69ab31 | | | 743 | } |
| b69ab31 | | | 744 | case 'setConfig': { |
| b69ab31 | | | 745 | logger.info('set config', data.name, data.value); |
| b69ab31 | | | 746 | repo.setConfig(ctx, 'user', data.name, data.value).catch(err => { |
| b69ab31 | | | 747 | logger.error('error setting config', data.name, data.value, err); |
| b69ab31 | | | 748 | }); |
| b69ab31 | | | 749 | break; |
| b69ab31 | | | 750 | } |
| b69ab31 | | | 751 | case 'setDebugLogging': { |
| b69ab31 | | | 752 | logger.info('set debug', data.name, data.enabled); |
| b69ab31 | | | 753 | if (data.name === 'debug' || data.name === 'verbose') { |
| b69ab31 | | | 754 | ctx[data.name] = !!data.enabled; |
| b69ab31 | | | 755 | } |
| b69ab31 | | | 756 | break; |
| b69ab31 | | | 757 | } |
| b69ab31 | | | 758 | case 'requestComparison': { |
| b69ab31 | | | 759 | const {comparison} = data; |
| b69ab31 | | | 760 | const diff: Promise<Result<string>> = repo |
| b69ab31 | | | 761 | .runDiff(ctx, comparison) |
| b69ab31 | | | 762 | .then(value => ({value})) |
| b69ab31 | | | 763 | .catch(error => { |
| b69ab31 | | | 764 | logger?.error('error running diff', error.toString()); |
| b69ab31 | | | 765 | return {error}; |
| b69ab31 | | | 766 | }); |
| b69ab31 | | | 767 | diff.then(data => |
| b69ab31 | | | 768 | this.postMessage({ |
| b69ab31 | | | 769 | type: 'comparison', |
| b69ab31 | | | 770 | comparison, |
| b69ab31 | | | 771 | data: {diff: data}, |
| b69ab31 | | | 772 | }), |
| b69ab31 | | | 773 | ); |
| b69ab31 | | | 774 | break; |
| b69ab31 | | | 775 | } |
| b69ab31 | | | 776 | case 'requestComparisonContextLines': { |
| b69ab31 | | | 777 | const { |
| b69ab31 | | | 778 | id: {path: relativePath, comparison}, |
| b69ab31 | | | 779 | // This is the line number in the "before" side of the comparison |
| b69ab31 | | | 780 | start, |
| b69ab31 | | | 781 | // This is the number of context lines to fetch |
| b69ab31 | | | 782 | numLines, |
| b69ab31 | | | 783 | } = data; |
| b69ab31 | | | 784 | |
| b69ab31 | | | 785 | const absolutePath = path.join(repo.info.repoRoot, relativePath); |
| b69ab31 | | | 786 | |
| b69ab31 | | | 787 | // TODO: For context lines, before/after sides of the comparison |
| b69ab31 | | | 788 | // are identical... except for line numbers. |
| b69ab31 | | | 789 | // Typical comparisons with '.' would be much faster (nearly instant) |
| b69ab31 | | | 790 | // by reading from the filesystem rather than using cat, |
| b69ab31 | | | 791 | // we just need the caller to ask with "after" line numbers instead of "before". |
| b69ab31 | | | 792 | // Note: we would still need to fall back to cat for comparisons that do not involve |
| b69ab31 | | | 793 | // the working copy. |
| b69ab31 | | | 794 | const cat: Promise<string> = repo.cat( |
| b69ab31 | | | 795 | ctx, |
| b69ab31 | | | 796 | absolutePath, |
| b69ab31 | | | 797 | beforeRevsetForComparison(comparison), |
| b69ab31 | | | 798 | ); |
| b69ab31 | | | 799 | |
| b69ab31 | | | 800 | cat |
| b69ab31 | | | 801 | .then(content => |
| b69ab31 | | | 802 | this.postMessage({ |
| b69ab31 | | | 803 | type: 'comparisonContextLines', |
| b69ab31 | | | 804 | lines: {value: content.split('\n').slice(start - 1, start - 1 + numLines)}, |
| b69ab31 | | | 805 | path: relativePath, |
| b69ab31 | | | 806 | }), |
| b69ab31 | | | 807 | ) |
| b69ab31 | | | 808 | .catch((error: Error) => |
| b69ab31 | | | 809 | this.postMessage({ |
| b69ab31 | | | 810 | type: 'comparisonContextLines', |
| b69ab31 | | | 811 | lines: {error}, |
| b69ab31 | | | 812 | path: relativePath, |
| b69ab31 | | | 813 | }), |
| b69ab31 | | | 814 | ); |
| b69ab31 | | | 815 | break; |
| b69ab31 | | | 816 | } |
| b69ab31 | | | 817 | case 'requestMissedOperationProgress': { |
| b69ab31 | | | 818 | const {operationId} = data; |
| b69ab31 | | | 819 | this.handleMaybeForgotOperation(operationId, repo); |
| b69ab31 | | | 820 | break; |
| b69ab31 | | | 821 | } |
| b69ab31 | | | 822 | case 'refresh': { |
| b69ab31 | | | 823 | logger?.log('refresh requested'); |
| b69ab31 | | | 824 | repo.fetchAndSetRecommendedBookmarks(bookmarks => { |
| b69ab31 | | | 825 | this.postMessage({type: 'fetchedRecommendedBookmarks', bookmarks}); |
| b69ab31 | | | 826 | }); |
| b69ab31 | | | 827 | repo.fetchSmartlogCommits(); |
| b69ab31 | | | 828 | repo.fetchUncommittedChanges(); |
| b69ab31 | | | 829 | repo.fetchSubmoduleMap(); |
| b69ab31 | | | 830 | repo.checkForMergeConflicts(); |
| b69ab31 | | | 831 | repo.fullRepoBranchModule?.pullSubscribedFullRepoBranches(); |
| b69ab31 | | | 832 | repo.codeReviewProvider?.triggerDiffSummariesFetch(repo.getAllDiffIds()); |
| b69ab31 | | | 833 | repo.initialConnectionContext.tracker.track('DiffFetchSource', { |
| b69ab31 | | | 834 | extras: {source: 'manual_refresh'}, |
| b69ab31 | | | 835 | }); |
| b69ab31 | | | 836 | generatedFilesDetector.clear(); // allow generated files to be rechecked |
| b69ab31 | | | 837 | break; |
| b69ab31 | | | 838 | } |
| b69ab31 | | | 839 | case 'pageVisibility': { |
| b69ab31 | | | 840 | repo.setPageFocus(this.pageId, data.state); |
| b69ab31 | | | 841 | break; |
| b69ab31 | | | 842 | } |
| b69ab31 | | | 843 | case 'uploadFile': { |
| b69ab31 | | | 844 | const {id, filename, b64Content} = data; |
| b69ab31 | | | 845 | const payload = base64Decode(b64Content); |
| b69ab31 | | | 846 | const uploadFile = Internal.uploadFile; |
| b69ab31 | | | 847 | if (uploadFile == null) { |
| b69ab31 | | | 848 | return; |
| b69ab31 | | | 849 | } |
| b69ab31 | | | 850 | this.tracker |
| b69ab31 | | | 851 | .operation('UploadImage', 'UploadImageError', {}, () => |
| b69ab31 | | | 852 | uploadFile(this.logger, {filename, data: payload}), |
| b69ab31 | | | 853 | ) |
| b69ab31 | | | 854 | .then((result: string) => { |
| b69ab31 | | | 855 | this.logger.info('successfully uploaded file', filename, result); |
| b69ab31 | | | 856 | this.postMessage({type: 'uploadFileResult', id, result: {value: result}}); |
| b69ab31 | | | 857 | }) |
| b69ab31 | | | 858 | .catch((error: Error) => { |
| b69ab31 | | | 859 | this.logger.info('error uploading file', filename, error); |
| b69ab31 | | | 860 | this.postMessage({type: 'uploadFileResult', id, result: {error}}); |
| b69ab31 | | | 861 | }); |
| b69ab31 | | | 862 | break; |
| b69ab31 | | | 863 | } |
| b69ab31 | | | 864 | case 'fetchCommitMessageTemplate': { |
| b69ab31 | | | 865 | this.handleFetchCommitMessageTemplate(repo, ctx); |
| b69ab31 | | | 866 | break; |
| b69ab31 | | | 867 | } |
| b69ab31 | | | 868 | case 'fetchShelvedChanges': { |
| b69ab31 | | | 869 | repo |
| b69ab31 | | | 870 | .getShelvedChanges(ctx) |
| b69ab31 | | | 871 | .then(shelvedChanges => { |
| b69ab31 | | | 872 | this.postMessage({ |
| b69ab31 | | | 873 | type: 'fetchedShelvedChanges', |
| b69ab31 | | | 874 | shelvedChanges: {value: shelvedChanges}, |
| b69ab31 | | | 875 | }); |
| b69ab31 | | | 876 | }) |
| b69ab31 | | | 877 | .catch(err => { |
| b69ab31 | | | 878 | logger?.error('Could not fetch shelved changes', err); |
| b69ab31 | | | 879 | this.postMessage({type: 'fetchedShelvedChanges', shelvedChanges: {error: err}}); |
| b69ab31 | | | 880 | }); |
| b69ab31 | | | 881 | break; |
| b69ab31 | | | 882 | } |
| b69ab31 | | | 883 | case 'fetchLatestCommit': { |
| b69ab31 | | | 884 | repo |
| b69ab31 | | | 885 | .lookupCommits(ctx, [data.revset]) |
| b69ab31 | | | 886 | .then(commits => { |
| b69ab31 | | | 887 | const commit = firstOfIterable(commits.values()); |
| b69ab31 | | | 888 | if (commit == null) { |
| b69ab31 | | | 889 | throw new Error(`No commit found for revset ${data.revset}`); |
| b69ab31 | | | 890 | } |
| b69ab31 | | | 891 | this.postMessage({ |
| b69ab31 | | | 892 | type: 'fetchedLatestCommit', |
| b69ab31 | | | 893 | revset: data.revset, |
| b69ab31 | | | 894 | info: {value: commit}, |
| b69ab31 | | | 895 | }); |
| b69ab31 | | | 896 | }) |
| b69ab31 | | | 897 | .catch(err => { |
| b69ab31 | | | 898 | this.postMessage({ |
| b69ab31 | | | 899 | type: 'fetchedLatestCommit', |
| b69ab31 | | | 900 | revset: data.revset, |
| b69ab31 | | | 901 | info: {error: err as Error}, |
| b69ab31 | | | 902 | }); |
| b69ab31 | | | 903 | }); |
| b69ab31 | | | 904 | break; |
| b69ab31 | | | 905 | } |
| b69ab31 | | | 906 | case 'fetchPendingSignificantLinesOfCode': |
| b69ab31 | | | 907 | { |
| b69ab31 | | | 908 | repo |
| b69ab31 | | | 909 | .fetchPendingSignificantLinesOfCode(ctx, data.hash, data.includedFiles) |
| b69ab31 | | | 910 | .then(value => { |
| b69ab31 | | | 911 | this.postMessage({ |
| b69ab31 | | | 912 | type: 'fetchedPendingSignificantLinesOfCode', |
| b69ab31 | | | 913 | requestId: data.requestId, |
| b69ab31 | | | 914 | hash: data.hash, |
| b69ab31 | | | 915 | result: {value: value ?? 0}, |
| b69ab31 | | | 916 | }); |
| b69ab31 | | | 917 | }) |
| b69ab31 | | | 918 | .catch(err => { |
| b69ab31 | | | 919 | this.postMessage({ |
| b69ab31 | | | 920 | type: 'fetchedPendingSignificantLinesOfCode', |
| b69ab31 | | | 921 | hash: data.hash, |
| b69ab31 | | | 922 | requestId: data.requestId, |
| b69ab31 | | | 923 | result: {error: err as Error}, |
| b69ab31 | | | 924 | }); |
| b69ab31 | | | 925 | }); |
| b69ab31 | | | 926 | } |
| b69ab31 | | | 927 | break; |
| b69ab31 | | | 928 | case 'fetchSignificantLinesOfCode': |
| b69ab31 | | | 929 | { |
| b69ab31 | | | 930 | repo |
| b69ab31 | | | 931 | .fetchSignificantLinesOfCode(ctx, data.hash, data.excludedFiles) |
| b69ab31 | | | 932 | .then(value => { |
| b69ab31 | | | 933 | this.postMessage({ |
| b69ab31 | | | 934 | type: 'fetchedSignificantLinesOfCode', |
| b69ab31 | | | 935 | hash: data.hash, |
| b69ab31 | | | 936 | result: {value: value ?? 0}, |
| b69ab31 | | | 937 | }); |
| b69ab31 | | | 938 | }) |
| b69ab31 | | | 939 | .catch(err => { |
| b69ab31 | | | 940 | this.postMessage({ |
| b69ab31 | | | 941 | type: 'fetchedSignificantLinesOfCode', |
| b69ab31 | | | 942 | hash: data.hash, |
| b69ab31 | | | 943 | result: {error: err as Error}, |
| b69ab31 | | | 944 | }); |
| b69ab31 | | | 945 | }); |
| b69ab31 | | | 946 | } |
| b69ab31 | | | 947 | break; |
| b69ab31 | | | 948 | case 'fetchPendingAmendSignificantLinesOfCode': |
| b69ab31 | | | 949 | { |
| b69ab31 | | | 950 | repo |
| b69ab31 | | | 951 | .fetchPendingAmendSignificantLinesOfCode(ctx, data.hash, data.includedFiles) |
| b69ab31 | | | 952 | .then(value => { |
| b69ab31 | | | 953 | this.postMessage({ |
| b69ab31 | | | 954 | type: 'fetchedPendingAmendSignificantLinesOfCode', |
| b69ab31 | | | 955 | requestId: data.requestId, |
| b69ab31 | | | 956 | hash: data.hash, |
| b69ab31 | | | 957 | result: {value: value ?? 0}, |
| b69ab31 | | | 958 | }); |
| b69ab31 | | | 959 | }) |
| b69ab31 | | | 960 | .catch(err => { |
| b69ab31 | | | 961 | this.postMessage({ |
| b69ab31 | | | 962 | type: 'fetchedPendingAmendSignificantLinesOfCode', |
| b69ab31 | | | 963 | hash: data.hash, |
| b69ab31 | | | 964 | requestId: data.requestId, |
| b69ab31 | | | 965 | result: {error: err as Error}, |
| b69ab31 | | | 966 | }); |
| b69ab31 | | | 967 | }); |
| b69ab31 | | | 968 | } |
| b69ab31 | | | 969 | break; |
| b69ab31 | | | 970 | case 'fetchCommitChangedFiles': { |
| b69ab31 | | | 971 | repo |
| b69ab31 | | | 972 | .getAllChangedFiles(ctx, data.hash) |
| b69ab31 | | | 973 | .then(files => { |
| b69ab31 | | | 974 | this.postMessage({ |
| b69ab31 | | | 975 | type: 'fetchedCommitChangedFiles', |
| b69ab31 | | | 976 | hash: data.hash, |
| b69ab31 | | | 977 | result: { |
| b69ab31 | | | 978 | value: { |
| b69ab31 | | | 979 | filesSample: data.limit != null ? files.slice(0, data.limit) : files, |
| b69ab31 | | | 980 | totalFileCount: files.length, |
| b69ab31 | | | 981 | }, |
| b69ab31 | | | 982 | }, |
| b69ab31 | | | 983 | }); |
| b69ab31 | | | 984 | }) |
| b69ab31 | | | 985 | .catch(err => { |
| b69ab31 | | | 986 | this.postMessage({ |
| b69ab31 | | | 987 | type: 'fetchedCommitChangedFiles', |
| b69ab31 | | | 988 | hash: data.hash, |
| b69ab31 | | | 989 | result: {error: err as Error}, |
| b69ab31 | | | 990 | }); |
| b69ab31 | | | 991 | }); |
| b69ab31 | | | 992 | break; |
| b69ab31 | | | 993 | } |
| b69ab31 | | | 994 | case 'fetchCommitCloudState': { |
| b69ab31 | | | 995 | repo.getCommitCloudState(ctx).then(state => { |
| b69ab31 | | | 996 | this.postMessage({ |
| b69ab31 | | | 997 | type: 'fetchedCommitCloudState', |
| b69ab31 | | | 998 | state: {value: state}, |
| b69ab31 | | | 999 | }); |
| b69ab31 | | | 1000 | }); |
| b69ab31 | | | 1001 | break; |
| b69ab31 | | | 1002 | } |
| b69ab31 | | | 1003 | case 'fetchGeneratedStatuses': { |
| b69ab31 | | | 1004 | generatedFilesDetector |
| b69ab31 | | | 1005 | .queryFilesGenerated(repo, ctx, repo.info.repoRoot, data.paths) |
| b69ab31 | | | 1006 | .then(results => { |
| b69ab31 | | | 1007 | this.postMessage({type: 'fetchedGeneratedStatuses', results}); |
| b69ab31 | | | 1008 | }); |
| b69ab31 | | | 1009 | break; |
| b69ab31 | | | 1010 | } |
| b69ab31 | | | 1011 | case 'typeahead': { |
| b69ab31 | | | 1012 | // Current repo's code review provider should be able to handle all |
| b69ab31 | | | 1013 | // TypeaheadKinds for the fields in its defined schema. |
| b69ab31 | | | 1014 | repo.codeReviewProvider?.typeahead?.(data.kind, data.query, cwd)?.then(result => |
| b69ab31 | | | 1015 | this.postMessage({ |
| b69ab31 | | | 1016 | type: 'typeaheadResult', |
| b69ab31 | | | 1017 | id: data.id, |
| b69ab31 | | | 1018 | result, |
| b69ab31 | | | 1019 | }), |
| b69ab31 | | | 1020 | ); |
| b69ab31 | | | 1021 | break; |
| b69ab31 | | | 1022 | } |
| b69ab31 | | | 1023 | case 'fetchDiffSummaries': { |
| b69ab31 | | | 1024 | repo.codeReviewProvider?.triggerDiffSummariesFetch(data.diffIds ?? repo.getAllDiffIds()); |
| b69ab31 | | | 1025 | break; |
| b69ab31 | | | 1026 | } |
| e7069e1 | | | 1027 | case 'fetchCanopySignals': { |
| e7069e1 | | | 1028 | repo.codeReviewProvider?.triggerCanopySignalsFetch?.(); |
| e7069e1 | | | 1029 | break; |
| e7069e1 | | | 1030 | } |
| b69ab31 | | | 1031 | case 'fetchLandInfo': { |
| b69ab31 | | | 1032 | repo.codeReviewProvider |
| b69ab31 | | | 1033 | ?.fetchLandInfo?.(data.topOfStack) |
| b69ab31 | | | 1034 | ?.then((landInfo: LandInfo) => { |
| b69ab31 | | | 1035 | this.postMessage({ |
| b69ab31 | | | 1036 | type: 'fetchedLandInfo', |
| b69ab31 | | | 1037 | topOfStack: data.topOfStack, |
| b69ab31 | | | 1038 | landInfo: {value: landInfo}, |
| b69ab31 | | | 1039 | }); |
| b69ab31 | | | 1040 | }) |
| b69ab31 | | | 1041 | .catch(err => { |
| b69ab31 | | | 1042 | this.postMessage({ |
| b69ab31 | | | 1043 | type: 'fetchedLandInfo', |
| b69ab31 | | | 1044 | topOfStack: data.topOfStack, |
| b69ab31 | | | 1045 | landInfo: {error: err as Error}, |
| b69ab31 | | | 1046 | }); |
| b69ab31 | | | 1047 | }); |
| b69ab31 | | | 1048 | |
| b69ab31 | | | 1049 | break; |
| b69ab31 | | | 1050 | } |
| b69ab31 | | | 1051 | case 'confirmLand': { |
| b69ab31 | | | 1052 | if (data.landConfirmationInfo == null) { |
| b69ab31 | | | 1053 | break; |
| b69ab31 | | | 1054 | } |
| b69ab31 | | | 1055 | repo.codeReviewProvider |
| b69ab31 | | | 1056 | ?.confirmLand?.(data.landConfirmationInfo) |
| b69ab31 | | | 1057 | ?.then((result: Result<undefined>) => { |
| b69ab31 | | | 1058 | this.postMessage({ |
| b69ab31 | | | 1059 | type: 'confirmedLand', |
| b69ab31 | | | 1060 | result, |
| b69ab31 | | | 1061 | }); |
| b69ab31 | | | 1062 | }); |
| b69ab31 | | | 1063 | break; |
| b69ab31 | | | 1064 | } |
| b69ab31 | | | 1065 | case 'fetchAvatars': { |
| b69ab31 | | | 1066 | repo.codeReviewProvider?.fetchAvatars?.(data.authors)?.then(avatars => { |
| b69ab31 | | | 1067 | this.postMessage({ |
| b69ab31 | | | 1068 | type: 'fetchedAvatars', |
| b69ab31 | | | 1069 | avatars, |
| b69ab31 | | | 1070 | authors: data.authors, |
| b69ab31 | | | 1071 | }); |
| b69ab31 | | | 1072 | }); |
| b69ab31 | | | 1073 | break; |
| b69ab31 | | | 1074 | } |
| b69ab31 | | | 1075 | case 'fetchDiffComments': { |
| b69ab31 | | | 1076 | repo.codeReviewProvider |
| b69ab31 | | | 1077 | ?.fetchComments?.(data.diffId) |
| b69ab31 | | | 1078 | ?.then(comments => { |
| b69ab31 | | | 1079 | this.postMessage({ |
| b69ab31 | | | 1080 | type: 'fetchedDiffComments', |
| b69ab31 | | | 1081 | diffId: data.diffId, |
| b69ab31 | | | 1082 | comments: {value: comments}, |
| b69ab31 | | | 1083 | }); |
| b69ab31 | | | 1084 | }) |
| b69ab31 | | | 1085 | .catch(error => { |
| b69ab31 | | | 1086 | this.postMessage({ |
| b69ab31 | | | 1087 | type: 'fetchedDiffComments', |
| b69ab31 | | | 1088 | diffId: data.diffId, |
| b69ab31 | | | 1089 | comments: {error}, |
| b69ab31 | | | 1090 | }); |
| b69ab31 | | | 1091 | }); |
| b69ab31 | | | 1092 | break; |
| b69ab31 | | | 1093 | } |
| b69ab31 | | | 1094 | case 'renderMarkup': { |
| b69ab31 | | | 1095 | repo.codeReviewProvider |
| b69ab31 | | | 1096 | ?.renderMarkup?.(data.markup) |
| b69ab31 | | | 1097 | ?.then(html => { |
| b69ab31 | | | 1098 | this.postMessage({ |
| b69ab31 | | | 1099 | type: 'renderedMarkup', |
| b69ab31 | | | 1100 | id: data.id, |
| b69ab31 | | | 1101 | html, |
| b69ab31 | | | 1102 | }); |
| b69ab31 | | | 1103 | }) |
| b69ab31 | | | 1104 | ?.catch(err => { |
| b69ab31 | | | 1105 | this.logger.error('Error rendering markup:', err); |
| b69ab31 | | | 1106 | }); |
| b69ab31 | | | 1107 | break; |
| b69ab31 | | | 1108 | } |
| b69ab31 | | | 1109 | case 'getSuggestedReviewers': { |
| b69ab31 | | | 1110 | repo.codeReviewProvider?.getSuggestedReviewers?.(data.context).then(reviewers => { |
| b69ab31 | | | 1111 | this.postMessage({ |
| b69ab31 | | | 1112 | type: 'gotSuggestedReviewers', |
| b69ab31 | | | 1113 | reviewers, |
| b69ab31 | | | 1114 | key: data.key, |
| b69ab31 | | | 1115 | }); |
| b69ab31 | | | 1116 | }); |
| b69ab31 | | | 1117 | break; |
| b69ab31 | | | 1118 | } |
| b69ab31 | | | 1119 | case 'updateRemoteDiffMessage': { |
| b69ab31 | | | 1120 | repo.codeReviewProvider |
| b69ab31 | | | 1121 | ?.updateDiffMessage?.(data.diffId, data.title, data.description) |
| b69ab31 | | | 1122 | ?.catch(err => err) |
| b69ab31 | | | 1123 | ?.then((error: string | undefined) => { |
| b69ab31 | | | 1124 | if (error != null) { |
| b69ab31 | | | 1125 | this.logger.error('Error updating remote diff message:', error); |
| b69ab31 | | | 1126 | } |
| b69ab31 | | | 1127 | this.postMessage({type: 'updatedRemoteDiffMessage', diffId: data.diffId, error}); |
| b69ab31 | | | 1128 | }); |
| b69ab31 | | | 1129 | break; |
| b69ab31 | | | 1130 | } |
| b69ab31 | | | 1131 | case 'loadMoreCommits': { |
| b69ab31 | | | 1132 | const rangeInDays = repo.nextVisibleCommitRangeInDays(); |
| b69ab31 | | | 1133 | this.postMessage({type: 'commitsShownRange', rangeInDays}); |
| b69ab31 | | | 1134 | this.postMessage({type: 'beganLoadingMoreCommits'}); |
| b69ab31 | | | 1135 | repo.fetchSmartlogCommits(); |
| b69ab31 | | | 1136 | this.tracker.track('LoadMoreCommits', {extras: {daysToFetch: rangeInDays ?? 'Infinity'}}); |
| b69ab31 | | | 1137 | return; |
| b69ab31 | | | 1138 | } |
| b69ab31 | | | 1139 | case 'exportStack': { |
| b69ab31 | | | 1140 | const {revs, assumeTracked} = data; |
| b69ab31 | | | 1141 | const assumeTrackedArgs = (assumeTracked ?? []).map(path => `--assume-tracked=${path}`); |
| b69ab31 | | | 1142 | const exec = repo.runCommand( |
| b69ab31 | | | 1143 | ['debugexportstack', '-r', revs, ...assumeTrackedArgs], |
| b69ab31 | | | 1144 | 'ExportStackCommand', |
| b69ab31 | | | 1145 | ctx, |
| b69ab31 | | | 1146 | undefined, |
| b69ab31 | | | 1147 | /* don't timeout */ 0, |
| b69ab31 | | | 1148 | ); |
| b69ab31 | | | 1149 | const reply = (stack?: ExportStack, error?: string) => { |
| b69ab31 | | | 1150 | this.postMessage({ |
| b69ab31 | | | 1151 | type: 'exportedStack', |
| b69ab31 | | | 1152 | assumeTracked: assumeTracked ?? [], |
| b69ab31 | | | 1153 | revs, |
| b69ab31 | | | 1154 | stack: stack ?? [], |
| b69ab31 | | | 1155 | error, |
| b69ab31 | | | 1156 | }); |
| b69ab31 | | | 1157 | }; |
| b69ab31 | | | 1158 | parseExecJson(exec, reply); |
| b69ab31 | | | 1159 | break; |
| b69ab31 | | | 1160 | } |
| b69ab31 | | | 1161 | case 'importStack': { |
| b69ab31 | | | 1162 | const stdinStream = Readable.from(JSON.stringify(data.stack)); |
| b69ab31 | | | 1163 | const exec = repo.runCommand( |
| b69ab31 | | | 1164 | ['debugimportstack'], |
| b69ab31 | | | 1165 | 'ImportStackCommand', |
| b69ab31 | | | 1166 | ctx, |
| b69ab31 | | | 1167 | {stdin: stdinStream}, |
| b69ab31 | | | 1168 | /* don't timeout */ 0, |
| b69ab31 | | | 1169 | ); |
| b69ab31 | | | 1170 | const reply = (imported?: ImportedStack, error?: string) => { |
| b69ab31 | | | 1171 | this.postMessage({type: 'importedStack', imported: imported ?? [], error}); |
| b69ab31 | | | 1172 | }; |
| b69ab31 | | | 1173 | parseExecJson(exec, reply); |
| b69ab31 | | | 1174 | break; |
| b69ab31 | | | 1175 | } |
| b69ab31 | | | 1176 | case 'fetchQeFlag': { |
| b69ab31 | | | 1177 | Internal.fetchQeFlag?.(repo.initialConnectionContext, data.name).then((passes: boolean) => { |
| b69ab31 | | | 1178 | this.logger.info(`qe flag ${data.name} ${passes ? 'PASSES' : 'FAILS'}`); |
| b69ab31 | | | 1179 | this.postMessage({type: 'fetchedQeFlag', name: data.name, passes}); |
| b69ab31 | | | 1180 | }); |
| b69ab31 | | | 1181 | break; |
| b69ab31 | | | 1182 | } |
| b69ab31 | | | 1183 | case 'fetchFeatureFlag': { |
| b69ab31 | | | 1184 | Internal.fetchFeatureFlag?.(repo.initialConnectionContext, data.name).then( |
| b69ab31 | | | 1185 | (passes: boolean) => { |
| b69ab31 | | | 1186 | this.logger.info(`feature flag ${data.name} ${passes ? 'PASSES' : 'FAILS'}`); |
| b69ab31 | | | 1187 | this.postMessage({type: 'fetchedFeatureFlag', name: data.name, passes}); |
| b69ab31 | | | 1188 | }, |
| b69ab31 | | | 1189 | ); |
| b69ab31 | | | 1190 | break; |
| b69ab31 | | | 1191 | } |
| b69ab31 | | | 1192 | case 'bulkFetchFeatureFlags': { |
| b69ab31 | | | 1193 | Internal.bulkFetchFeatureFlags?.(repo.initialConnectionContext, data.names).then( |
| b69ab31 | | | 1194 | (result: Record<string, boolean>) => { |
| b69ab31 | | | 1195 | this.logger.info(`feature flags ${JSON.stringify(result, null, 2)}`); |
| b69ab31 | | | 1196 | this.postMessage({type: 'bulkFetchedFeatureFlags', id: data.id, result}); |
| b69ab31 | | | 1197 | }, |
| b69ab31 | | | 1198 | ); |
| b69ab31 | | | 1199 | break; |
| b69ab31 | | | 1200 | } |
| b69ab31 | | | 1201 | case 'fetchInternalUserInfo': { |
| b69ab31 | | | 1202 | Internal.fetchUserInfo?.(repo.initialConnectionContext).then((info: Serializable) => { |
| b69ab31 | | | 1203 | this.logger.info('user info:', info); |
| b69ab31 | | | 1204 | this.postMessage({type: 'fetchedInternalUserInfo', info}); |
| b69ab31 | | | 1205 | }); |
| b69ab31 | | | 1206 | break; |
| b69ab31 | | | 1207 | } |
| b69ab31 | | | 1208 | case 'fetchAndSetStables': { |
| b69ab31 | | | 1209 | Internal.fetchStableLocations?.(ctx, data.additionalStables).then( |
| b69ab31 | | | 1210 | (stables: StableLocationData | undefined) => { |
| b69ab31 | | | 1211 | this.logger.info('fetched stable locations', stables); |
| b69ab31 | | | 1212 | if (stables == null) { |
| b69ab31 | | | 1213 | return; |
| b69ab31 | | | 1214 | } |
| b69ab31 | | | 1215 | this.postMessage({type: 'fetchedStables', stables}); |
| b69ab31 | | | 1216 | repo.stableLocations = [ |
| b69ab31 | | | 1217 | ...stables.stables, |
| b69ab31 | | | 1218 | ...stables.special, |
| b69ab31 | | | 1219 | ...Object.values(stables.manual), |
| b69ab31 | | | 1220 | ] |
| b69ab31 | | | 1221 | .map(stable => stable?.value) |
| b69ab31 | | | 1222 | .filter(notEmpty); |
| b69ab31 | | | 1223 | repo.fetchSmartlogCommits(); |
| b69ab31 | | | 1224 | }, |
| b69ab31 | | | 1225 | ); |
| b69ab31 | | | 1226 | break; |
| b69ab31 | | | 1227 | } |
| b69ab31 | | | 1228 | case 'fetchStableLocationAutocompleteOptions': { |
| b69ab31 | | | 1229 | Internal.fetchStableLocationAutocompleteOptions?.(ctx).then( |
| b69ab31 | | | 1230 | (result: Result<Array<TypeaheadResult>>) => { |
| b69ab31 | | | 1231 | this.postMessage({type: 'fetchedStableLocationAutocompleteOptions', result}); |
| b69ab31 | | | 1232 | }, |
| b69ab31 | | | 1233 | ); |
| b69ab31 | | | 1234 | break; |
| b69ab31 | | | 1235 | } |
| b69ab31 | | | 1236 | case 'fetchDevEnvType': { |
| b69ab31 | | | 1237 | if (Internal.getDevEnvType == null) { |
| b69ab31 | | | 1238 | break; |
| b69ab31 | | | 1239 | } |
| b69ab31 | | | 1240 | |
| b69ab31 | | | 1241 | Internal.getDevEnvType() |
| b69ab31 | | | 1242 | .catch((error: Error) => { |
| b69ab31 | | | 1243 | this.logger.error('Error getting dev env type:', error); |
| b69ab31 | | | 1244 | return 'error'; |
| b69ab31 | | | 1245 | }) |
| b69ab31 | | | 1246 | .then((result: string) => { |
| b69ab31 | | | 1247 | this.postMessage({ |
| b69ab31 | | | 1248 | type: 'fetchedDevEnvType', |
| b69ab31 | | | 1249 | envType: result, |
| b69ab31 | | | 1250 | id: data.id, |
| b69ab31 | | | 1251 | }); |
| b69ab31 | | | 1252 | }); |
| b69ab31 | | | 1253 | break; |
| b69ab31 | | | 1254 | } |
| b69ab31 | | | 1255 | case 'splitCommitWithAI': { |
| b69ab31 | | | 1256 | Internal.splitCommitWithAI?.(ctx, data.diffCommit, data.args).then( |
| b69ab31 | | | 1257 | (result: Result<ReadonlyArray<PartiallySelectedDiffCommit>>) => { |
| b69ab31 | | | 1258 | this.postMessage({ |
| b69ab31 | | | 1259 | type: 'splitCommitWithAI', |
| b69ab31 | | | 1260 | id: data.id, |
| b69ab31 | | | 1261 | result, |
| b69ab31 | | | 1262 | }); |
| b69ab31 | | | 1263 | }, |
| b69ab31 | | | 1264 | ); |
| b69ab31 | | | 1265 | break; |
| b69ab31 | | | 1266 | } |
| b69ab31 | | | 1267 | case 'fetchActiveAlerts': { |
| b69ab31 | | | 1268 | repo |
| b69ab31 | | | 1269 | .getActiveAlerts(ctx) |
| b69ab31 | | | 1270 | .then(alerts => { |
| b69ab31 | | | 1271 | if (alerts.length === 0) { |
| b69ab31 | | | 1272 | return; |
| b69ab31 | | | 1273 | } |
| b69ab31 | | | 1274 | this.postMessage({ |
| b69ab31 | | | 1275 | type: 'fetchedActiveAlerts', |
| b69ab31 | | | 1276 | alerts, |
| b69ab31 | | | 1277 | }); |
| b69ab31 | | | 1278 | }) |
| b69ab31 | | | 1279 | .catch(err => { |
| b69ab31 | | | 1280 | this.logger.error('Failed to fetch active alerts:', err); |
| b69ab31 | | | 1281 | }); |
| b69ab31 | | | 1282 | break; |
| b69ab31 | | | 1283 | } |
| b69ab31 | | | 1284 | case 'gotUiState': { |
| b69ab31 | | | 1285 | break; |
| b69ab31 | | | 1286 | } |
| b69ab31 | | | 1287 | case 'getConfiguredMergeTool': { |
| b69ab31 | | | 1288 | repo.getMergeTool(ctx).then((tool: string | null) => { |
| b69ab31 | | | 1289 | this.postMessage({ |
| b69ab31 | | | 1290 | type: 'gotConfiguredMergeTool', |
| b69ab31 | | | 1291 | tool: tool ?? undefined, |
| b69ab31 | | | 1292 | }); |
| b69ab31 | | | 1293 | }); |
| b69ab31 | | | 1294 | break; |
| b69ab31 | | | 1295 | } |
| b69ab31 | | | 1296 | case 'fetchGkDetails': { |
| b69ab31 | | | 1297 | Internal.fetchGkDetails?.(ctx, data.name) |
| b69ab31 | | | 1298 | .then((gk: InternalTypes['InternalGatekeeper']) => { |
| b69ab31 | | | 1299 | this.postMessage({type: 'fetchedGkDetails', id: data.id, result: {value: gk}}); |
| b69ab31 | | | 1300 | }) |
| b69ab31 | | | 1301 | .catch((err: unknown) => { |
| b69ab31 | | | 1302 | logger?.error('Could not fetch GK details', err); |
| b69ab31 | | | 1303 | this.postMessage({ |
| b69ab31 | | | 1304 | type: 'fetchedGkDetails', |
| b69ab31 | | | 1305 | id: data.id, |
| b69ab31 | | | 1306 | result: {error: err as Error}, |
| b69ab31 | | | 1307 | }); |
| b69ab31 | | | 1308 | }); |
| b69ab31 | | | 1309 | break; |
| b69ab31 | | | 1310 | } |
| b69ab31 | | | 1311 | case 'fetchJkDetails': { |
| b69ab31 | | | 1312 | Internal.fetchJustKnobsByNames?.(ctx, data.names) |
| b69ab31 | | | 1313 | .then((jk: InternalTypes['InternalJustknob']) => { |
| b69ab31 | | | 1314 | this.postMessage({type: 'fetchedJkDetails', id: data.id, result: {value: jk}}); |
| b69ab31 | | | 1315 | }) |
| b69ab31 | | | 1316 | .catch((err: unknown) => { |
| b69ab31 | | | 1317 | logger?.error('Could not fetch JK details', err); |
| b69ab31 | | | 1318 | this.postMessage({ |
| b69ab31 | | | 1319 | type: 'fetchedJkDetails', |
| b69ab31 | | | 1320 | id: data.id, |
| b69ab31 | | | 1321 | result: {error: err as Error}, |
| b69ab31 | | | 1322 | }); |
| b69ab31 | | | 1323 | }); |
| b69ab31 | | | 1324 | break; |
| b69ab31 | | | 1325 | } |
| b69ab31 | | | 1326 | case 'fetchKnobsetDetails': { |
| b69ab31 | | | 1327 | Internal.fetchKnobset?.(ctx, data.configPath) |
| b69ab31 | | | 1328 | .then((knobset: InternalTypes['InternalKnobset']) => { |
| b69ab31 | | | 1329 | this.postMessage({ |
| b69ab31 | | | 1330 | type: 'fetchedKnobsetDetails', |
| b69ab31 | | | 1331 | id: data.id, |
| b69ab31 | | | 1332 | result: {value: knobset}, |
| b69ab31 | | | 1333 | }); |
| b69ab31 | | | 1334 | }) |
| b69ab31 | | | 1335 | .catch((err: unknown) => { |
| b69ab31 | | | 1336 | logger?.error('Could not fetch knobset details', err); |
| b69ab31 | | | 1337 | this.postMessage({ |
| b69ab31 | | | 1338 | type: 'fetchedKnobsetDetails', |
| b69ab31 | | | 1339 | id: data.id, |
| b69ab31 | | | 1340 | result: {error: err as Error}, |
| b69ab31 | | | 1341 | }); |
| b69ab31 | | | 1342 | }); |
| b69ab31 | | | 1343 | break; |
| b69ab31 | | | 1344 | } |
| b69ab31 | | | 1345 | case 'fetchQeDetails': { |
| b69ab31 | | | 1346 | Internal.fetchQeMetadata?.(ctx, data.name) |
| b69ab31 | | | 1347 | .then((qe: InternalTypes['InternalQuickExperiment']) => { |
| b69ab31 | | | 1348 | this.postMessage({ |
| b69ab31 | | | 1349 | type: 'fetchedQeDetails', |
| b69ab31 | | | 1350 | id: data.id, |
| b69ab31 | | | 1351 | result: {value: qe}, |
| b69ab31 | | | 1352 | }); |
| b69ab31 | | | 1353 | }) |
| b69ab31 | | | 1354 | .catch((err: unknown) => { |
| b69ab31 | | | 1355 | logger?.error('Could not fetch QE details', err); |
| b69ab31 | | | 1356 | this.postMessage({ |
| b69ab31 | | | 1357 | type: 'fetchedQeDetails', |
| b69ab31 | | | 1358 | id: data.id, |
| b69ab31 | | | 1359 | result: {error: err as Error}, |
| b69ab31 | | | 1360 | }); |
| b69ab31 | | | 1361 | }); |
| b69ab31 | | | 1362 | break; |
| b69ab31 | | | 1363 | } |
| b69ab31 | | | 1364 | case 'fetchABPropDetails': { |
| b69ab31 | | | 1365 | Internal.fetchABPropMetadata?.(ctx, data.name) |
| b69ab31 | | | 1366 | .then((abprop: InternalTypes['InternalMetaConfig']) => { |
| b69ab31 | | | 1367 | this.postMessage({ |
| b69ab31 | | | 1368 | type: 'fetchedABPropDetails', |
| b69ab31 | | | 1369 | id: data.id, |
| b69ab31 | | | 1370 | result: {value: abprop}, |
| b69ab31 | | | 1371 | }); |
| b69ab31 | | | 1372 | }) |
| b69ab31 | | | 1373 | .catch((err: unknown) => { |
| b69ab31 | | | 1374 | logger?.error('Could not fetch ABProp details', err); |
| b69ab31 | | | 1375 | this.postMessage({ |
| b69ab31 | | | 1376 | type: 'fetchedABPropDetails', |
| b69ab31 | | | 1377 | id: data.id, |
| b69ab31 | | | 1378 | result: {error: err as Error}, |
| b69ab31 | | | 1379 | }); |
| b69ab31 | | | 1380 | }); |
| b69ab31 | | | 1381 | break; |
| b69ab31 | | | 1382 | } |
| b69ab31 | | | 1383 | case 'getRepoUrlAtHash': { |
| b69ab31 | | | 1384 | const args = ['url', '--rev', data.revset]; |
| b69ab31 | | | 1385 | // validate that the path is a valid file in repo |
| b69ab31 | | | 1386 | if (data.path != null && absolutePathForFileInRepo(data.path, repo) != null) { |
| b69ab31 | | | 1387 | args.push(`path:${data.path}`); |
| b69ab31 | | | 1388 | } |
| b69ab31 | | | 1389 | repo |
| b69ab31 | | | 1390 | .runCommand(args, 'RepoUrlCommand', ctx) |
| b69ab31 | | | 1391 | .then(result => { |
| b69ab31 | | | 1392 | this.postMessage({ |
| b69ab31 | | | 1393 | type: 'gotRepoUrlAtHash', |
| b69ab31 | | | 1394 | url: {value: result.stdout}, |
| b69ab31 | | | 1395 | }); |
| b69ab31 | | | 1396 | }) |
| b69ab31 | | | 1397 | .catch((err: EjecaError) => { |
| b69ab31 | | | 1398 | this.logger.error('Failed to get repo url at hash:', err); |
| b69ab31 | | | 1399 | this.postMessage({ |
| b69ab31 | | | 1400 | type: 'gotRepoUrlAtHash', |
| b69ab31 | | | 1401 | url: {error: err}, |
| b69ab31 | | | 1402 | }); |
| b69ab31 | | | 1403 | }); |
| b69ab31 | | | 1404 | break; |
| b69ab31 | | | 1405 | } |
| b69ab31 | | | 1406 | case 'fetchTaskDetails': { |
| b69ab31 | | | 1407 | Internal.getTask?.(ctx, data.taskNumber).then( |
| b69ab31 | | | 1408 | (task: InternalTypes['InternalTaskDetails']) => { |
| b69ab31 | | | 1409 | this.postMessage({type: 'fetchedTaskDetails', id: data.id, result: {value: task}}); |
| b69ab31 | | | 1410 | }, |
| b69ab31 | | | 1411 | ); |
| b69ab31 | | | 1412 | break; |
| b69ab31 | | | 1413 | } |
| b69ab31 | | | 1414 | case 'runDevmateCommand': { |
| b69ab31 | | | 1415 | Internal.runDevmateCommand?.(data.args, data.cwd) |
| b69ab31 | | | 1416 | .then((result: EjecaReturn) => { |
| b69ab31 | | | 1417 | this.postMessage({ |
| b69ab31 | | | 1418 | type: 'devmateCommandResult', |
| b69ab31 | | | 1419 | result: {type: 'value', stdout: result.stdout, requestId: data.requestId}, |
| b69ab31 | | | 1420 | }); |
| b69ab31 | | | 1421 | }) |
| b69ab31 | | | 1422 | .catch((error: EjecaError) => { |
| b69ab31 | | | 1423 | this.postMessage({ |
| b69ab31 | | | 1424 | type: 'devmateCommandResult', |
| b69ab31 | | | 1425 | result: {type: 'error', stderr: error.stderr, requestId: data.requestId}, |
| b69ab31 | | | 1426 | }); |
| b69ab31 | | | 1427 | }); |
| b69ab31 | | | 1428 | break; |
| b69ab31 | | | 1429 | } |
| b69ab31 | | | 1430 | case 'fetchSubscribedFullRepoBranches': { |
| b69ab31 | | | 1431 | Internal.fetchSubscribedFullRepoBranches?.(ctx, repo) |
| b69ab31 | | | 1432 | .then((branches: Array<InternalTypes['FullRepoBranch']>) => { |
| b69ab31 | | | 1433 | this.postMessage({ |
| b69ab31 | | | 1434 | type: 'fetchedSubscribedFullRepoBranches', |
| b69ab31 | | | 1435 | result: {value: branches}, |
| b69ab31 | | | 1436 | }); |
| b69ab31 | | | 1437 | }) |
| b69ab31 | | | 1438 | .catch((error: EjecaError) => { |
| b69ab31 | | | 1439 | this.postMessage({ |
| b69ab31 | | | 1440 | type: 'fetchedSubscribedFullRepoBranches', |
| b69ab31 | | | 1441 | result: {error}, |
| b69ab31 | | | 1442 | }); |
| b69ab31 | | | 1443 | }); |
| b69ab31 | | | 1444 | break; |
| b69ab31 | | | 1445 | } |
| b69ab31 | | | 1446 | case 'fetchFullRepoBranchAllChangedFiles': { |
| b69ab31 | | | 1447 | Internal.getFullRepoBranchAllChangedFiles?.(ctx, data.fullRepoBranch) |
| b69ab31 | | | 1448 | .then((paths: Array<ChangedFile>) => { |
| b69ab31 | | | 1449 | this.postMessage({ |
| b69ab31 | | | 1450 | type: 'fetchedFullRepoBranchAllChangedFiles', |
| b69ab31 | | | 1451 | id: data.id, |
| b69ab31 | | | 1452 | result: {value: paths}, |
| b69ab31 | | | 1453 | }); |
| b69ab31 | | | 1454 | }) |
| b69ab31 | | | 1455 | .catch((error: EjecaError) => { |
| b69ab31 | | | 1456 | this.postMessage({ |
| b69ab31 | | | 1457 | type: 'fetchedFullRepoBranchAllChangedFiles', |
| b69ab31 | | | 1458 | id: data.id, |
| b69ab31 | | | 1459 | result: {error}, |
| b69ab31 | | | 1460 | }); |
| b69ab31 | | | 1461 | }); |
| b69ab31 | | | 1462 | break; |
| b69ab31 | | | 1463 | } |
| b69ab31 | | | 1464 | case 'fetchFullRepoBranchMergeSubtreePaths': { |
| b69ab31 | | | 1465 | Internal.getFullRepoBranchMergeSubtreePaths?.(ctx, data.fullRepoBranch, data.paths) |
| b69ab31 | | | 1466 | .then((paths: Array<string>) => { |
| b69ab31 | | | 1467 | this.postMessage({ |
| b69ab31 | | | 1468 | type: 'fetchedFullRepoBranchMergeSubtreePaths', |
| b69ab31 | | | 1469 | id: data.id, |
| b69ab31 | | | 1470 | result: {value: paths}, |
| b69ab31 | | | 1471 | }); |
| b69ab31 | | | 1472 | }) |
| b69ab31 | | | 1473 | .catch((error: EjecaError) => { |
| b69ab31 | | | 1474 | this.postMessage({ |
| b69ab31 | | | 1475 | type: 'fetchedFullRepoBranchMergeSubtreePaths', |
| b69ab31 | | | 1476 | id: data.id, |
| b69ab31 | | | 1477 | result: {error}, |
| b69ab31 | | | 1478 | }); |
| b69ab31 | | | 1479 | }); |
| b69ab31 | | | 1480 | break; |
| b69ab31 | | | 1481 | } |
| b69ab31 | | | 1482 | case 'subscribeToFullRepoBranch': { |
| b69ab31 | | | 1483 | Internal.subscribeToFullRepoBranch?.(ctx, repo, data.fullRepoBranch); |
| b69ab31 | | | 1484 | break; |
| b69ab31 | | | 1485 | } |
| b69ab31 | | | 1486 | case 'unsubscribeToFullRepoBranch': { |
| b69ab31 | | | 1487 | Internal.unsubscribeToFullRepoBranch?.(ctx, repo, data.fullRepoBranch); |
| b69ab31 | | | 1488 | break; |
| b69ab31 | | | 1489 | } |
| b69ab31 | | | 1490 | default: { |
| b69ab31 | | | 1491 | if ( |
| b69ab31 | | | 1492 | repo.codeReviewProvider?.handleClientToServerMessage?.(data, message => |
| b69ab31 | | | 1493 | this.postMessage(message), |
| b69ab31 | | | 1494 | ) === true |
| b69ab31 | | | 1495 | ) { |
| b69ab31 | | | 1496 | break; |
| b69ab31 | | | 1497 | } |
| b69ab31 | | | 1498 | this.platform.handleMessageFromClient( |
| b69ab31 | | | 1499 | repo, |
| b69ab31 | | | 1500 | ctx, |
| b69ab31 | | | 1501 | data as Exclude<typeof data, CodeReviewProviderSpecificClientToServerMessages>, |
| b69ab31 | | | 1502 | message => this.postMessage(message), |
| b69ab31 | | | 1503 | (dispose: () => unknown) => { |
| b69ab31 | | | 1504 | this.repoDisposables.push({dispose}); |
| b69ab31 | | | 1505 | }, |
| b69ab31 | | | 1506 | ); |
| b69ab31 | | | 1507 | break; |
| b69ab31 | | | 1508 | } |
| b69ab31 | | | 1509 | } |
| b69ab31 | | | 1510 | |
| b69ab31 | | | 1511 | this.notifyListeners(data); |
| b69ab31 | | | 1512 | } |
| b69ab31 | | | 1513 | |
| b69ab31 | | | 1514 | private notifyListeners(data: IncomingMessage): void { |
| b69ab31 | | | 1515 | const listeners = this.listenersByType.get(data.type); |
| b69ab31 | | | 1516 | if (listeners) { |
| b69ab31 | | | 1517 | listeners.forEach(handle => handle(data)); |
| b69ab31 | | | 1518 | } |
| b69ab31 | | | 1519 | } |
| b69ab31 | | | 1520 | |
| b69ab31 | | | 1521 | private async handleFetchCommitMessageTemplate(repo: Repository, ctx: RepositoryContext) { |
| b69ab31 | | | 1522 | const {logger} = ctx; |
| b69ab31 | | | 1523 | try { |
| b69ab31 | | | 1524 | const [result, customTemplate] = await Promise.all([ |
| b69ab31 | | | 1525 | repo.runCommand(['debugcommitmessage', 'isl'], 'FetchCommitTemplateCommand', ctx), |
| b69ab31 | | | 1526 | Internal.getCustomDefaultCommitTemplate?.(repo.initialConnectionContext), |
| b69ab31 | | | 1527 | ]); |
| b69ab31 | | | 1528 | |
| b69ab31 | | | 1529 | let template = result.stdout |
| b69ab31 | | | 1530 | .replace(repo.IGNORE_COMMIT_MESSAGE_LINES_REGEX, '') |
| b69ab31 | | | 1531 | .replace(/^<Replace this line with a title. Use 1 line only, 67 chars or less>/, ''); |
| b69ab31 | | | 1532 | |
| b69ab31 | | | 1533 | if (customTemplate && customTemplate?.trim() !== '') { |
| b69ab31 | | | 1534 | template = customTemplate as string; |
| b69ab31 | | | 1535 | |
| b69ab31 | | | 1536 | this.tracker.track('UseCustomCommitMessageTemplate'); |
| b69ab31 | | | 1537 | } |
| b69ab31 | | | 1538 | |
| b69ab31 | | | 1539 | this.postMessage({ |
| b69ab31 | | | 1540 | type: 'fetchedCommitMessageTemplate', |
| b69ab31 | | | 1541 | template, |
| b69ab31 | | | 1542 | }); |
| b69ab31 | | | 1543 | } catch (err) { |
| b69ab31 | | | 1544 | logger?.error('Could not fetch commit message template', err); |
| b69ab31 | | | 1545 | } |
| b69ab31 | | | 1546 | } |
| b69ab31 | | | 1547 | } |