Skip to content

Commit 66db580

Browse files
committed
use cursor paging for summary queries
- Some deps have hundreds of files which will timeout a summary query. - Add longer request timeout to graphql queries - Ignore .envrc used locally for testing - Bump version
1 parent 56d5615 commit 66db580

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typings/
7171
# dotenv environment variables file
7272
.env
7373
.env.test
74+
.envrc
7475

7576
# parcel-bundler cache (https://parceljs.org/)
7677
.cache

dist/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
4747
const stackAidJson = { version: 1, dependencies: [] };
4848
const owner = process.env.GITHUB_REPOSITORY_OWNER;
4949
const repo = (_a = process.env.GITHUB_REPOSITORY) === null || _a === void 0 ? void 0 : _a.split('/', 2)[1];
50+
// TODO(wes): Do not limit file paths for current repository.
5051
const direct = yield (0, queries_1.getRepositoryDependencies)(owner, repo);
5152
core.info(`Found ${direct.length} direct dependencies`);
5253
// We need to query each direct dependency separately since the graphql API
@@ -208,25 +209,44 @@ const graphql = (query, variables) => __awaiter(void 0, void 0, void 0, function
208209
// Required for dependency graph queries, see:
209210
// https://docs.github.com/en/graphql/overview/schema-previews#access-to-a-repositories-dependency-graph-preview
210211
Accept: 'application/vnd.github.hawkgirl-preview+json',
211-
} }));
212+
}, request: { timeout: 60 * 1000 } }));
212213
return result;
213214
});
214215
exports.graphql = graphql;
215-
const getRepositorySummary = (owner, repo) => __awaiter(void 0, void 0, void 0, function* () {
216+
const getRepositorySummaryPage = (owner, repo, cursor = '') => __awaiter(void 0, void 0, void 0, function* () {
216217
const result = (yield (0, exports.graphql)(`
217-
query getRepositorySummary($owner: String!, $repo: String!) {
218+
query getRepositorySummary(
219+
$owner: String!
220+
$repo: String!
221+
$cursor: String
222+
) {
218223
repository(owner: $owner, name: $repo) {
219224
dependencyGraphManifests(
220225
dependenciesFirst: 1
221226
withDependencies: true
227+
first: 100
228+
after: $cursor
222229
) {
223230
...summaryFragment
224231
}
225232
}
226233
}
227234
${(0, graphql_1.print)(exports.summaryFragment)}
228-
`, { repo, owner }));
235+
`, { repo, owner, cursor }));
229236
const { dependencyGraphManifests: { edges }, } = result.repository;
237+
return edges;
238+
});
239+
const getRepositorySummary = (owner, repo) => __awaiter(void 0, void 0, void 0, function* () {
240+
let edges = yield getRepositorySummaryPage(owner, repo);
241+
if (!edges.length) {
242+
return [];
243+
}
244+
let { cursor } = edges[edges.length - 1];
245+
while (cursor) {
246+
edges = [...edges, ...(yield getRepositorySummaryPage(owner, repo, cursor))];
247+
const next = edges[edges.length - 1].cursor;
248+
cursor = next !== cursor ? next : '';
249+
}
230250
const relevant = edges
231251
.filter((edge) => ALLOWED_FILENAMES.includes(edge.node.filename.toLowerCase()))
232252
.map((edge, i) => (Object.assign(Object.assign({}, edge), { after: i > 0 ? edges[i - 1].cursor : undefined })));

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stackaid-json-generator",
3-
"version": "0.1.4",
3+
"version": "1.1.0",
44
"private": false,
55
"description": "A GitHub action to generate a stackaid.json file based on your repository's dependency graph",
66
"main": "lib/src/main.js",

src/queries.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,60 @@ export const graphql = async (
8383
// https://docs.github.com/en/graphql/overview/schema-previews#access-to-a-repositories-dependency-graph-preview
8484
Accept: 'application/vnd.github.hawkgirl-preview+json',
8585
},
86+
request: { timeout: 60 * 1000 },
8687
})
8788

8889
return result as any
8990
}
9091

91-
export const getRepositorySummary = async (owner: string, repo: string) => {
92+
const getRepositorySummaryPage = async (
93+
owner: string,
94+
repo: string,
95+
cursor: string = ''
96+
) => {
9297
const result = (await graphql(
9398
`
94-
query getRepositorySummary($owner: String!, $repo: String!) {
99+
query getRepositorySummary(
100+
$owner: String!
101+
$repo: String!
102+
$cursor: String
103+
) {
95104
repository(owner: $owner, name: $repo) {
96105
dependencyGraphManifests(
97106
dependenciesFirst: 1
98107
withDependencies: true
108+
first: 100
109+
after: $cursor
99110
) {
100111
...summaryFragment
101112
}
102113
}
103114
}
104115
${print(summaryFragment)}
105116
`,
106-
{ repo, owner } as GetRepositorySummaryQueryVariables
117+
{ repo, owner, cursor } as GetRepositorySummaryQueryVariables
107118
)) as GetRepositorySummaryQuery
108119

109120
const {
110121
dependencyGraphManifests: { edges },
111122
} = result.repository
112123

124+
return edges
125+
}
126+
127+
export const getRepositorySummary = async (owner: string, repo: string) => {
128+
let edges = await getRepositorySummaryPage(owner, repo)
129+
if (!edges.length) {
130+
return []
131+
}
132+
133+
let { cursor } = edges[edges.length - 1]
134+
while (cursor) {
135+
edges = [...edges, ...(await getRepositorySummaryPage(owner, repo, cursor))]
136+
const next = edges[edges.length - 1].cursor
137+
cursor = next !== cursor ? next : ''
138+
}
139+
113140
const relevant = edges
114141
.filter((edge) =>
115142
ALLOWED_FILENAMES.includes(edge.node.filename.toLowerCase())

0 commit comments

Comments
 (0)