Skip to content

Commit

Permalink
Add GitHub API query to bug report template
Browse files Browse the repository at this point in the history
This may help debug why sometimes the GitHub API search seems to not find a match when it should.
  • Loading branch information
Brian Vaughn committed May 4, 2021
1 parent 4ca62ca commit 78f1ec9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'];

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export type GitHubIssue = {|

const GITHUB_ISSUES_API = 'https://api.github.com/search/issues';

export async function searchGitHubIssues(
message: string,
): Promise<GitHubIssue | null> {
export function searchGitHubIssuesURL(message: string): string {
// Remove Fiber IDs from error message (as those will be unique).
message = message.replace(/"[0-9]+"/g, '');

Expand All @@ -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<GitHubIssue | null> {
const response = await fetch(searchGitHubIssuesURL(message));
const data = await response.json();
if (data.items.length > 0) {
const item = data.items[0];
Expand Down

0 comments on commit 78f1ec9

Please sign in to comment.