Skip to content

Commit

Permalink
WIP: PR title for multiple components
Browse files Browse the repository at this point in the history
  • Loading branch information
dgellow committed Jan 20, 2024
1 parent f3af23f commit 3c9f2c8
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions src/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('(', '\\(')
Expand All @@ -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}',
'(\\((?<changesBranch>[\\w-./]+ => )?(?<branch>[\\w-./]+)\\))?'
)
// FIXME(sam): review + fix regexp for components segment
.replace('${componentsSegment}', ' ?(?<componentsSegment>@?[\\w-./]*)?')
.replace('${changesBranch}', '(?<changesBranch>?[\\w-./]+)?')
.replace('${branch}', '(?<branch>[\\w-./]+)?')}$`
);
}

export class PullRequestTitle {
components?: string[];
changesBranch?: string;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3c9f2c8

Please sign in to comment.