Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use project.version instead of tagName for commit messages of version change commits #336

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/groovy/net/researchgate/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
void preTagCommit() {
if (attributes.usesSnapshot || attributes.versionModified || attributes.propertiesFileCreated) {
// should only be committed if the project was using a snapshot version.
def message = extension.preTagCommitMessage + " '${tagName()}'."
def message = extension.preTagCommitMessage + " '" + project.version.toString() + "'."

if (extension.preCommitText) {
message = "${extension.preCommitText} ${message}"
Expand Down Expand Up @@ -299,7 +299,7 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
}

def commitNewVersion() {
def message = extension.newVersionCommitMessage + " '${tagName()}'."
def message = extension.newVersionCommitMessage + " '" + project.version.toString() + "'."
if (extension.preCommitText) {
message = "${extension.preCommitText} ${message}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package net.researchgate.release

import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.revwalk.RevWalk
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder

Expand Down Expand Up @@ -66,4 +68,31 @@ class GitReleasePluginCommitNewVersionTests extends GitSpecification {
remoteGit.repository.workTree.listFiles().any { it.name == 'gradle.properties' && it.text.contains("version=$project.version") }
! remoteGit.repository.workTree.listFiles().any { it.name == 'test.txt' && it.text.contains('testTarget') }
}

def 'should push new version to remote tracking branch with custom commit message as prefix for project version'() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is passing without my change, as tagTemplate's default is '$version'

given:
project.version = "1.2-SNAPSHOT"
project.file('gradle.properties').withWriter { it << "version=${project.version}" }
project.release.newVersionCommitMessage = "New snapshot version:"
when:
project.commitNewVersion.execute()
gitHardReset(remoteGit)
then: 'a commit is pushed with specified commit message prefix + project.version'
RevCommit revCommit = new RevWalk(remoteGit.repository).parseCommit(remoteGit.repository.resolve(Constants.HEAD))
revCommit.getShortMessage().equals("New snapshot version: '1.2-SNAPSHOT'.")
}

def 'it is project.version that is present in commit message, and not tagTemplate'() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing without my change.

given:
project.version = "1.3-SNAPSHOT"
project.file('gradle.properties').withWriter { it << "version=${project.version}" }
project.release.newVersionCommitMessage = "New snapshot version:"
project.release.tagTemplate = 'foo-$version-bar'
when:
project.commitNewVersion.execute()
gitHardReset(remoteGit)
then: 'a commit is pushed with specified commit message prefix + project.version'
RevCommit revCommit = new RevWalk(remoteGit.repository).parseCommit(remoteGit.repository.resolve(Constants.HEAD))
revCommit.getShortMessage().equals("New snapshot version: '1.3-SNAPSHOT'.")
}
}