| 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 App from 'isl/src/App'; |
| 9 | import {getLatestOperationInfo, onOperationExited} from 'isl/src/operationsState'; |
| 10 | import {registerDisposable} from 'isl/src/utils'; |
| 11 | import ReactDOM from 'react-dom/client'; |
| 12 | import serverAPI from '../../isl/src/ClientToServerAPI'; |
| 13 | import {Internal} from './Internal'; |
| 14 | |
| 15 | // start state side effect fetches |
| 16 | import './state'; |
| 17 | |
| 18 | import './vscode-styles.css'; |
| 19 | |
| 20 | const PHABRICATOR_DIFF_ID_REGEX = /D([1-9][0-9]{5,})/im; |
| 21 | |
| 22 | registerDisposable( |
| 23 | serverAPI, |
| 24 | onOperationExited((progress, operation) => { |
| 25 | if (progress.exitCode !== 0) { |
| 26 | return; // don't show survey if submit failed |
| 27 | } |
| 28 | const isJfSubmitOperation = Internal.isJfSubmitOperation; |
| 29 | if (!isJfSubmitOperation || !isJfSubmitOperation(operation)) { |
| 30 | return; // only show survey for submits |
| 31 | } |
| 32 | |
| 33 | // get latest operation |
| 34 | const info = getLatestOperationInfo(operation); |
| 35 | |
| 36 | if (info == null || info.commandOutput == null) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | // phabricator url is in the last line of the commandOutput |
| 41 | const message = info.commandOutput[info.commandOutput.length - 1]; |
| 42 | |
| 43 | const onCommitFormSubmit = Internal.onCommitFormSubmit; |
| 44 | |
| 45 | const match = PHABRICATOR_DIFF_ID_REGEX.exec(message); |
| 46 | if (onCommitFormSubmit !== undefined) { |
| 47 | if (match && match[0]) { |
| 48 | onCommitFormSubmit(match[0]); |
| 49 | } else { |
| 50 | onCommitFormSubmit(); |
| 51 | } |
| 52 | } |
| 53 | }), |
| 54 | ); |
| 55 | |
| 56 | window.addEventListener('load', () => { |
| 57 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 58 | const root = ReactDOM.createRoot(document.getElementById('root')!); |
| 59 | root.render(<App />); |
| 60 | }); |
| 61 | |