-
Notifications
You must be signed in to change notification settings - Fork 47.7k
/
Copy pathgithubAPI.js
46 lines (40 loc) · 987 Bytes
/
githubAPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import {Octokit} from '@octokit/rest';
export type GitHubIssue = {|
title: string,
url: string,
|};
export async function searchGitHubIssues(
message: string,
): Promise<GitHubIssue | null> {
// Remove Fiber IDs from error message (as those will be unique).
message = message.replace(/"[0-9]+"/, '');
const filters = [
'in:title',
'is:issue',
'is:open',
'is:public',
'label:"Component: Developer Tools"',
'repo:facebook/react',
];
const octokit = new Octokit();
const {data} = await octokit.search.issuesAndPullRequests({
q: message + ' ' + filters.join(' '),
});
if (data.items.length > 0) {
const item = data.items[0];
return {
title: item.title,
url: item.html_url,
};
} else {
return null;
}
}