Skip to content

Commit cc24683

Browse files
Add 'pr-message-template' input to allow setting custom PR message (gradle-update#886)
* Add 'pr-message-template' input to allow setting custom PR message Allow setting custom PR message. Fixes gradle-update#495 * update README * refactor messages
1 parent ae11fbd commit cc24683

File tree

11 files changed

+180
-96
lines changed

11 files changed

+180
-96
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Request](https://user-images.githubusercontent.com/316923/93274006-8922ef80-f7b9
3232
- [`release-channel`](#release-channel)
3333
- [`merge-method`](#merge-method)
3434
- [`pr-title-template`](#pr-title-template)
35+
- [`pr-message-template`](#pr-message-template)
3536
- [`commit-message-template`](#commit-message-template)
3637
- [Examples](#examples)
3738
- [Scheduling action execution](#scheduling-action-execution)
@@ -144,8 +145,12 @@ This is the list of supported inputs:
144145
| [`paths`](#paths) | List of paths where to search for Gradle Wrapper files (comma or newline-separated). | No | (empty) |
145146
| [`paths-ignore`](#paths-ignore) | List of paths to be excluded when searching for Gradle Wrapper files (comma or newline-separated). | No | (empty) |
146147
| [`set-distribution-checksum`](#set-distribution-checksum) | Whether to set the `distributionSha256Sum` property. | No | `true` |
148+
| [`distributions-base-url`](#distributions-base-url) | Set a custom url to download the Gradle Wrapper zip file from. | No | (empty) |
147149
| [`release-channel`](#release-channel) | Which Gradle release channel to use: either `stable` or `release-candidate`. | No | `stable` |
148150
| [`merge-method`](#merge-method) | Which merge method to use for [auto-merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request). Valid values include `MERGE`, `REBASE`, or `SQUASH`. If unset, automerge will not be enabled on opened PRs. | No | (unset) No auto-merge |
151+
| [`pr-title-template`](#pr-title-template) | The template to use for the title of the pull request created by this action | No | `Update Gradle Wrapper from %sourceVersion% to %targetVersion%` |
152+
| [`pr-message-template`](#pr-message-template) | The template to use for the description of the pull request created by this action | No | (empty) |
153+
| [`commit-message-template`](#commit-message-template) | The template to use for the commit message created by this action | No | `Update Gradle Wrapper from %sourceVersion% to %targetVersion%` |
149154

150155
---
151156

@@ -429,6 +434,9 @@ For example:
429434
with:
430435
release-channel: release-candidate
431436
```
437+
438+
---
439+
432440
### `merge-method`
433441

434442
| Name | Description | Required | Default |
@@ -443,6 +451,9 @@ For example:
443451
with:
444452
merge-method: SQUASH
445453
```
454+
455+
---
456+
446457
### `pr-title-template`
447458

448459
| Name | Description | Required | Default |
@@ -462,6 +473,29 @@ with:
462473
pr-title-template: 'chore(deps): Bump Gradle Wrapper from %sourceVersion% to %targetVersion%'
463474
```
464475

476+
---
477+
478+
### `pr-message-template`
479+
480+
| Name | Description | Required | Default |
481+
| --- | --- | --- | --- |
482+
| `pr-message-template` | The template to use for the description of the pull request created by this action | No | (empty) |
483+
484+
This input is used for the description of the pull request created by this action.
485+
486+
`%sourceVersion%` and `%targetVersion%` will be replaced by the current/old and the new version of the Gradle Wrapper respectively.
487+
488+
There are cases in which the source version of the Gradle Wrapper can not be determined successfully. In such cases, the string `undefined` will be used to replace the source version placeholder.
489+
490+
For example:
491+
492+
```yaml
493+
with:
494+
pr-message-template: 'Upgrading the Gradle Wrapper from version %sourceVersion% to %targetVersion%.'
495+
```
496+
497+
---
498+
465499
### `commit-message-template`
466500

467501
| Name | Description | Required | Default |

action.yml

+13-2
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,26 @@ inputs:
5454
required: false
5555
pr-title-template:
5656
description: |
57-
Template used for PR title.
57+
Template used for PR title. Use %sourceVersion% and %targetVersion% to
58+
refer to the source and target versions of the Gradle Wrapper.
5859
There are cases in which the source version of the Gradle Wrapper can not
5960
be determined successfully. In such cases, the string 'undefined' will be
6061
used to replace the source version placeholder.
6162
required: false
6263
default: 'Update Gradle Wrapper from %sourceVersion% to %targetVersion%'
64+
pr-message-template:
65+
description: |
66+
Template used for PR description. Use %sourceVersion% and %targetVersion%
67+
to refer to the source and target versions of the Gradle Wrapper.
68+
There are cases in which the source version of the Gradle Wrapper can not
69+
be determined successfully. In such cases, the string 'undefined' will be
70+
used to replace the source version placeholder.
71+
required: false
72+
default: ''
6373
commit-message-template:
6474
description: |
65-
Template used for commit message.
75+
Template used for commit message. Use %sourceVersion% and %targetVersion%
76+
to refer to the source and target versions of the Gradle Wrapper.
6677
There are cases in which the source version of the Gradle Wrapper can not
6778
be determined successfully. In such cases, the string 'undefined' will be
6879
used to replace the source version placeholder.

dist/index.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,20 @@ class GitHubOps {
727727
return;
728728
});
729729
}
730-
createPullRequest(branchName, prTitleTemplate, distTypes, targetRelease, sourceVersion) {
730+
createPullRequest(branchName, distTypes, targetRelease, sourceVersion) {
731731
return __awaiter(this, void 0, void 0, function* () {
732732
const targetBranch = this.inputs.targetBranch !== ''
733733
? this.inputs.targetBranch
734734
: yield this.api.repoDefaultBranch();
735735
core.debug(`Target branch: ${targetBranch}`);
736-
const { title, body } = (0, messages_1.pullRequestText)(prTitleTemplate, distTypes, targetRelease, sourceVersion);
736+
let title, body;
737+
if (this.inputs.prMessageTemplate) {
738+
title = (0, messages_1.replaceVersionPlaceholders)(this.inputs.prTitleTemplate, sourceVersion, targetRelease.version);
739+
body = (0, messages_1.replaceVersionPlaceholders)(this.inputs.prMessageTemplate, sourceVersion, targetRelease.version);
740+
}
741+
else {
742+
({ title, body } = (0, messages_1.pullRequestText)(this.inputs.prTitleTemplate, distTypes, targetRelease, sourceVersion));
743+
}
737744
const pullRequest = yield this.api.createPullRequest({
738745
branchName: `refs/heads/${branchName}`,
739746
target: targetBranch,
@@ -931,6 +938,12 @@ class ActionInputs {
931938
this.prTitleTemplate =
932939
'Update Gradle Wrapper from %sourceVersion% to %targetVersion%';
933940
}
941+
this.prMessageTemplate = core
942+
.getInput('pr-message-template', { required: false })
943+
.trim();
944+
if (!this.prMessageTemplate) {
945+
this.prMessageTemplate = '';
946+
}
934947
this.commitMessageTemplate = core
935948
.getInput('commit-message-template', { required: false })
936949
.trim();
@@ -950,25 +963,19 @@ class ActionInputs {
950963
"use strict";
951964

952965
Object.defineProperty(exports, "__esModule", ({ value: true }));
953-
exports.pullRequestTitle = pullRequestTitle;
954-
exports.commitMessageText = commitMessageText;
966+
exports.replaceVersionPlaceholders = replaceVersionPlaceholders;
955967
exports.pullRequestText = pullRequestText;
956968
const ISSUES_URL = 'https://github.com/gradle-update/update-gradle-wrapper-action/issues';
957969
const TARGET_VERSION_PLACEHOLDER = '%targetVersion%';
958970
const SOURCE_VERSION_PLACEHOLDER = '%sourceVersion%';
959-
function pullRequestTitle(template, sourceVersion, targetVersion) {
971+
function replaceVersionPlaceholders(template, sourceVersion, targetVersion) {
960972
return template
961973
.replace(TARGET_VERSION_PLACEHOLDER, targetVersion)
962974
.replace(SOURCE_VERSION_PLACEHOLDER, sourceVersion !== null && sourceVersion !== void 0 ? sourceVersion : 'undefined');
963975
}
964-
function commitMessageText(template, source, target) {
965-
return template
966-
.replace(TARGET_VERSION_PLACEHOLDER, target)
967-
.replace(SOURCE_VERSION_PLACEHOLDER, source ? source : 'undefined');
968-
}
969976
function pullRequestText(prTitleTemplate, distTypes, targetRelease, sourceVersion) {
970977
const targetVersion = targetRelease.version;
971-
const title = pullRequestTitle(prTitleTemplate, sourceVersion, targetVersion);
978+
const title = replaceVersionPlaceholders(prTitleTemplate, sourceVersion, targetVersion);
972979
const bodyHeader = `${title}.
973980

974981
Read the release notes: https://docs.gradle.org/${targetVersion}/release-notes.html`;
@@ -1323,7 +1330,7 @@ class MainAction {
13231330
yield updater.verify();
13241331
core.endGroup();
13251332
core.startGroup('Committing');
1326-
const commitMessage = (0, messages_1.commitMessageText)(this.inputs.commitMessageTemplate, wrapper.version, targetRelease.version);
1333+
const commitMessage = (0, messages_1.replaceVersionPlaceholders)(this.inputs.commitMessageTemplate, wrapper.version, targetRelease.version);
13271334
yield (0, git_commit_1.commit)(modifiedFiles, commitMessage);
13281335
core.endGroup();
13291336
commitDataList.push({
@@ -1348,7 +1355,7 @@ class MainAction {
13481355
core.info('Pushing branch');
13491356
yield git.push(branchName);
13501357
core.info('Creating Pull Request');
1351-
const pullRequestData = yield this.githubOps.createPullRequest(branchName, this.inputs.prTitleTemplate, distTypes, targetRelease, commitDataList.length === 1
1358+
const pullRequestData = yield this.githubOps.createPullRequest(branchName, distTypes, targetRelease, commitDataList.length === 1
13521359
? commitDataList[0].sourceVersion
13531360
: undefined);
13541361
core.info(`✅ Created a Pull Request at ${pullRequestData.url} ✨`);

src/github/gh-ops.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {context, getOctokit} from '@actions/github';
1919

2020
import {Inputs} from '../inputs';
2121
import {PullRequestData} from '../store';
22-
import {pullRequestText} from '../messages';
22+
import {replaceVersionPlaceholders, pullRequestText} from '../messages';
2323
import {Release} from '../releases';
2424
import {GitHubApi, IGitHubApi} from './gh-api';
2525

@@ -61,7 +61,6 @@ export class GitHubOps {
6161

6262
async createPullRequest(
6363
branchName: string,
64-
prTitleTemplate: string,
6564
distTypes: Set<string>,
6665
targetRelease: Release,
6766
sourceVersion?: string
@@ -73,12 +72,27 @@ export class GitHubOps {
7372

7473
core.debug(`Target branch: ${targetBranch}`);
7574

76-
const {title, body} = pullRequestText(
77-
prTitleTemplate,
78-
distTypes,
79-
targetRelease,
80-
sourceVersion
81-
);
75+
let title, body;
76+
77+
if (this.inputs.prMessageTemplate) {
78+
title = replaceVersionPlaceholders(
79+
this.inputs.prTitleTemplate,
80+
sourceVersion,
81+
targetRelease.version
82+
);
83+
body = replaceVersionPlaceholders(
84+
this.inputs.prMessageTemplate,
85+
sourceVersion,
86+
targetRelease.version
87+
);
88+
} else {
89+
({title, body} = pullRequestText(
90+
this.inputs.prTitleTemplate,
91+
distTypes,
92+
targetRelease,
93+
sourceVersion
94+
));
95+
}
8296

8397
const pullRequest = await this.api.createPullRequest({
8498
branchName: `refs/heads/${branchName}`,

src/inputs/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface Inputs {
2828
releaseChannel: string;
2929
mergeMethod: string | undefined;
3030
prTitleTemplate: string;
31+
prMessageTemplate: string;
3132
commitMessageTemplate: string;
3233
}
3334

@@ -51,6 +52,7 @@ class ActionInputs implements Inputs {
5152
releaseChannel: string;
5253
mergeMethod: string | undefined;
5354
prTitleTemplate: string;
55+
prMessageTemplate: string;
5456
commitMessageTemplate: string;
5557

5658
constructor() {
@@ -127,6 +129,13 @@ class ActionInputs implements Inputs {
127129
'Update Gradle Wrapper from %sourceVersion% to %targetVersion%';
128130
}
129131

132+
this.prMessageTemplate = core
133+
.getInput('pr-message-template', {required: false})
134+
.trim();
135+
if (!this.prMessageTemplate) {
136+
this.prMessageTemplate = '';
137+
}
138+
130139
this.commitMessageTemplate = core
131140
.getInput('commit-message-template', {required: false})
132141
.trim();

src/messages.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,28 @@ const ISSUES_URL =
2020
const TARGET_VERSION_PLACEHOLDER = '%targetVersion%';
2121
const SOURCE_VERSION_PLACEHOLDER = '%sourceVersion%';
2222

23-
export function pullRequestTitle(
23+
export function replaceVersionPlaceholders(
2424
template: string,
2525
sourceVersion: string | undefined,
2626
targetVersion: string
27-
) {
27+
): string {
2828
return template
2929
.replace(TARGET_VERSION_PLACEHOLDER, targetVersion)
3030
.replace(SOURCE_VERSION_PLACEHOLDER, sourceVersion ?? 'undefined');
3131
}
3232

33-
export function commitMessageText(
34-
template: string,
35-
source: string | undefined,
36-
target: string
37-
): string {
38-
return template
39-
.replace(TARGET_VERSION_PLACEHOLDER, target)
40-
.replace(SOURCE_VERSION_PLACEHOLDER, source ? source : 'undefined');
41-
}
42-
4333
export function pullRequestText(
4434
prTitleTemplate: string,
4535
distTypes: Set<string>,
4636
targetRelease: Release,
4737
sourceVersion?: string
4838
): {title: string; body: string} {
4939
const targetVersion = targetRelease.version;
50-
const title = pullRequestTitle(prTitleTemplate, sourceVersion, targetVersion);
40+
const title = replaceVersionPlaceholders(
41+
prTitleTemplate,
42+
sourceVersion,
43+
targetVersion
44+
);
5145
const bodyHeader = `${title}.
5246
5347
Read the release notes: https://docs.gradle.org/${targetVersion}/release-notes.html`;

src/tasks/main.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as gitAuth from '../git/git-auth';
1919
import * as store from '../store';
2020

2121
import {commit} from '../git/git-commit';
22-
import {commitMessageText} from '../messages';
22+
import {replaceVersionPlaceholders} from '../messages';
2323
import {createWrapperInfo} from '../wrapperInfo';
2424
import {createWrapperUpdater} from '../wrapperUpdater';
2525
import {findWrapperPropertiesFiles} from '../wrapper/find';
@@ -162,7 +162,7 @@ export class MainAction {
162162

163163
core.startGroup('Committing');
164164

165-
const commitMessage = commitMessageText(
165+
const commitMessage = replaceVersionPlaceholders(
166166
this.inputs.commitMessageTemplate,
167167
wrapper.version,
168168
targetRelease.version
@@ -202,7 +202,6 @@ export class MainAction {
202202
core.info('Creating Pull Request');
203203
const pullRequestData = await this.githubOps.createPullRequest(
204204
branchName,
205-
this.inputs.prTitleTemplate,
206205
distTypes,
207206
targetRelease,
208207
commitDataList.length === 1

0 commit comments

Comments
 (0)