Skip to content

Commit 17583cb

Browse files
[tools] Try alternative GitHub search API
1 parent 5ade3dd commit 17583cb

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tools-public/toolpad/pages/waitingForMaintainer/page.yml

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ spec:
4747
- name: GITHUB_TOKEN
4848
value:
4949
$$env: GITHUB_TOKEN
50+
- name: waitingForMaintainer2
51+
mode: query
52+
query:
53+
function: queryGitHubSearchAPI.ts#queryGitHubSearchAPI
54+
kind: local
55+
parameters:
56+
- name: queryInput
57+
value:
58+
$$jsExpression: '`is:issue repo:mui/${page.parameters.repository}
59+
label:\\"status: waiting for maintainer\\"`'
5060
display: shell
5161
alias:
5262
- hj1i3hqe
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* eslint-disable import/prefer-default-export */
2+
import { rawRequest } from 'graphql-request';
3+
4+
export async function queryGitHubSearchAPI(queryInput = '', type = 'ISSUE') {
5+
if (!process.env.GITHUB_TOKEN) {
6+
throw new Error(`Env variable GITHUB_TOKEN not configured`);
7+
}
8+
9+
const endpoint = 'https://api.github.com/graphql';
10+
const token = process.env.GITHUB_TOKEN;
11+
12+
// https://docs.github.com/en/graphql/reference/queries#search
13+
// 5,000 requests/hr rate limit https://docs.github.com/en/graphql/overview/rate-limits-and-node-limits-for-the-graphql-api#primary-rate-limit
14+
// vs. https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#rate-limit
15+
// with 30 requests/minutes or 1,800 request/hr.
16+
const query = `
17+
{
18+
search(query: "${queryInput}", type: ${type}, first: 100) {
19+
issueCount
20+
nodes {
21+
... on PullRequest {
22+
number
23+
state
24+
labels(first: 10, orderBy: { direction: DESC, field: CREATED_AT }) {
25+
nodes {
26+
name
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
`;
34+
35+
const response = await rawRequest<any>(
36+
endpoint,
37+
query,
38+
{},
39+
{
40+
Authorization: `Bearer ${token}`,
41+
},
42+
);
43+
44+
return response.data.search;
45+
}

0 commit comments

Comments
 (0)