Skip to content

Commit

Permalink
feat: Introduce new parameter componentNoSpace; Partially revert pr…
Browse files Browse the repository at this point in the history
…evious changes
  • Loading branch information
Kiruyuto committed Sep 11, 2024
1 parent 767149e commit 555b2a6
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 39 deletions.
11 changes: 10 additions & 1 deletion schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@
"initial-version": {
"description": "Releases the initial library with a specified version",
"type": "string"
},
"component-no-space": {
"description": "release-please automatically adds ` ` (space) in front of parsed ${component}. This option indicates whether that behaviour should be disabled. Defaults to `false`",
"type": "boolean"
}
}
}
Expand Down Expand Up @@ -423,6 +427,10 @@
"release-label": {
"description": "Comma-separated list of labels to add to a pull request that has been released/tagged",
"type": "string"
},
"component-no-space": {
"description": "release-please automatically adds ` ` (space) in front of parsed ${component}. This option indicates whether that behaviour should be disabled. Defaults to `false`",
"type": "boolean"
}
},
"required": ["packages"]
Expand Down Expand Up @@ -467,6 +475,7 @@
"version-file": true,
"snapshot-label": true,
"initial-version": true,
"exclude-paths": true
"exclude-paths": true,
"component-no-space": false
}
}
7 changes: 7 additions & 0 deletions src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ interface TaggingArgs {
pullRequestTitlePattern?: string;
pullRequestHeader?: string;
pullRequestFooter?: string;
componentNoSpace?: boolean;
}

