From 7a5c525049060d5fabd057d0f303bbed03f895df Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 28 Jan 2023 23:12:53 -0500 Subject: [PATCH] Create new interfaces for MatchConfig --- src/branch.ts | 14 +++++++------- src/labeler.ts | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/branch.ts b/src/branch.ts index 1c7e87b3..0a39a1d3 100644 --- a/src/branch.ts +++ b/src/branch.ts @@ -1,9 +1,14 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; +export interface BranchMatchConfig { + headBranch?: string[]; + baseBranch?: string[]; +} + type BranchBase = 'base' | 'head'; -export function toMatchConfigWithBranches(config: any) { +export function toBranchMatchConfig(config: any): BranchMatchConfig { if (!config['head-branch'] || config['base-branch']) { return config; } @@ -27,12 +32,7 @@ export function toMatchConfigWithBranches(config: any) { } } - return { - ...config, - ['head-branch']: undefined, - ['base-branch']: undefined, - ...branchConfig - }; + return branchConfig; } export function getBranchName(branchBase?: BranchBase): string | undefined { diff --git a/src/labeler.ts b/src/labeler.ts index a83181ca..919571fa 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -3,15 +3,19 @@ import * as github from '@actions/github'; import * as yaml from 'js-yaml'; import {Minimatch} from 'minimatch'; -import {checkBranch, toMatchConfigWithBranches} from './branch'; +import {checkBranch, toBranchMatchConfig, BranchMatchConfig} from './branch'; -interface MatchConfig { +interface FilesChangedMatchConfig { all?: string[]; any?: string[]; - headBranch?: string[]; - baseBranch?: string[]; + filesChanged?: { + all?: string[]; + any?: string[]; + }; } +type MatchConfig = FilesChangedMatchConfig & BranchMatchConfig; + type StringOrMatchConfig = string | MatchConfig; type ClientType = ReturnType; @@ -152,7 +156,12 @@ function toMatchConfig(config: StringOrMatchConfig): MatchConfig { }; } - return toMatchConfigWithBranches(config); + const branchConfig = toBranchMatchConfig(config); + + return { + ...config, + ...branchConfig + }; } function printPattern(matcher: Minimatch): string {