Skip to content

Commit

Permalink
fix(build): allow download script to handle more than 30 GitHub relea…
Browse files Browse the repository at this point in the history
…se assets

To download the built schemas from `octokit/openapi`, we use
GitHub's "List release assets" API.

This API is paginated, which means that it will only by default
return up to 30 assets. This can mean that we miss data when the
script runs - e.g. see [this commit][1] where GitHub AE schemas
were dropped.

This fixes the issue by using Octokit's pagination plugin to
automatically cycle through pages and find all release assets.
A more lightweight fix would have been to set the `per_page`
attribute, but this is more correct and more future-proof.

[1]: 2704936
  • Loading branch information
timrogers committed Aug 15, 2022
1 parent f3ce532 commit 3bbf304
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { writeFileSync } from "node:fs";
import { mkdir, rm } from "node:fs/promises";

import { Octokit } from "@octokit/core";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import gheVersions from "github-enterprise-server-versions";
const { getCurrentVersions } = gheVersions;

Expand All @@ -14,7 +15,9 @@ run(process.env.OCTOKIT_OPENAPI_VERSION.replace(/^v/, "")).then(
console.error
);

const octokit = new Octokit({
const OctokitWithPlugins = Octokit.plugin(paginateRest);

const octokit = new OctokitWithPlugins({
auth: process.env.GITHUB_TOKEN,
});

Expand All @@ -30,7 +33,7 @@ async function run(version) {
tag: `v${version}`,
});

const { data: releaseAssets } = await octokit.request(
const releaseAssets = await octokit.paginate(
"GET /repos/{owner}/{repo}/releases/{release_id}/assets",
{
owner: "octokit",
Expand Down

0 comments on commit 3bbf304

Please sign in to comment.