interface CreatePullRequestArgs
Expand Down Expand Up @@ -424,6 +425,11 @@ function taggingOptions(yargs: yargs.Argv): yargs.Argv {
.option('pull-request-footer', {
describe: 'Footer for release PR',
type: 'string',
})
.option('component-no-space', {
describe: 'release-please automatically adds ` ` (space) in front of parsed ${component}. Should this be disabled?',
type: 'boolean',
default: false
});
}
Expand Down Expand Up @@ -464,6 +470,7 @@ const createReleasePullRequestCommand: yargs.CommandModule<
pullRequestTitlePattern: argv.pullRequestTitlePattern,
pullRequestHeader: argv.pullRequestHeader,
pullRequestFooter: argv.pullRequestFooter,
componentNoSpace: argv.componentNoSpace,
changelogSections: argv.changelogSections,
releaseAs: argv.releaseAs,
versioning: argv.versioningStrategy,
Expand Down
6 changes: 5 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface ReleaserConfig {
pullRequestTitlePattern?: string;
pullRequestHeader?: string;
pullRequestFooter?: string;
componentNoSpace?: boolean;
tagSeparator?: string;
separatePullRequests?: boolean;
labels?: string[];
Expand Down Expand Up @@ -173,6 +174,7 @@ interface ReleaserConfigJson {
'pull-request-title-pattern'?: string;
'pull-request-header'?: string;
'pull-request-footer'?: string;
'component-no-space'?: boolean;
'separate-pull-requests'?: boolean;
'tag-separator'?: string;
'extra-files'?: ExtraFile[];
Expand Down Expand Up @@ -1368,6 +1370,7 @@ function extractReleaserConfig(
pullRequestTitlePattern: config['pull-request-title-pattern'],
pullRequestHeader: config['pull-request-header'],
pullRequestFooter: config['pull-request-footer'],
componentNoSpace: config['component-no-space'],
tagSeparator: config['tag-separator'],
separatePullRequests: config['separate-pull-requests'],
labels: config['label']?.split(','),
Expand Down Expand Up @@ -1541,7 +1544,6 @@ function isPublishedVersion(strategy: Strategy, version: Version): boolean {
* @param {string} targetBranch Name of the scanned branch.
* @param releaseFilter Validator function for release version. Used to filter-out SNAPSHOT releases for Java strategy.
* @param {string} prefix Limit the release to a specific component.
* @param pullRequestTitlePattern Configured PR title pattern.
*/
async function latestReleaseVersion(
github: GitHub,
Expand Down Expand Up @@ -1607,6 +1609,7 @@ async function latestReleaseVersion(
const pullRequestTitle = PullRequestTitle.parse(
mergedPullRequest.title,
config.pullRequestTitlePattern,
config.componentNoSpace,
logger
);
if (!pullRequestTitle) {
Expand Down Expand Up @@ -1725,6 +1728,7 @@ function mergeReleaserConfig(
pathConfig.pullRequestHeader ?? defaultConfig.pullRequestHeader,
pullRequestFooter:
pathConfig.pullRequestFooter ?? defaultConfig.pullRequestFooter,
componentNoSpace: pathConfig.componentNoSpace ?? defaultConfig.componentNoSpace,
separatePullRequests:
pathConfig.separatePullRequests ?? defaultConfig.separatePullRequests,
skipSnapshot: pathConfig.skipSnapshot ?? defaultConfig.skipSnapshot,
Expand Down
12 changes: 11 additions & 1 deletion src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface BaseStrategyOptions {
pullRequestTitlePattern?: string;
pullRequestHeader?: string;
pullRequestFooter?: string;
componentNoSpace?: boolean;
extraFiles?: ExtraFile[];
versionFile?: string;
snapshotLabels?: string[]; // Java-only
Expand Down Expand Up @@ -109,6 +110,7 @@ export abstract class BaseStrategy implements Strategy {
readonly pullRequestTitlePattern?: string;
readonly pullRequestHeader?: string;
readonly pullRequestFooter?: string;
readonly componentNoSpace?: boolean;
readonly extraFiles: ExtraFile[];
readonly extraLabels: string[];

Expand Down Expand Up @@ -142,6 +144,7 @@ export abstract class BaseStrategy implements Strategy {
this.pullRequestTitlePattern = options.pullRequestTitlePattern;
this.pullRequestHeader = options.pullRequestHeader;
this.pullRequestFooter = options.pullRequestFooter;
this.componentNoSpace = options.componentNoSpace;
this.extraFiles = options.extraFiles || [];
this.initialVersion = options.initialVersion;
this.extraLabels = options.extraLabels || [];
Expand Down Expand Up @@ -292,11 +295,16 @@ export abstract class BaseStrategy implements Strategy {
'pull request title pattern:',
this.pullRequestTitlePattern
);
this.logger.debug(
'componentNoSpace:',
this.componentNoSpace
);
const pullRequestTitle = PullRequestTitle.ofComponentTargetBranchVersion(
component || '',
this.targetBranch,
newVersion,
this.pullRequestTitlePattern
this.pullRequestTitlePattern,
this.componentNoSpace
);
const branchComponent = await this.getBranchComponent();
const branchName = branchComponent
Expand Down Expand Up @@ -580,11 +588,13 @@ export abstract class BaseStrategy implements Strategy {
PullRequestTitle.parse(
mergedPullRequest.title,
this.pullRequestTitlePattern,
this.componentNoSpace,
this.logger
) ||
PullRequestTitle.parse(
mergedPullRequest.title,
mergedTitlePattern,
this.componentNoSpace,
this.logger
);
if (!pullRequestTitle) {
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/dotnet-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const CHANGELOG_SECTIONS = [
];
const DEFAULT_CHANGELOG_PATH = 'docs/history.md';
const DEFAULT_PULL_REQUEST_TITLE_PATTERN =
'Release ${component} version ${version}';
'Release${component} version ${version}';
const DEFAULT_PULL_REQUEST_HEADER =
':robot: I have created a release *beep* *boop*';
const DEFAULT_PULL_REQUEST_FOOTER =
Expand Down
1 change: 1 addition & 0 deletions src/strategies/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class Java extends BaseStrategy {
PullRequestTitle.parse(
commit.pullRequest?.title || commit.message,
this.pullRequestTitlePattern,
this.componentNoSpace,
this.logger
)
)
Expand Down
1 change: 1 addition & 0 deletions src/updaters/release-please-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function releaserConfigToJsonConfig(
'pull-request-title-pattern': config.pullRequestTitlePattern,
'pull-request-header': config.pullRequestHeader,
'pull-request-footer': config.pullRequestFooter,
'component-no-space': config.componentNoSpace,
'separate-pull-requests': config.separatePullRequests,
'tag-separator': config.tagSeparator,
'extra-files': config.extraFiles,
Expand Down
51 changes: 32 additions & 19 deletions src/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ import {Version} from '../version';
// or instance methods/properties.

const DEFAULT_PR_TITLE_PATTERN =
'chore${scope}: release ${component} ${version}';
'chore${scope}: release${component} ${version}';
const COMPONENT_NO_SPACE = false;

export function generateMatchPattern(
pullRequestTitlePattern?: string,
componentNoSpace?: boolean,
logger: Logger = defaultLogger
): RegExp {
console.log(`componentNoSpace-generateMatch: ${componentNoSpace}`)
if (
pullRequestTitlePattern &&
pullRequestTitlePattern.search(/\$\{scope\}/) === -1
Expand All @@ -47,7 +51,7 @@ export function generateMatchPattern(
.replace('(', '\\(')
.replace(')', '\\)')
.replace('${scope}', '(\\((?<branch>[\\w-./]+)\\))?')
.replace('${component}', '?(?<component>@?[\\w-./]*)?')
.replace('${component}', componentNoSpace === true ? '?(?<component>@?[\\w-./]*)?' : ' ?(?<component>@?[\\w-./]*)?')
.replace('${version}', 'v?(?<version>[0-9].*)')
.replace('${branch}', '(?<branch>[\\w-./]+)?')}$`
);
Expand All @@ -59,31 +63,36 @@ export class PullRequestTitle {
version?: Version;
pullRequestTitlePattern: string;
matchPattern: RegExp;
componentNoSpace?: boolean;

private constructor(opts: {
version?: Version;
component?: string;
targetBranch?: string;
pullRequestTitlePattern?: string;
componentNoSpace?: boolean
logger?: Logger;
}) {
this.version = opts.version;
this.component = opts.component;
this.targetBranch = opts.targetBranch;
this.pullRequestTitlePattern =
opts.pullRequestTitlePattern || DEFAULT_PR_TITLE_PATTERN;
this.componentNoSpace = opts.componentNoSpace || COMPONENT_NO_SPACE;
this.matchPattern = generateMatchPattern(
this.pullRequestTitlePattern,
this.componentNoSpace,
opts.logger
);
}

static parse(
title: string,
pullRequestTitlePattern?: string,
componentNoSpace?: boolean,
logger: Logger = defaultLogger
): PullRequestTitle | undefined {
const matchPattern = generateMatchPattern(pullRequestTitlePattern, logger);
const matchPattern = generateMatchPattern(pullRequestTitlePattern, componentNoSpace, logger);
const match = title.match(matchPattern);
if (match?.groups) {
return new PullRequestTitle({
Expand All @@ -93,6 +102,7 @@ export class PullRequestTitle {
component: match.groups['component'],
targetBranch: match.groups['branch'],
pullRequestTitlePattern,
componentNoSpace,
logger,
});
}
Expand All @@ -102,47 +112,55 @@ export class PullRequestTitle {
static ofComponentVersion(
component: string,
version: Version,
pullRequestTitlePattern?: string
pullRequestTitlePattern?: string,
componentNoSpace?: boolean
): PullRequestTitle {
return new PullRequestTitle({version, component, pullRequestTitlePattern});
return new PullRequestTitle({version, component, pullRequestTitlePattern, componentNoSpace});
}
static ofVersion(
version: Version,
pullRequestTitlePattern?: string
pullRequestTitlePattern?: string,
componentNoSpace?: boolean
): PullRequestTitle {
return new PullRequestTitle({version, pullRequestTitlePattern});
return new PullRequestTitle({version, pullRequestTitlePattern, componentNoSpace});
}
static ofTargetBranchVersion(
targetBranch: string,
version: Version,
pullRequestTitlePattern?: string
pullRequestTitlePattern?: string,
componentNoSpace?: boolean
): PullRequestTitle {
return new PullRequestTitle({
version,
targetBranch,
pullRequestTitlePattern,
componentNoSpace
});
}
static ofComponentTargetBranchVersion(
component?: string,
targetBranch?: string,
version?: Version,
pullRequestTitlePattern?: string
pullRequestTitlePattern?: string,
componentNoSpace?: boolean
): PullRequestTitle {
return new PullRequestTitle({
version,
component,
targetBranch,
pullRequestTitlePattern,
componentNoSpace
});
}
static ofTargetBranch(
targetBranch: string,
pullRequestTitlePattern?: string
pullRequestTitlePattern?: string,
componentNoSpace?: boolean
): PullRequestTitle {
return new PullRequestTitle({
targetBranch,
pullRequestTitlePattern,
componentNoSpace
});
}

Expand All @@ -158,16 +176,11 @@ export class PullRequestTitle {

toString(): string {
const scope = this.targetBranch ? `(${this.targetBranch})` : '';
const component = this.component ? `${this.component}` : '';
const component = this.componentNoSpace === true ? (this.component ? `${this.component}` : '') : (this.component ? ` ${this.component}` : '');
const version = this.version ?? '';
if (!component) {
console.log(
'"component" is empty, removing component from title pattern.'
);
this.pullRequestTitlePattern = this.pullRequestTitlePattern.replace(
'${component} ',
''
);
if (this.componentNoSpace === true && !component) {
console.log('`component` is empty. Removing component from title pattern..');
this.pullRequestTitlePattern = this.pullRequestTitlePattern.replace('${component} ', '');
}

return this.pullRequestTitlePattern
Expand Down
Loading

0 comments on commit 555b2a6

Please sign in to comment.