Skip to content

Commit

Permalink
feat: reimplement custom pull request title (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 committed Nov 28, 2021
1 parent 0aeb67b commit 2f3e84c
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 45 deletions.
68 changes: 39 additions & 29 deletions __snapshots__/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,54 @@ release-please github-release
create a GitHub release from a release PR
Options:
--help Show help [boolean]
--version Show version number [boolean]
--debug print verbose errors (use only for local debugging).
[boolean] [default: false]
--trace print extra verbose errors (use only for local debugging).
[boolean] [default: false]
--token GitHub token with repo write permissions
--api-url URL to use when making API requests
--help Show help [boolean]
--version Show version number [boolean]
--debug print verbose errors (use only for local
debugging). [boolean] [default: false]
--trace print extra verbose errors (use only for local
debugging). [boolean] [default: false]
--token GitHub token with repo write permissions
--api-url URL to use when making API requests
[string] [default: "https://api.github.com"]
--graphql-url URL to use when making GraphQL requests
--graphql-url URL to use when making GraphQL requests
[string] [default: "https://api.github.com"]
--default-branch The branch to open release PRs against and tag releases on
--default-branch The branch to open release PRs against and tag
releases on
[deprecated: use --target-branch instead] [string]
--target-branch The branch to open release PRs against and tag releases on
[string]
--repo-url GitHub URL to generate release for [required]
--dry-run Prepare but do not take action [boolean] [default: false]
--monorepo-tags include library name in tags and release branches
--target-branch The branch to open release PRs against and tag
releases on [string]
--repo-url GitHub URL to generate release for [required]
--dry-run Prepare but do not take action
[boolean] [default: false]
--path release from path other than root directory [string]
--component name of component release is being minted for [string]
--package-name name of package release is being minted for [string]
--release-type what type of repo is a release being created for?
--monorepo-tags include library name in tags and release
branches [boolean] [default: false]
--pull-request-title-pattern Title pattern to make release PR [string]
--path release from path other than root directory
[string]
--component name of component release is being minted for
[string]
--package-name name of package release is being minted for
[string]
--release-type what type of repo is a release being created
for?
[choices: "dart", "elixir", "go", "go-yoshi", "helm", "java-backport",
"java-bom", "java-lts", "java-yoshi", "krm-blueprint", "node", "ocaml", "php",
"php-yoshi", "python", "ruby", "ruby-yoshi", "rust", "simple",
"terraform-module"]
--config-file where can the config file be found in the project?
[default: "release-please-config.json"]
--manifest-file where can the manifest file be found in the project?
--config-file where can the config file be found in the
project? [default: "release-please-config.json"]
--manifest-file where can the manifest file be found in the
project?
[default: ".release-please-manifest.json"]
--draft mark release as a draft. no tag is created but tag_name and
target_commitish are associated with the release for future
tag creation upon "un-drafting" the release.
--draft mark release as a draft. no tag is created but
tag_name and target_commitish are associated
with the release for future tag creation upon
"un-drafting" the release.
[boolean] [default: false]
--label comma-separated list of labels to remove to from release PR
[default: "autorelease: pending"]
--release-label set a pull request label other than "autorelease: tagged"
--label comma-separated list of labels to remove to from
release PR [default: "autorelease: pending"]
--release-label set a pull request label other than
"autorelease: tagged"
[string] [default: "autorelease: tagged"]
`

Expand Down Expand Up @@ -161,7 +171,6 @@ Options:
generated? [boolean] [default: false]
--versioning-strategy strategy used for bumping versions
[choices: "default", "always-bump-patch", "service-pack"] [default: "default"]
--pull-request-title-pattern Title pattern to make release PR [string]
--changelog-path where can the CHANGELOG be found in the
project? [string] [default: "CHANGELOG.md"]
--last-package-version last version # that package was released as
Expand All @@ -184,6 +193,7 @@ Options:
<email@example.com>"). [string]
--monorepo-tags include library name in tags and release
branches [boolean] [default: false]
--pull-request-title-pattern Title pattern to make release PR [string]
--path release from path other than root directory
[string]
--component name of component release is being minted
Expand Down
21 changes: 11 additions & 10 deletions src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ interface PullRequestStrategyArgs {
// for Ruby: TODO refactor to find version.rb like Python finds version.py
// and then remove this property
versionFile?: string;
pullRequestTitlePattern?: string;
extraFiles?: string[];
}

interface TaggingArgs {
monorepoTags?: boolean;
pullRequestTitlePattern?: string;
}

interface CreatePullRequestArgs
Expand Down Expand Up @@ -268,10 +268,6 @@ function pullRequestStrategyOptions(yargs: yargs.Argv): yargs.Argv {
choices: getVersioningStrategyTypes(),
default: 'default',
})
.option('pull-request-title-pattern', {
describe: 'Title pattern to make release PR',
type: 'string',
})
.option('changelog-path', {
default: 'CHANGELOG.md',
describe: 'where can the CHANGELOG be found in the project?',
Expand Down Expand Up @@ -351,11 +347,16 @@ function manifestOptions(yargs: yargs.Argv): yargs.Argv {
}
function taggingOptions(yargs: yargs.Argv): yargs.Argv {
return yargs.option('monorepo-tags', {
describe: 'include library name in tags and release branches',
type: 'boolean',
default: false,
});
return yargs
.option('monorepo-tags', {
describe: 'include library name in tags and release branches',
type: 'boolean',
default: false,
})
.option('pull-request-title-pattern', {
describe: 'Title pattern to make release PR',
type: 'string',
});
}
const createReleasePullRequestCommand: yargs.CommandModule<
Expand Down
1 change: 1 addition & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export async function buildStrategy(
skipGitHubRelease: options.skipGithubRelease,
releaseAs: options.releaseAs,
includeComponentInTag: options.includeComponentInTag,
pullRequestTitlePattern: options.pullRequestTitlePattern,
};
switch (options.releaseType) {
case 'ruby': {
Expand Down
14 changes: 11 additions & 3 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface ReleaserConfig {
component?: string;
packageName?: string;
includeComponentInTag?: boolean;
pullRequestTitlePattern?: string;

// Ruby-only
versionFile?: string;
Expand Down Expand Up @@ -88,6 +89,7 @@ interface ReleaserConfigJson {
label?: string;
'release-label'?: string;
'include-component-in-tag'?: boolean;
'pull-request-title-pattern'?: string;

// Ruby-only
'version-file'?: string;
Expand Down Expand Up @@ -298,7 +300,8 @@ export class Manifest {
const latestVersion = await latestReleaseVersion(
github,
targetBranch,
config.includeComponentInTag ? component : ''
config.includeComponentInTag ? component : '',
config.pullRequestTitlePattern
);
if (latestVersion) {
releasedVersions[path] = latestVersion;
Expand Down Expand Up @@ -825,6 +828,7 @@ function extractReleaserConfig(config: ReleaserPackageConfig): ReleaserConfig {
versionFile: config['version-file'],
extraFiles: config['extra-files'],
includeComponentInTag: config['include-component-in-tag'],
pullRequestTitlePattern: config['pull-request-title-pattern'],
};
}

Expand Down Expand Up @@ -894,7 +898,8 @@ async function parseReleasedVersions(
async function latestReleaseVersion(
github: GitHub,
targetBranch: string,
prefix?: string
prefix?: string,
pullRequestTitlePattern?: string
): Promise<Version | undefined> {
const branchPrefix = prefix
? prefix.endsWith('-')
Expand Down Expand Up @@ -927,7 +932,10 @@ async function latestReleaseVersion(
continue;
}

const pullRequestTitle = PullRequestTitle.parse(mergedPullRequest.title);
const pullRequestTitle = PullRequestTitle.parse(
mergedPullRequest.title,
pullRequestTitlePattern
);
if (!pullRequestTitle) {
continue;
}
Expand Down
12 changes: 10 additions & 2 deletions src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface StrategyOptions {
releaseAs?: string;
changelogNotes?: ChangelogNotes;
includeComponentInTag?: boolean;
pullRequestTitlePattern?: string;
}

/**
Expand All @@ -80,6 +81,7 @@ export abstract class Strategy {
private skipGitHubRelease: boolean;
private releaseAs?: string;
private includeComponentInTag: boolean;
private pullRequestTitlePattern?: string;

protected changelogNotes: ChangelogNotes;

Expand All @@ -104,6 +106,7 @@ export abstract class Strategy {
this.changelogNotes =
options.changelogNotes || new DefaultChangelogNotes(options);
this.includeComponentInTag = options.includeComponentInTag ?? true;
this.pullRequestTitlePattern = options.pullRequestTitlePattern;
}

/**
Expand Down Expand Up @@ -208,10 +211,12 @@ export abstract class Strategy {
this.includeComponentInTag ? component : undefined,
this.tagSeparator
);
logger.warn('pull request title pattern:', this.pullRequestTitlePattern);
const pullRequestTitle = PullRequestTitle.ofComponentTargetBranchVersion(
component || '',
this.targetBranch,
newVersion
newVersion,
this.pullRequestTitlePattern
);
const branchName = component
? BranchName.ofComponentTargetBranch(component, this.targetBranch)
Expand Down Expand Up @@ -302,7 +307,10 @@ export abstract class Strategy {
}

const pullRequestTitle =
PullRequestTitle.parse(mergedPullRequest.title) ||
PullRequestTitle.parse(
mergedPullRequest.title,
this.pullRequestTitlePattern
) ||
PullRequestTitle.parse(
mergedPullRequest.title,
MANIFEST_PULL_REQUEST_TITLE_PATTERN
Expand Down
91 changes: 90 additions & 1 deletion test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('Manifest', () => {
expect(Object.keys(manifest.repositoryConfig)).lengthOf(1);
expect(Object.keys(manifest.releasedVersions)).lengthOf(1);
});
it('finds previous release without tag', async () => {
it('should find custom release pull request title', async () => {
mockCommits(github, [
{
sha: 'abc123',
Expand All @@ -189,8 +189,37 @@ describe('Manifest', () => {
pullRequest: {
headBranchName: 'release-please/branches/main',
baseBranchName: 'main',
title: 'release: 1.2.3',
number: 123,
body: '',
labels: [],
files: [],
},
},
]);

const manifest = await Manifest.fromConfig(github, 'target-branch', {
releaseType: 'simple',
bumpMinorPreMajor: true,
bumpPatchForMinorPreMajor: true,
pullRequestTitlePattern: 'release: ${version}',
component: 'foobar',
includeComponentInTag: false,
});
expect(Object.keys(manifest.repositoryConfig)).lengthOf(1);
expect(Object.keys(manifest.releasedVersions)).lengthOf(1);
});
it('finds previous release without tag', async () => {
mockCommits(github, [
{
sha: 'abc123',
message: 'some commit message',
files: [],
pullRequest: {
title: 'chore: release 1.2.3',
headBranchName: 'release-please/branches/main',
baseBranchName: 'main',
number: 123,
body: '',
labels: [],
files: [],
Expand Down Expand Up @@ -358,6 +387,26 @@ describe('Manifest', () => {
const pullRequest = pullRequests[0];
expect(pullRequest.labels).to.eql(['some-special-label']);
});

it('allows customizing pull request title', async () => {
const manifest = new Manifest(
github,
'main',
{
'.': {
releaseType: 'simple',
pullRequestTitlePattern: 'release: ${version}',
},
},
{
'.': Version.parse('1.0.0'),
}
);
const pullRequests = await manifest.buildPullRequests();
expect(pullRequests).lengthOf(1);
const pullRequest = pullRequests[0];
expect(pullRequest.title.toString()).to.eql('release: 1.0.1');
});
});

it('should find the component from config', async () => {
Expand Down Expand Up @@ -1968,6 +2017,46 @@ describe('Manifest', () => {
expect(releases).lengthOf(1);
expect(releases[0].tag.toString()).to.eql('v1.3.1');
});

it('should handle customized pull request title', async () => {
mockPullRequests(
github,
[],
[
{
headBranchName: 'release-please/branches/main',
baseBranchName: 'main',
number: 1234,
title: 'release: 3.2.7',
body: pullRequestBody('release-notes/single.txt'),
labels: ['autorelease: pending'],
files: [],
sha: 'abc123',
},
]
);
const manifest = new Manifest(
github,
'main',
{
'.': {
releaseType: 'simple',
pullRequestTitlePattern: 'release: ${version}',
},
},
{
'.': Version.parse('3.2.6'),
}
);
const releases = await manifest.buildReleases();
expect(releases).lengthOf(1);
expect(releases[0].tag.toString()).to.eql('v3.2.7');
expect(releases[0].sha).to.eql('abc123');
expect(releases[0].notes)
.to.be.a('string')
.and.satisfy((msg: string) => msg.startsWith('### [3.2.7]'));
expect(releases[0].path).to.eql('.');
});
});

describe('createReleases', () => {
Expand Down

0 comments on commit 2f3e84c

Please sign in to comment.