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