Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions .github/scripts/dependabot-pr-reminder/cli.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { appendFile, writeFile } from 'node:fs/promises';
import * as core from '@actions/core';
import { writeFile } from 'node:fs/promises';
import * as path from 'node:path';

import { createOctokit } from '../shared/octokit.mts';
Expand All @@ -19,16 +20,9 @@ async function main(): Promise<void> {
const maintainerTeam = environment.MAINTAINER_TEAM;
const githubToken = environment.GH_TOKEN;
const planningToken = environment.PLANNING_TOKEN;
const outputPath = environment.GITHUB_OUTPUT;
if (
!repository ||
!maintainerTeam ||
!githubToken ||
!planningToken ||
!outputPath
) {
if (!repository || !maintainerTeam || !githubToken || !planningToken) {
throw new Error(
'GITHUB_REPOSITORY, MAINTAINER_TEAM, GH_TOKEN, PLANNING_TOKEN and GITHUB_OUTPUT are required',
'GITHUB_REPOSITORY, MAINTAINER_TEAM, GH_TOKEN and PLANNING_TOKEN are required',
);
}

Expand All @@ -37,8 +31,8 @@ async function main(): Promise<void> {
repository,
);
if (pullRequests.length === 0) {
console.log('No open Dependabot pull requests to report.');
await appendFile(outputPath, 'has-prs=false\n');
core.info('No open Dependabot pull requests to report.');
core.setOutput('has-prs', false);
return;
}

Expand All @@ -52,8 +46,8 @@ async function main(): Promise<void> {
try {
topology = await fetchTopology(createOctokit(planningToken));
} catch (error) {
console.log(
`::warning::Could not read topology.json, posting without Slack tags: ${String(error)}`,
core.warning(
`Could not read topology.json, posting without Slack tags: ${String(error)}`,
);
}

Expand All @@ -68,12 +62,12 @@ async function main(): Promise<void> {
'dependabot-reminder-payload.json',
);
await writeFile(payloadPath, JSON.stringify(payload));
await appendFile(outputPath, `has-prs=true\npayload-path=${payloadPath}\n`);
core.setOutput('has-prs', true);
core.setOutput('payload-path', payloadPath);
}

try {
await main();
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
core.setFailed(error instanceof Error ? error.message : String(error));
}
2 changes: 1 addition & 1 deletion .github/scripts/dependabot-pr-reminder/cli.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('cli', () => {
});

await expect(run).rejects.toMatchObject({
stderr: expect.stringContaining('are required'),
stdout: expect.stringContaining('are required'),
});
});
});
3 changes: 1 addition & 2 deletions .github/scripts/dependabot-pr-reminder/github-api.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Octokit } from 'octokit';

import type { Octokit } from '../shared/octokit.mts';
import type { PullRequest } from './types.mts';

/**
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/dependabot-pr-reminder/github-api.test.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Octokit } from 'octokit';
import { describe, expect, it, vi } from 'vitest';
import type { Mock } from 'vitest';

import type { Octokit } from '../shared/octokit.mts';
import { fetchDependabotPullRequests } from './github-api.mts';
import type { PullRequest } from './types.mts';

Expand Down
22 changes: 19 additions & 3 deletions .github/scripts/shared/octokit.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import { Octokit } from 'octokit';
import type { getOctokit } from '@actions/github';
import { GitHub, getOctokitOptions } from '@actions/github/lib/utils';
import { paginateGraphQL } from '@octokit/plugin-paginate-graphql';
import type { paginateGraphQLInterface } from '@octokit/plugin-paginate-graphql';
import { retry } from '@octokit/plugin-retry';

type OctokitPlugin = Parameters<typeof getOctokit>[2];

// The plugins' types come from the root @octokit/core, which is not the one
// @actions/github uses, so they are cast to its plugin type.
const RetryingOctokit = GitHub.plugin(
retry as unknown as OctokitPlugin,
paginateGraphQL as unknown as OctokitPlugin,
);

/** An Octokit client that retries failed requests and paginates GraphQL. */
export type Octokit = InstanceType<typeof GitHub> & paginateGraphQLInterface;

/**
* Creates an Octokit client. It retries every method, writes included, so pass
Expand All @@ -10,7 +26,7 @@ import { Octokit } from 'octokit';
*/
export function createOctokit(
token: string,
options: ConstructorParameters<typeof Octokit>[0] = {},
options: Parameters<typeof getOctokitOptions>[1] = {},
): Octokit {
return new Octokit({ auth: token, ...options });
return new RetryingOctokit(getOctokitOptions(token, options)) as Octokit;
}
2 changes: 1 addition & 1 deletion .github/scripts/shared/topology.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Octokit } from 'octokit';
import type { Octokit } from './octokit.mts';

/**
* A team's entry in `topology.json`.
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/tests/topology.test.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Octokit } from 'octokit';
import { describe, expect, it, vi } from 'vitest';

import type { Octokit } from '../shared/octokit.mts';
import {
fetchTopology,
getSlackHandle,
Expand Down
9 changes: 3 additions & 6 deletions oxlint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@
"typescript/no-explicit-any": {
"count": 6
},
"typescript/no-unsafe-argument": {
"count": 4
},
"typescript/no-unsafe-assignment": {
"count": 12
"count": 8
},
"typescript/no-unsafe-call": {
"count": 14
"count": 3
},
"typescript/no-unsafe-member-access": {
"count": 21
"count": 9
},
"typescript/prefer-nullish-coalescing": {
"count": 6
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
"update-release-sheet": "node .github/scripts/update-release-sheet.mjs"
},
"dependencies": {
"@actions/core": "3.0.1",
"@actions/github": "9.1.1",
"@metamask/auto-changelog": "^7.0.1",
"@metamask/utils": "^7.1.0",
"@octokit/graphql": "^7.0.1",
"@octokit/plugin-paginate-graphql": "6.0.0",
"@octokit/plugin-retry": "8.1.1",
"@octokit/request": "^8.1.1",
"@octokit/rest": "^19.0.13",
"@slack/web-api": "^6.0.0",
Expand All @@ -39,7 +43,6 @@
"execa": "^9.5.2",
"googleapis": "144.0.0",
"luxon": "^3.3.0",
"octokit": "5.0.5",
"ora": "^5.4.1",
"prettier": "^3.6.2",
"semver": "^7.7.2",
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default defineConfig({
thresholds: {
// Raises the thresholds in this file when coverage improves.
autoUpdate: true,
branches: 43.74,
branches: 43.76,
functions: 53.86,
lines: 43.24,
statements: 43.45,
Expand Down
Loading