diff --git a/README.md b/README.md index 5e986df..7452c7e 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,9 @@ be done with the `perennial-branches` and `perennial-regex` inputs respectively: Both inputs can be used at the same time. This action will merge the perennial branches given into a single, de-duplicated list. -#### Skip Single Stacks +## Customization + +### Skip Single Stacks If you don't want the stack description to appear on pull requests which are not part of a stack, you can add `skip-single-stacks: true` to the job. diff --git a/action.yml b/action.yml index ad66c71..c5e2f90 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,9 @@ inputs: skip-single-stacks: required: false default: false + history-limit: + required: false + default: 0 runs: using: 'node20' diff --git a/package-lock.json b/package-lock.json index 1c80b02..4ab65a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "zod": "^3.22.4" }, "devDependencies": { + "@octokit/types": "^13.6.2", "@types/node": "^20.11.30", "@vercel/style-guide": "^5.2.0", "editorconfig-checker": "5.1.8", @@ -1126,6 +1127,19 @@ "node": ">= 18" } }, + "node_modules/@octokit/core/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" + }, + "node_modules/@octokit/core/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, "node_modules/@octokit/endpoint": { "version": "9.0.4", "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.4.tgz", @@ -1138,6 +1152,19 @@ "node": ">= 18" } }, + "node_modules/@octokit/endpoint/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" + }, + "node_modules/@octokit/endpoint/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, "node_modules/@octokit/graphql": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.0.2.tgz", @@ -1151,11 +1178,25 @@ "node": ">= 18" } }, - "node_modules/@octokit/openapi-types": { + "node_modules/@octokit/graphql/node_modules/@octokit/openapi-types": { "version": "20.0.0", "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" }, + "node_modules/@octokit/graphql/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "22.2.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-22.2.0.tgz", + "integrity": "sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==", + "dev": true + }, "node_modules/@octokit/plugin-paginate-rest": { "version": "9.2.1", "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.2.1.tgz", @@ -1170,6 +1211,19 @@ "@octokit/core": "5" } }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" + }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, "node_modules/@octokit/plugin-rest-endpoint-methods": { "version": "10.4.1", "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.4.1.tgz", @@ -1184,6 +1238,19 @@ "@octokit/core": "5" } }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" + }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, "node_modules/@octokit/request": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.2.0.tgz", @@ -1211,7 +1278,12 @@ "node": ">= 18" } }, - "node_modules/@octokit/types": { + "node_modules/@octokit/request-error/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" + }, + "node_modules/@octokit/request-error/node_modules/@octokit/types": { "version": "12.6.0", "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", @@ -1219,6 +1291,28 @@ "@octokit/openapi-types": "^20.0.0" } }, + "node_modules/@octokit/request/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==" + }, + "node_modules/@octokit/request/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, + "node_modules/@octokit/types": { + "version": "13.6.2", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.6.2.tgz", + "integrity": "sha512-WpbZfZUcZU77DrSW4wbsSgTPfKcp286q3ItaIgvSbBpZJlu6mnYXAkjZz6LVZPXkEvLIM8McanyZejKTYUHipA==", + "dev": true, + "dependencies": { + "@octokit/openapi-types": "^22.2.0" + } + }, "node_modules/@pkgr/core": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", diff --git a/package.json b/package.json index 20a810a..4cb7012 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "zod": "^3.22.4" }, "devDependencies": { + "@octokit/types": "^13.6.2", "@types/node": "^20.11.30", "@vercel/style-guide": "^5.2.0", "editorconfig-checker": "5.1.8", diff --git a/src/inputs.ts b/src/inputs.ts index 534f33e..95219ae 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core' import type * as github from '@actions/github' +import type { Endpoints } from '@octokit/types' import { pullRequestSchema } from './types' import type { PullRequest, Octokit } from './types' import type { Config } from './config' @@ -11,12 +12,27 @@ export const inputs = { getSkipSingleStacks() { core.startGroup('Inputs: Skip single stacks') - const input = core.getBooleanInput('skip-single-stacks', { required: false }) + const input = core.getBooleanInput('skip-single-stacks', { + required: false, + trimWhitespace: true, + }) core.info(input.toString()) core.endGroup() return input }, + getHistoryLimit() { + core.startGroup('Inputs: History limit') + const input = core.getInput('history-limit', { + required: false, + trimWhitespace: true, + }) + const historyLimit = Number.parseInt(input, 10) + core.info(input) + core.endGroup() + return historyLimit + }, + async getMainBranch( octokit: Octokit, config: Config | undefined, @@ -117,24 +133,43 @@ export const inputs = { }, async getPullRequests(octokit: Octokit, context: typeof github.context) { - const pullRequests = await octokit.paginate( - 'GET /repos/{owner}/{repo}/pulls', - { - ...context.repo, - state: 'all', - per_page: 100, - }, - (response) => - response.data.map( - (item): PullRequest => ({ - number: item.number, - base: { ref: item.base.ref }, - head: { ref: item.head.ref }, - body: item.body ?? undefined, - state: item.state, - }) - ) - ) + function toPullRequest( + item: Endpoints['GET /repos/{owner}/{repo}/pulls']['response']['data'][number] + ): PullRequest { + return { + number: item.number, + base: { ref: item.base.ref }, + head: { ref: item.head.ref }, + body: item.body ?? undefined, + state: item.state, + } + } + + const [openPullRequests, closedPullRequests] = await Promise.all([ + octokit.paginate( + 'GET /repos/{owner}/{repo}/pulls', + { + ...context.repo, + state: 'open', + per_page: 100, + }, + (response) => response.data.map(toPullRequest) + ), + + octokit.paginate( + 'GET /repos/{owner}/{repo}/pulls', + { + ...context.repo, + state: 'closed', + per_page: 100, + }, + (response, done) => { + return response.data.map(toPullRequest) + } + ), + ]) + + const pullRequests = [...openPullRequests, ...closedPullRequests] pullRequests.sort((a, b) => b.number - a.number) core.startGroup('Inputs: Pull requests')