fix: action failure on branch with perennial parent (#10)

This commit is contained in:
Long Tran
2024-03-28 20:55:36 +11:00
committed by GitHub
parent eb21bfe902
commit 1860fa26f8
5 changed files with 28 additions and 12 deletions
+4
View File
@@ -1,3 +1,7 @@
## Description
## Stack
<!-- branch-stack -->
+9 -4
View File
@@ -46840,8 +46840,13 @@ var inputs = {
return mainBranch;
},
async getPerennialBranches(octokit, config2, context3) {
const { data } = await octokit.rest.repos.listBranches({ ...context3.repo });
const repoBranches = data.map((branch) => branch.name);
const [{ data: unprotectedBranches }, { data: protectedBranches }] = await Promise.all([
octokit.rest.repos.listBranches({ ...context3.repo }),
octokit.rest.repos.listBranches({ ...context3.repo, protected: true })
]);
const repoBranches = [...unprotectedBranches, ...protectedBranches].map(
(branch) => branch.name
);
let explicitBranches = [];
explicitBranches = config2?.branches?.perennials ?? explicitBranches;
const perennialBranchesInput = core2.getMultilineInput("perennial-branches", {
@@ -46850,7 +46855,7 @@ var inputs = {
});
explicitBranches = perennialBranchesInput.length > 0 ? perennialBranchesInput : explicitBranches;
let perennialRegex;
perennialRegex = config2?.branches?.perennialRegex ?? perennialRegex;
perennialRegex = config2?.branches?.["perennial-regex"] ?? perennialRegex;
const perennialRegexInput = core2.getInput("perennial-regex", {
required: false,
trimWhitespace: true
@@ -46906,7 +46911,7 @@ var configSchema = object({
branches: object({
main: string3().optional(),
perennials: array(string3()).optional(),
perennialRegex: string3().optional()
"perennial-regex": string3().optional()
}).optional()
});
var configFile;
+1 -1
View File
@@ -9,7 +9,7 @@ const configSchema = object({
branches: object({
main: string().optional(),
perennials: array(string()).optional(),
perennialRegex: string().optional(),
'perennial-regex': string().optional(),
}).optional(),
})
+5 -4
View File
@@ -2,6 +2,7 @@ import { describe, beforeEach, it, expect, vi } from 'vitest'
import type * as github from '@actions/github'
import { inputs } from './inputs'
import type { Octokit } from './types'
import type { Config } from './config'
beforeEach(() => {
vi.unstubAllEnvs()
@@ -24,7 +25,7 @@ describe('getMainBranch', () => {
},
},
} as unknown as Octokit
const config = {}
const config: Config = {}
const context = {
repo: {},
} as unknown as typeof github.context
@@ -46,7 +47,7 @@ describe('getMainBranch', () => {
},
},
} as unknown as Octokit
const config = {
const config: Config = {
branches: {
main: 'main',
},
@@ -115,10 +116,10 @@ describe('getPerennialBranches', () => {
},
},
} as unknown as Octokit
const config = {
const config: Config = {
branches: {
perennials: ['dev', 'staging', 'prod'],
perennialRegex: '^release-.*$',
'perennial-regex': '^release-.*$',
},
}
const context = {
+9 -3
View File
@@ -37,8 +37,14 @@ export const inputs = {
config: Config | undefined,
context: typeof github.context
): Promise<string[]> {
const { data } = await octokit.rest.repos.listBranches({ ...context.repo })
const repoBranches = data.map((branch) => branch.name)
const [{ data: unprotectedBranches }, { data: protectedBranches }] =
await Promise.all([
octokit.rest.repos.listBranches({ ...context.repo }),
octokit.rest.repos.listBranches({ ...context.repo, protected: true }),
])
const repoBranches = [...unprotectedBranches, ...protectedBranches].map(
(branch) => branch.name
)
let explicitBranches: string[] = []
explicitBranches = config?.branches?.perennials ?? explicitBranches
@@ -50,7 +56,7 @@ export const inputs = {
perennialBranchesInput.length > 0 ? perennialBranchesInput : explicitBranches
let perennialRegex: string | undefined
perennialRegex = config?.branches?.perennialRegex ?? perennialRegex
perennialRegex = config?.branches?.['perennial-regex'] ?? perennialRegex
const perennialRegexInput = core.getInput('perennial-regex', {
required: false,
trimWhitespace: true,