Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub API query to bug report template #21421

Merged
merged 1 commit into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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