| 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 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import * as React from 'react'; |
| 11 | import Icon from '../Icon'; |
| 12 | import {searchGitHubIssuesURL} from './githubAPI'; |
| 13 | import styles from './shared.css'; |
| 14 | |
| 15 | const LABELS = [ |
| 16 | 'Component: Developer Tools', |
| 17 | 'Type: Bug', |
| 18 | 'Status: Unconfirmed', |
| 19 | ]; |
| 20 | |
| 21 | // This must match the filename in ".github/ISSUE_TEMPLATE/" |
| 22 | const TEMPLATE = 'devtools_bug_report.yml'; |
| 23 | |
| 24 | type Props = { |
| 25 | callStack: string | null, |
| 26 | componentStack: string | null, |
| 27 | errorMessage: string | null, |
| 28 | }; |
| 29 | |
| 30 | export default function ReportNewIssue({ |
| 31 | callStack, |
| 32 | componentStack, |
| 33 | errorMessage, |
| 34 | }: Props): React.Node { |
| 35 | let bugURL = process.env.GITHUB_URL; |
| 36 | if (!bugURL) { |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | const gitHubAPISearch = |
| 41 | errorMessage !== null ? searchGitHubIssuesURL(errorMessage) : '(none)'; |
| 42 | |
| 43 | const title = `[DevTools Bug] ${errorMessage || ''}`; |
| 44 | |
| 45 | const parameters = [ |
| 46 | `template=${TEMPLATE}`, |
| 47 | `labels=${encodeURIComponent(LABELS.join(','))}`, |
| 48 | `title=${encodeURIComponent(title)}`, |
| 49 | `automated_package=${process.env.DEVTOOLS_PACKAGE || ''}`, |
| 50 | `automated_version=${process.env.DEVTOOLS_VERSION || ''}`, |
| 51 | `automated_error_message=${encodeURIComponent(errorMessage || '')}`, |
| 52 | `automated_call_stack=${encodeURIComponent(callStack || '')}`, |
| 53 | `automated_component_stack=${encodeURIComponent(componentStack || '')}`, |
| 54 | `automated_github_query_string=${gitHubAPISearch}`, |
| 55 | ]; |
| 56 | |
| 57 | bugURL += `/issues/new?${parameters.join('&')}`; |
| 58 | |
| 59 | return ( |
| 60 | <div className={styles.GitHubLinkRow}> |
| 61 | <Icon className={styles.ReportIcon} type="bug" /> |
| 62 | <a |
| 63 | className={styles.ReportLink} |
| 64 | href={bugURL} |
| 65 | rel="noopener noreferrer" |
| 66 | target="_blank"> |
| 67 | Report this issue |
| 68 | </a> |
| 69 | <div className={styles.ReproSteps}> |
| 70 | (Please include steps on how to reproduce it and the components used.) |
| 71 | </div> |
| 72 | </div> |
| 73 | ); |
| 74 | } |