From 78f1ec9b37b6182d166f3d70a20b4ffdebf5b709 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 3 May 2021 23:55:09 -0400 Subject: [PATCH] Add GitHub API query to bug report template This may help debug why sometimes the GitHub API search seems to not find a match when it should. --- .../views/ErrorBoundary/ReportNewIssue.js | 11 ++++++++-- .../devtools/views/ErrorBoundary/githubAPI.js | 20 +++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/ReportNewIssue.js b/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/ReportNewIssue.js index 8dd3be4ad3851..3546c94387111 100644 --- a/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/ReportNewIssue.js +++ b/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/ReportNewIssue.js @@ -9,6 +9,7 @@ import * as React from 'react'; import Icon from '../Icon'; +import {searchGitHubIssuesURL} from './githubAPI'; import styles from './shared.css'; function encodeURIWrapper(string: string): string { @@ -31,6 +32,9 @@ export default function ReportNewIssue({ return null; } + const gitHubAPISearch = + errorMessage !== null ? searchGitHubIssuesURL(errorMessage) : '(none)'; + const title = `Error: "${errorMessage || ''}"`; const labels = ['Component: Developer Tools', 'Status: Unconfirmed']; @@ -57,10 +61,13 @@ If possible, please describe how to reproduce this bug on the website or app men DevTools version: ${process.env.DEVTOOLS_VERSION || ''} Call stack: -${callStack || '(not available)'} +${callStack || '(none)'} Component stack: -${componentStack || '(not available)'} +${componentStack || '(none)'} + +GitHub URL search query: +${gitHubAPISearch} `; bugURL += `/issues/new?labels=${encodeURIWrapper( diff --git a/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js b/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js index 3f63416bc1338..714919effa810 100644 --- a/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js +++ b/packages/react-devtools-shared/src/devtools/views/ErrorBoundary/githubAPI.js @@ -14,9 +14,7 @@ export type GitHubIssue = {| const GITHUB_ISSUES_API = 'https://api.github.com/search/issues'; -export async function searchGitHubIssues( - message: string, -): Promise { +export function searchGitHubIssuesURL(message: string): string { // Remove Fiber IDs from error message (as those will be unique). message = message.replace(/"[0-9]+"/g, ''); @@ -29,13 +27,19 @@ export async function searchGitHubIssues( 'repo:facebook/react', ]; - const response = await fetch( + return ( GITHUB_ISSUES_API + - '?q=' + - encodeURIComponent(message) + - '%20' + - filters.map(encodeURIComponent).join('%20'), + '?q=' + + encodeURIComponent(message) + + '%20' + + filters.map(encodeURIComponent).join('%20') ); +} + +export async function searchGitHubIssues( + message: string, +): Promise { + const response = await fetch(searchGitHubIssuesURL(message)); const data = await response.json(); if (data.items.length > 0) { const item = data.items[0];