diff --git a/.editorconfig-checker b/.editorconfig-checker index 4367774..98ee990 100644 --- a/.editorconfig-checker +++ b/.editorconfig-checker @@ -1,5 +1,5 @@ { - "Version": "v3.0.1", + "Version": "v3.0.3", "Verbose": false, "Format": "", "Debug": false, diff --git a/.husky/pre-commit b/.husky/pre-commit index 6513333..92cfb0b 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,4 @@ npm exec lint-staged npm run lint:ec npm run test:ci +npm run build diff --git a/dist/index.js b/dist/index.js index 311f3bf..41bf522 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42834,10 +42834,10 @@ var remark2 = remark().use(remarkGfm).data("settings", { // src/main.ts async function main({ octokit, - mainBranch, - perennialBranches, currentPullRequest, pullRequests, + mainBranch, + perennialBranches, skipSingleStacks }) { const repoGraph = new import_graphology.MultiDirectedGraph(); @@ -46861,18 +46861,21 @@ var inputs = { mainBranch = mainBranchInput !== "" ? mainBranchInput : mainBranch; return mainBranch; }, - async getPerennialBranches(octokit, config2, context3) { - const [{ data: unprotectedBranches }, { data: protectedBranches }] = await Promise.all([ - octokit.rest.repos.listBranches({ ...context3.repo }), - octokit.rest.repos.listBranches({ ...context3.repo, protected: true }) - ]); + async getRemoteBranches(octokit, context3) { + const remoteBranches = await octokit.paginate( + "GET /repos/{owner}/{repo}/branches", + { + ...context3.repo, + per_page: 100 + }, + (response) => response.data.map((branch) => branch.name) + ); core2.startGroup("Inputs: Remote branches"); - core2.info(`Unprotected: ${JSON.stringify(unprotectedBranches)}`); - core2.info(`Protected: ${JSON.stringify(protectedBranches)}`); + core2.info(JSON.stringify(remoteBranches)); core2.endGroup(); - const repoBranches = [...unprotectedBranches, ...protectedBranches].map( - (branch) => branch.name - ); + return remoteBranches; + }, + async getPerennialBranches(config2, remoteBranches) { let explicitBranches = []; explicitBranches = config2?.branches?.perennials ?? explicitBranches; const perennialBranchesInput = core2.getMultilineInput("perennial-branches", { @@ -46892,7 +46895,7 @@ var inputs = { perennialRegex = perennialRegexInput !== "" ? perennialRegexInput : perennialRegex; const perennialBranches = [ ...explicitBranches, - ...repoBranches.filter( + ...remoteBranches.filter( (branch) => perennialRegex ? RegExp(perennialRegex).test(branch) : false ) ]; @@ -46984,16 +46987,18 @@ async function run() { return; } const octokit = github2.getOctokit(inputs.getToken()); - const [mainBranch, perennialBranches, pullRequests] = await Promise.all([ + const [mainBranch, remoteBranches, pullRequests] = await Promise.all([ inputs.getMainBranch(octokit, config, github2.context), - inputs.getPerennialBranches(octokit, config, github2.context), + inputs.getRemoteBranches(octokit, github2.context), inputs.getPullRequests(octokit, github2.context) ]); + const perennialBranches = await inputs.getPerennialBranches(config, remoteBranches); const context3 = { octokit, currentPullRequest: inputs.getCurrentPullRequest(github2.context), pullRequests, mainBranch, + remoteBranches, perennialBranches, skipSingleStacks: inputs.getSkipSingleStacks() }; diff --git a/package-lock.json b/package-lock.json index 9b0184c..046f19e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "devDependencies": { "@types/node": "^20.11.30", "@vercel/style-guide": "^5.2.0", - "editorconfig-checker": "^5.1.5", + "editorconfig-checker": "5.1.8", "esbuild": "^0.20.2", "eslint": "^8.57.0", "eslint-plugin-prettier": "^5.1.3", @@ -2732,9 +2732,9 @@ } }, "node_modules/editorconfig-checker": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/editorconfig-checker/-/editorconfig-checker-5.1.5.tgz", - "integrity": "sha512-l2QifQhu33enwAauVdwT0oBPz8xdCHOZ7jImuUNV/3AR3Dg26jPAVPdHeKzuf1qpMZTfnuOONqLlpSIEFP33Ig==", + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/editorconfig-checker/-/editorconfig-checker-5.1.8.tgz", + "integrity": "sha512-GM/qCbXA8GajSqqjXiWZN49i0nizQV5PjkVKIwWB9rtsm/pztjnBC+4dts5wW2KdrP2zyMPEltWHtWQwoCadqg==", "dev": true, "bin": { "ec": "dist/index.js", diff --git a/package.json b/package.json index b634c94..c9f504e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "engineStrict": true, "scripts": { "dev": "npm run build -- --watch", - "build": "esbuild src/index.ts --outfile=dist/index.js --bundle --platform=node --target=node20 ", + "build": "esbuild src/index.ts --outfile=dist/index.js --bundle --platform=node --target=node20", "test": "vitest", "test:ci": "vitest run", "lint:eslint": "eslint src --max-warnings=0", @@ -30,7 +30,7 @@ "devDependencies": { "@types/node": "^20.11.30", "@vercel/style-guide": "^5.2.0", - "editorconfig-checker": "^5.1.5", + "editorconfig-checker": "5.1.8", "esbuild": "^0.20.2", "eslint": "^8.57.0", "eslint-plugin-prettier": "^5.1.3", diff --git a/src/index.ts b/src/index.ts index d9d62aa..ca0eaaf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,17 +19,19 @@ async function run() { const octokit = github.getOctokit(inputs.getToken()) - const [mainBranch, perennialBranches, pullRequests] = await Promise.all([ + const [mainBranch, remoteBranches, pullRequests] = await Promise.all([ inputs.getMainBranch(octokit, config, github.context), - inputs.getPerennialBranches(octokit, config, github.context), + inputs.getRemoteBranches(octokit, github.context), inputs.getPullRequests(octokit, github.context), ]) + const perennialBranches = await inputs.getPerennialBranches(config, remoteBranches) const context = { octokit, currentPullRequest: inputs.getCurrentPullRequest(github.context), pullRequests, mainBranch, + remoteBranches, perennialBranches, skipSingleStacks: inputs.getSkipSingleStacks(), } diff --git a/src/inputs.test.ts b/src/inputs.test.ts index 3d15d5c..d635264 100644 --- a/src/inputs.test.ts +++ b/src/inputs.test.ts @@ -91,53 +91,22 @@ describe('getMainBranch', () => { }) describe('getPerennialBranches', () => { - const octokit = { - rest: { - repos: { - listBranches: async () => ({ - data: [ - { - name: 'main', - commit: { sha: '', url: '' }, - protection: false, - }, - { - name: 'release-v1.0.0', - commit: { sha: '', url: '' }, - protection: false, - }, - { - name: 'v1.0.0', - commit: { sha: '', url: '' }, - protection: false, - }, - ], - }), - }, - }, - } as unknown as Octokit + const remoteBranches = ['main', 'release-v1.0.0', 'v1.0.0'] const config: Config = { branches: { perennials: ['dev', 'staging', 'prod'], 'perennial-regex': '^release-.*$', }, } - const context = { - repo: {}, - } as unknown as typeof github.context it('should default to no branches', async () => { - const perennialBranches = await inputs.getPerennialBranches( - octokit, - undefined, - context - ) + const perennialBranches = await inputs.getPerennialBranches(undefined, remoteBranches) expect(perennialBranches).toStrictEqual([]) }) it('should override default with config', async () => { - const perennialBranches = await inputs.getPerennialBranches(octokit, config, context) + const perennialBranches = await inputs.getPerennialBranches(config, remoteBranches) expect(perennialBranches).toStrictEqual(['dev', 'staging', 'prod', 'release-v1.0.0']) }) @@ -153,7 +122,7 @@ describe('getPerennialBranches', () => { ) vi.stubEnv('INPUT_PERENNIAL-REGEX', '^v.*$') - const perennialBranches = await inputs.getPerennialBranches(octokit, config, context) + const perennialBranches = await inputs.getPerennialBranches(config, remoteBranches) expect(perennialBranches).toStrictEqual(['test', 'uat', 'live', 'v1.0.0']) }) diff --git a/src/inputs.ts b/src/inputs.ts index 4720d44..95bbea5 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -44,26 +44,27 @@ export const inputs = { return mainBranch }, - async getPerennialBranches( - octokit: Octokit, - config: Config | undefined, - context: typeof github.context - ): Promise { - const [{ data: unprotectedBranches }, { data: protectedBranches }] = - await Promise.all([ - octokit.rest.repos.listBranches({ ...context.repo }), - octokit.rest.repos.listBranches({ ...context.repo, protected: true }), - ]) + async getRemoteBranches(octokit: Octokit, context: typeof github.context) { + const remoteBranches = await octokit.paginate( + 'GET /repos/{owner}/{repo}/branches', + { + ...context.repo, + per_page: 100, + }, + (response) => response.data.map((branch) => branch.name) + ) core.startGroup('Inputs: Remote branches') - core.info(`Unprotected: ${JSON.stringify(unprotectedBranches)}`) - core.info(`Protected: ${JSON.stringify(protectedBranches)}`) + core.info(JSON.stringify(remoteBranches)) core.endGroup() - const repoBranches = [...unprotectedBranches, ...protectedBranches].map( - (branch) => branch.name - ) + return remoteBranches + }, + async getPerennialBranches( + config: Config | undefined, + remoteBranches: string[] + ): Promise { let explicitBranches: string[] = [] explicitBranches = config?.branches?.perennials ?? explicitBranches const perennialBranchesInput = core.getMultilineInput('perennial-branches', { @@ -87,7 +88,7 @@ export const inputs = { const perennialBranches = [ ...explicitBranches, - ...repoBranches.filter((branch) => + ...remoteBranches.filter((branch) => perennialRegex ? RegExp(perennialRegex).test(branch) : false ), ] diff --git a/src/main.ts b/src/main.ts index c6ed500..698d58e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,10 +7,10 @@ import { remark } from './remark' export async function main({ octokit, - mainBranch, - perennialBranches, currentPullRequest, pullRequests, + mainBranch, + perennialBranches, skipSingleStacks, }: Context) { const repoGraph = new MultiDirectedGraph()