From 3c9f2c86119a0260192eaae2a13b3354187e94d9 Mon Sep 17 00:00:00 2001 From: Samuel El-Borai Date: Fri, 19 Jan 2024 23:51:59 -0500 Subject: [PATCH] WIP: PR title for multiple components --- src/util/pull-request-title.ts | 50 +++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/util/pull-request-title.ts b/src/util/pull-request-title.ts index bacb74547..774ef039c 100644 --- a/src/util/pull-request-title.ts +++ b/src/util/pull-request-title.ts @@ -19,11 +19,27 @@ import {Version} from '../version'; // at the script level are undefined, they are only defined inside function // or instance methods/properties. -const DEFAULT_PR_TITLE_PATTERN = - 'chore${scope}: release${component} ${version}'; -export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp { +const DEFAULT_PR_TITLE_PATTERN = 'release: ${componentsSegment}'; + +/** + * Default pattern for a component in the "components segment" of the release PR title + */ +const DEFAULT_PR_TITLE_PATTERN_SINGLE_COMPONENT_SEGMENT = + '${component} ${version}'; + +/** + * Default separator for components in the "component segment" of the release PR. + */ +const DEFAULT_PR_TITLE_PATTERN_COMPONENT_SEPARATOR = ','; + +export function generateMatchPatternPRTitleComponentsSegment( + componentsSegmentPattern?: string +): RegExp { return new RegExp( - `^${(pullRequestTitlePattern || DEFAULT_PR_TITLE_PATTERN) + `^${( + componentsSegmentPattern || + DEFAULT_PR_TITLE_PATTERN_SINGLE_COMPONENT_SEGMENT + ) .replace('[', '\\[') // TODO: handle all regex escaping .replace(']', '\\]') .replace('(', '\\(') @@ -39,6 +55,26 @@ export function generateMatchPattern(pullRequestTitlePattern?: string): RegExp { ); } +export function generateMatchPatternPRTitle( + pullRequestTitlePattern?: string +): RegExp { + return new RegExp( + `^${(pullRequestTitlePattern || DEFAULT_PR_TITLE_PATTERN) + .replace('[', '\\[') // TODO: handle all regex escaping + .replace(']', '\\]') + .replace('(', '\\(') + .replace(')', '\\)') + .replace( + '${scope}', + '(\\((?[\\w-./]+ => )?(?[\\w-./]+)\\))?' + ) + // FIXME(sam): review + fix regexp for components segment + .replace('${componentsSegment}', ' ?(?@?[\\w-./]*)?') + .replace('${changesBranch}', '(??[\\w-./]+)?') + .replace('${branch}', '(?[\\w-./]+)?')}$` + ); +} + export class PullRequestTitle { components?: string[]; changesBranch?: string; @@ -97,11 +133,11 @@ export class PullRequestTitle { pullRequestTitlePattern, }); } - static ofVersion( - versions: Version[], + static ofSingleVersion( + version: Version, pullRequestTitlePattern?: string ): PullRequestTitle { - return new PullRequestTitle({versions, pullRequestTitlePattern}); + return new PullRequestTitle({versions: [version], pullRequestTitlePattern}); } static ofTargetBranchVersion( targetBranch: string,