Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

use graphQL to collect issues and prs for a given milestone (#78496)

Chris Vandoodewaardefb763bef820
diff --git a/.github/workflows/release-notes-preview.yml b/.github/workflows/release-notes-preview.yml
index 30cb9930397..d471ec1d847 100644
--- a/.github/workflows/release-notes-preview.yml
+++ b/.github/workflows/release-notes-preview.yml
@@ -36,6 +36,8 @@ jobs:
- name: Get Release Version
uses: actions/github-script@v9
env:
+ # required by getMilestoneIssues to configure GraphQL client
+ GITHUB_TOKEN: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}
DOCKERHUB_OWNER: test_owner
DOCKERHUB_REPO: test_repo
AWS_S3_DOWNLOADS_BUCKET: test_bucket
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 88c3d3d2a55..6c08f26547b 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -445,6 +445,9 @@ jobs:
uses: ./.github/actions/prepare-release-scripts
- name: Publish draft release notes to github
uses: actions/github-script@v9
+ env:
+ # required by getMilestoneIssues to configure GraphQL client
+ GITHUB_TOKEN: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}
with:
github-token: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}
result-encoding: string
diff --git a/release/bun.lock b/release/bun.lock
index 3d7b91306ec..b1f44843b6e 100644
--- a/release/bun.lock
+++ b/release/bun.lock
@@ -5,6 +5,7 @@
"": {
"name": "release-helper",
"dependencies": {
+ "@octokit/plugin-paginate-graphql": "^6.0.0",
"@octokit/rest": "^21.1.1",
"@slack/web-api": "^8.0.0",
"dayjs": "^1.11.20",
@@ -364,6 +365,8 @@
"@octokit/openapi-types": ["@octokit/[email protected]", "", {}, "sha512-FZvktFu7HfOIJf2BScLKIEYjDsw6RKc7rBJCdvCTfKsVnx2GEB/Nbzjr29DUdb7vQhlzS/j8qDzdditP0OC6aw=="],
+ "@octokit/plugin-paginate-graphql": ["@octokit/[email protected]", "", { "peerDependencies": { "@octokit/core": ">=6" } }, "sha512-crfpnIoFiBtRkvPqOyLOsw12XsveYuY2ieP6uYDosoUegBJpSVxGwut9sxUgFFcll3VTOTqpUf8yGd8x1OmAkQ=="],
+
"@octokit/plugin-paginate-rest": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/types": "^13.10.0" } }, "sha512-n5KPteiF7pWKgBIBJSk8qzoZWcUkza2O6A0za97pMGVrGfPdltxrfmfF5GucHYvHGZD8BdaZmmHGz5cX/3gdpw=="],
"@octokit/plugin-request-log": ["@octokit/[email protected]", "", {}, "sha512-n/lNeCtq+9ofhC15xzmJCNKP2BWTv8Ih2TTy+jatNCCq/gQP/V7rK3fjIfuz0pDWDALO/o/4QY4hyOF6TQQFUw=="],
diff --git a/release/package.json b/release/package.json
index 7ed667590b5..230a1ecb5c7 100644
--- a/release/package.json
+++ b/release/package.json
@@ -19,6 +19,7 @@
"author": "Metabase",
"license": "AGPL-3.0-or-later",
"dependencies": {
+ "@octokit/plugin-paginate-graphql": "^6.0.0",
"@octokit/rest": "^21.1.1",
"@slack/web-api": "^8.0.0",
"dayjs": "^1.11.20",
diff --git a/release/src/github.ts b/release/src/github.ts
index 2fc4758e477..a81ddf84768 100644
--- a/release/src/github.ts
+++ b/release/src/github.ts
@@ -1,3 +1,6 @@
+import { Octokit } from "@octokit/rest";
+import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
+
import type { GithubCheck, GithubProps, Issue, ReleaseProps } from "./types";
import {
getLastReleaseTag,
@@ -8,6 +11,65 @@ import {
type MilestoneState = "open" | "closed" | "all";
+const PaginatingOctokit = Octokit.plugin(paginateGraphQL);
+
+type MilestoneItemNode = {
+ number: number;
+ id: string;
+ title: string;
+ body: string | null;
+ url: string;
+ createdAt: string;
+ labels: { nodes: { name: string }[] };
+ assignees: { nodes: { login: string }[] };
+};
+
+const getMilestoneItems = async ({
+ owner,
+ repo,
+ milestoneNumber,
+ connection,
+ states,
+}: {
+ owner: string;
+ repo: string;
+ milestoneNumber: number;
+ connection: "issues" | "pullRequests";
+ states: string[];
+}): Promise<MilestoneItemNode[]> => {
+ // The octokit injected by actions/github-script lacks the paginate-graphql
+ // plugin, so build our own plugin-enabled client from the token in env
+ const client = new PaginatingOctokit({ auth: process.env.GITHUB_TOKEN });
+ const stateType = connection === "pullRequests" ? "PullRequestState" : "IssueState";
+
+ const { repository } = await client.graphql.paginate<{
+ repository: { milestone: Record<string, { nodes: MilestoneItemNode[] }> };
+ }>(
+ `query paginate($cursor: String, $owner: String!, $repo: String!, $num: Int!, $states: [${stateType}!]) {
+ repository(owner: $owner, name: $repo) {
+ milestone(number: $num) {
+ ${connection}(first: 100, after: $cursor, states: $states) {
+ pageInfo { hasNextPage endCursor }
+ nodes {
+ number
+ id
+ title
+ body
+ url
+ createdAt
+ labels(first: 50) { nodes { name } }
+ assignees(first: 1) { nodes { login } }
+ }
+ }
+ }
+ }
+ }`,
+ { owner, repo, num: milestoneNumber, states },
+ );
+
+ return repository.milestone[connection].nodes;
+};
+
export const getMilestones = async ({
github,
owner,
@@ -106,15 +168,44 @@ export const getMilestoneIssues = async ({
return [];
}
- // we have to use paginate function or the issues will be truncated to 100
- const issues = await github.paginate(github.rest.issues.listForRepo, {
- owner,
- repo,
- milestone: String(milestone.number),
- state,
+ const issueStates = state === "closed" ? ["CLOSED"] : ["OPEN"];
+ const prStates = state === "closed" ? ["MERGED", "CLOSED"] : ["OPEN"];
+
+ const [issueNodes, prNodes] = await Promise.all([
+ getMilestoneItems({
+ owner,
+ repo,
+ milestoneNumber: milestone.number,
+ connection: "issues",
+ states: issueStates,
+ }),
+ getMilestoneItems({
+ owner,
+ repo,
+ milestoneNumber: milestone.number,
+ connection: "pullRequests",
+ states: prStates,
+ }),
+ ]);
+
+ // map results of getMilestoneItems to Issue type
+ const toIssue = (n: MilestoneItemNode, isPR: boolean): Issue => ({
+ number: n.number,
+ node_id: n.id,
+ title: n.title,
+ html_url: n.url,
+ body: n.body ?? "",
+ pull_request: isPR ? { html_url: n.url } : undefined,
+ milestone,
+ labels: n.labels.nodes.map((l) => ({ name: l.name })),
+ assignee: n.assignees.nodes[0] ? { login: n.assignees.nodes[0].login } : null,
+ created_at: n.createdAt,
});
- return (issues ?? []) as Issue[];
+ return [
+ ...issueNodes.map((n) => toIssue(n, false)),
+ ...prNodes.map((n) => toIssue(n, true)),
+ ];
};
export const hasBeenReleased = async ({