diff --git a/README.md b/README.md index 394e32a2..6b35bded 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Request](https://user-images.githubusercontent.com/316923/93274006-8922ef80-f7b9 - [`set-distribution-checksum`](#set-distribution-checksum) - [`release-channel`](#release-channel) - [`merge-method`](#merge-method) + - [`commit-message-template`](#commit-message-template) - [Examples](#examples) - [Scheduling action execution](#scheduling-action-execution) - [Targeting a custom branch](#targeting-a-custom-branch) @@ -424,6 +425,25 @@ with: merge-method: SQUASH ``` +### `commit-message-template` + +| Name | Description | Required | Default | +| --- | --- | --- | --- | +| `commit-message-template` | The template to use for the commit message created by this action | No | `Update Gradle Wrapper from %sourceVersion% to %targetVersion%` | + +This input is used for the message of the commit created by this action. This allows for better integration into +repositories which make use of commit message patterns like [Conventional Commits](https://www.conventionalcommits.org/). + +`%sourceVersion%` and `%targetVersion%` will be replaced by the current/old and the new version of the Gradle Wrapper +respectively. + +For example: + +```yaml +with: + commit-message-template: 'chore(deps): Bump Gradle Wrapper from %sourceVersion% to %targetVersion%' +``` + ## Examples ### Scheduling action execution diff --git a/action.yml b/action.yml index 1359e3c3..fb232946 100644 --- a/action.yml +++ b/action.yml @@ -48,6 +48,10 @@ inputs: merge-method: description: 'Which merge method to use for auto-merge (either `MERGE`, `REBASE`, or `SQUASH`). If unset, auto-merge will not be enabled on opened PRs.' required: false + commit-message-template: + description: 'Template used for commit message' + required: false + default: 'Update Gradle Wrapper from %sourceVersion% to %targetVersion%' runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index 62072b5f..a1ed3ad0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -280,10 +280,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", ({ value: true })); exports.commit = void 0; const git = __importStar(__nccwpck_require__(8940)); -function commit(files, targetVersion, sourceVersion) { +function commit(files, commitMessage) { return __awaiter(this, void 0, void 0, function* () { yield git.add(files); - yield git.commit(`Update Gradle Wrapper from ${sourceVersion} to ${targetVersion}.`); + yield git.commit(commitMessage); }); } exports.commit = commit; @@ -846,6 +846,13 @@ class ActionInputs { if (!this.mergeMethod) { this.mergeMethod = undefined; } + this.commitMessageTemplate = core + .getInput('commit-message-template', { required: false }) + .trim(); + if (!this.commitMessageTemplate) { + this.commitMessageTemplate = + 'Update Gradle Wrapper from %sourceVersion% to %targetVersion%'; + } } } @@ -858,8 +865,16 @@ class ActionInputs { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.pullRequestText = void 0; +exports.pullRequestText = exports.commitMessageText = void 0; const ISSUES_URL = 'https://github.com/gradle-update/update-gradle-wrapper-action/issues'; +const TARGET_VERSION_PLACEHOLDER = '%targetVersion%'; +const SOURCE_VERSION_PLACEHOLDER = '%sourceVersion%'; +function commitMessageText(template, source, target) { + return template + .replace(TARGET_VERSION_PLACEHOLDER, target) + .replace(SOURCE_VERSION_PLACEHOLDER, source); +} +exports.commitMessageText = commitMessageText; function pullRequestText(distTypes, targetRelease, sourceVersion) { const targetVersion = targetRelease.version; const title = sourceVersion @@ -1112,6 +1127,7 @@ const git = __importStar(__nccwpck_require__(8940)); const gitAuth = __importStar(__nccwpck_require__(1304)); const store = __importStar(__nccwpck_require__(5826)); const git_commit_1 = __nccwpck_require__(4779); +const messages_1 = __nccwpck_require__(9112); const wrapperInfo_1 = __nccwpck_require__(6832); const wrapperUpdater_1 = __nccwpck_require__(7412); const find_1 = __nccwpck_require__(2758); @@ -1190,7 +1206,8 @@ class MainAction { yield updater.verify(); core.endGroup(); core.startGroup('Committing'); - yield (0, git_commit_1.commit)(modifiedFiles, targetRelease.version, wrapper.version); + const commitMessage = (0, messages_1.commitMessageText)(this.inputs.commitMessageTemplate, wrapper.version, targetRelease.version); + yield (0, git_commit_1.commit)(modifiedFiles, commitMessage); core.endGroup(); commitDataList.push({ files: modifiedFiles, diff --git a/src/git/git-commit.ts b/src/git/git-commit.ts index 2d2b0d36..01306cbc 100644 --- a/src/git/git-commit.ts +++ b/src/git/git-commit.ts @@ -14,13 +14,7 @@ import * as git from './git-cmds'; -export async function commit( - files: string[], - targetVersion: string, - sourceVersion: string -) { +export async function commit(files: string[], commitMessage: string) { await git.add(files); - await git.commit( - `Update Gradle Wrapper from ${sourceVersion} to ${targetVersion}.` - ); + await git.commit(commitMessage); } diff --git a/src/inputs/index.ts b/src/inputs/index.ts index 5aa1f636..d0d6c4b4 100644 --- a/src/inputs/index.ts +++ b/src/inputs/index.ts @@ -26,6 +26,7 @@ export interface Inputs { pathsIgnore: string[]; releaseChannel: string; mergeMethod: string | undefined; + commitMessageTemplate: string; } export function getInputs(): Inputs { @@ -46,6 +47,7 @@ class ActionInputs implements Inputs { pathsIgnore: string[]; releaseChannel: string; mergeMethod: string | undefined; + commitMessageTemplate: string; constructor() { this.repoToken = core.getInput('repo-token', {required: false}); @@ -107,5 +109,13 @@ class ActionInputs implements Inputs { if (!this.mergeMethod) { this.mergeMethod = undefined; } + + this.commitMessageTemplate = core + .getInput('commit-message-template', {required: false}) + .trim(); + if (!this.commitMessageTemplate) { + this.commitMessageTemplate = + 'Update Gradle Wrapper from %sourceVersion% to %targetVersion%'; + } } } diff --git a/src/messages.ts b/src/messages.ts index 7d10fd5f..8b2da529 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -17,6 +17,19 @@ import {Release} from './releases'; const ISSUES_URL = 'https://github.com/gradle-update/update-gradle-wrapper-action/issues'; +const TARGET_VERSION_PLACEHOLDER = '%targetVersion%'; +const SOURCE_VERSION_PLACEHOLDER = '%sourceVersion%'; + +export function commitMessageText( + template: string, + source: string, + target: string +): string { + return template + .replace(TARGET_VERSION_PLACEHOLDER, target) + .replace(SOURCE_VERSION_PLACEHOLDER, source); +} + export function pullRequestText( distTypes: Set, targetRelease: Release, diff --git a/src/tasks/main.ts b/src/tasks/main.ts index e4ceea86..8e5cd759 100644 --- a/src/tasks/main.ts +++ b/src/tasks/main.ts @@ -19,6 +19,7 @@ import * as gitAuth from '../git/git-auth'; import * as store from '../store'; import {commit} from '../git/git-commit'; +import {commitMessageText} from '../messages'; import {createWrapperInfo} from '../wrapperInfo'; import {createWrapperUpdater} from '../wrapperUpdater'; import {findWrapperPropertiesFiles} from '../wrapper/find'; @@ -160,7 +161,13 @@ export class MainAction { core.endGroup(); core.startGroup('Committing'); - await commit(modifiedFiles, targetRelease.version, wrapper.version); + + const commitMessage = commitMessageText( + this.inputs.commitMessageTemplate, + wrapper.version, + targetRelease.version + ); + await commit(modifiedFiles, commitMessage); core.endGroup(); commitDataList.push({ diff --git a/tests/github/gh-ops.test.ts b/tests/github/gh-ops.test.ts index 2e3a871f..688f1133 100644 --- a/tests/github/gh-ops.test.ts +++ b/tests/github/gh-ops.test.ts @@ -36,7 +36,9 @@ const defaultMockInputs: Inputs = { paths: [], pathsIgnore: [], releaseChannel: '', - mergeMethod: undefined + mergeMethod: undefined, + commitMessageTemplate: + 'Update Gradle Wrapper from %sourceVersion% to %targetVersion%' }; const defaultMockGitHubApi: IGitHubApi = { diff --git a/tests/inputs/inputs.test.ts b/tests/inputs/inputs.test.ts index a62a8969..d278ae77 100644 --- a/tests/inputs/inputs.test.ts +++ b/tests/inputs/inputs.test.ts @@ -15,6 +15,7 @@ import * as core from '@actions/core'; import {getInputs} from '../../src/inputs'; + jest.mock('@actions/core'); describe('getInputs', () => { @@ -44,6 +45,7 @@ describe('getInputs', () => { expect(getInputs()).toMatchInlineSnapshot(` ActionInputs { "baseBranch": "", + "commitMessageTemplate": "Update Gradle Wrapper from %sourceVersion% to %targetVersion%", "labels": Array [], "mergeMethod": undefined, "paths": Array [], @@ -190,6 +192,30 @@ describe('getInputs', () => { }); }); + describe('commitMessageTemplate', () => { + it('defaults to "Update Gradle Wrapper from %sourceVersion% to %targetVersion%"', () => { + ymlInputs = { + 'repo-token': 's3cr3t' + }; + + expect(getInputs().commitMessageTemplate).toStrictEqual( + 'Update Gradle Wrapper from %sourceVersion% to %targetVersion%' + ); + }); + + it('is set to the input string value', () => { + ymlInputs = { + 'repo-token': 's3cr3t', + 'commit-message-template': + 'Change wrapper from %sourceVersion% to %targetVersion%' + }; + + expect(getInputs().commitMessageTemplate).toStrictEqual( + 'Change wrapper from %sourceVersion% to %targetVersion%' + ); + }); + }); + describe('releaseChannel', () => { it('defaults to stable channel', () => { ymlInputs = { diff --git a/tests/messages.test.ts b/tests/messages.test.ts index 007200b7..acce330a 100644 --- a/tests/messages.test.ts +++ b/tests/messages.test.ts @@ -12,8 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {pullRequestText} from '../src/messages'; import {Release} from '../src/releases'; +import {commitMessageText, pullRequestText} from '../src/messages'; + +describe('commitMessageText', () => { + it('replaces %sourceVersion% with the source version parameter', () => { + const message = commitMessageText( + 'Update from %sourceVersion%', + '1.0.0', + '1.0.1' + ); + expect(message).toEqual('Update from 1.0.0'); + }); + + it('replaces %targetVersion% with the source version parameter', () => { + const message = commitMessageText( + 'Update to %targetVersion%', + '1.0.0', + '1.0.1' + ); + expect(message).toEqual('Update to 1.0.1'); + }); + + it('replaces both placeholders', () => { + const message = commitMessageText( + 'Update from %sourceVersion% to %targetVersion%', + '1.0.0', + '1.0.1' + ); + expect(message).toEqual('Update from 1.0.0 to 1.0.1'); + }); +}); describe('pullRequestText', () => { const distributionTypes = new Set(['all', 'bin']); diff --git a/tests/tasks/main.test.ts b/tests/tasks/main.test.ts index 89fefaaf..7fef9125 100644 --- a/tests/tasks/main.test.ts +++ b/tests/tasks/main.test.ts @@ -43,7 +43,9 @@ const defaultMockInputs: Inputs = { paths: [], pathsIgnore: [], releaseChannel: '', - mergeMethod: undefined + mergeMethod: undefined, + commitMessageTemplate: + 'Update Gradle Wrapper from %sourceVersion% to %targetVersion%' }; const defaultMockGitHubApi: IGitHubApi = { @@ -152,8 +154,7 @@ describe('run', () => { '/path/to/gradle/wrapper/gradle-wrapper.properties', '/path/to/gradle/wrapper/gradle-wrapper.jar' ], - '1.0.1', - '1.0.0' + 'Update Gradle Wrapper from 1.0.0 to 1.0.1' ); expect(git.push).toHaveBeenCalledWith('gradlew-update-1.0.1');