This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
[SHIPKIT-513] Automated commit message should have CI build ID #709
Open
ArturSkowronski
wants to merge
5
commits into
master
Choose a base branch
from
SHIPKIT-513-new-version
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e18084c
[SHIPKIT-513] Basic version
ArturSkowronski 4890e47
[SHIPKIT-513] Renaming of methods
ArturSkowronski 30be329
Refactor of Commit Message Utils
ArturSkowronski 354834e
[SHIPKIT-513] Fix for restories system properties
ArturSkowronski bf77c9f
[SHIPKIT-513] Decoupling message from Git Plugin
ArturSkowronski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,10 @@ | |
import java.io.File; | ||
import java.util.List; | ||
|
||
import static java.lang.System.getProperty; | ||
import static org.shipkit.internal.gradle.exec.ExecCommandFactory.execCommand; | ||
import static org.shipkit.internal.gradle.util.GitUtil.getTag; | ||
import static org.shipkit.internal.gradle.util.CommitMessageUtils.generateCommitMessagePostfix; | ||
|
||
/** | ||
* Adds Git-specific tasks needed for the release process. | ||
|
@@ -55,13 +57,15 @@ public class GitPlugin implements Plugin<Project> { | |
|
||
public void apply(final Project project) { | ||
final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration(); | ||
String commitMessage = generateCommitMessagePostfix(conf, getProperty("TRAVIS_BUILD_NUMBER")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GitPlugin should be decoupled from Travis, so that we can use it for Circle CI, etc. Take a look at #514 - we're adding new code to TravisPlugin. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I exposed it to CommitMessageUtil but using Travis Plugin for that seems to be really better way |
||
|
||
TaskMaker.task(project, GIT_COMMIT_TASK, GitCommitTask.class, new Action<GitCommitTask>() { | ||
public void execute(final GitCommitTask t) { | ||
t.setDescription("Commits all changed files using generic --author and aggregated commit message"); | ||
t.setGitUserName(conf.getGit().getUser()); | ||
t.setGitUserEmail(conf.getGit().getEmail()); | ||
t.setCommitMessagePostfix(conf.getGit().getCommitMessagePostfix()); | ||
t.setCommitMessagePostfix(commitMessage); | ||
|
||
} | ||
}); | ||
|
||
|
24 changes: 24 additions & 0 deletions
24
subprojects/shipkit/src/main/groovy/org/shipkit/internal/gradle/util/CommitMessageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.shipkit.internal.gradle.util; | ||
|
||
import org.shipkit.gradle.configuration.ShipkitConfiguration; | ||
|
||
public class CommitMessageUtils { | ||
private static final String URL_PATTERN = "https://travis-ci.org/%s/builds/%s"; | ||
|
||
public static String generateCommitMessagePostfix(ShipkitConfiguration conf, String travisBuildNumber) { | ||
if (!StringUtil.isEmpty(travisBuildNumber)) { | ||
return getTravisCommitMessagePostfix(conf, travisBuildNumber); | ||
} | ||
|
||
return conf.getGit().getCommitMessagePostfix(); | ||
} | ||
|
||
private static String getTravisCommitMessagePostfix(ShipkitConfiguration conf, String travisBuildNumber) { | ||
String travisJobUrl = generateTravisBuildUrl(conf, travisBuildNumber); | ||
return String.format("CI job: %s %s", travisJobUrl, conf.getGit().getCommitMessagePostfix()); | ||
} | ||
|
||
private static String generateTravisBuildUrl(ShipkitConfiguration conf, String travisBuildNumber) { | ||
return String.format(URL_PATTERN, conf.getGitHub().getRepository(), travisBuildNumber); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.shipkit.internal.gradle.git | ||
|
||
import org.shipkit.gradle.git.GitCommitTask | ||
import org.shipkit.gradle.git.GitPushTask | ||
import testutil.PluginSpecification | ||
|
||
|
@@ -22,4 +23,28 @@ class GitPluginTest extends PluginSpecification { | |
gitPush.url == "https://dummy:[email protected]/my-repo.git" | ||
gitPush.secretValue == "foo" | ||
} | ||
|
||
def "configures git commit"() { | ||
conf.gitHub.repository = 'my-repo' | ||
conf.gitHub.writeAuthToken = 'foo' | ||
|
||
when: | ||
project.plugins.apply(GitPlugin) | ||
|
||
then: | ||
GitCommitTask gitCommit = project.tasks[GitPlugin.GIT_COMMIT_TASK] | ||
gitCommit.commitMessagePostfix == "[ci skip]" | ||
} | ||
|
||
def "configures git commit in Travis environment"() { | ||
conf.gitHub.repository = 'my-repo' | ||
conf.gitHub.writeAuthToken = 'foo' | ||
System.setProperty("TRAVIS_BUILD_NUMBER", "test") | ||
when: | ||
project.plugins.apply(GitPlugin) | ||
|
||
then: | ||
GitCommitTask gitCommit = project.tasks[GitPlugin.GIT_COMMIT_TASK] | ||
gitCommit.commitMessagePostfix == "CI job: https://travis-ci.org/my-repo/builds/test [ci skip]" | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ts/shipkit/src/test/groovy/org/shipkit/internal/gradle/util/CommitMessageUtilsTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.shipkit.internal.gradle.util | ||
|
||
import spock.lang.Specification | ||
|
||
import org.shipkit.gradle.configuration.ShipkitConfiguration | ||
|
||
class CommitMessageUtilsTest extends Specification { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test coverage! Thanks! |
||
|
||
def "should build travis url with [ci skip]"() { | ||
given: | ||
ShipkitConfiguration shipkitConfiguration = Mock(ShipkitConfiguration) | ||
ShipkitConfiguration.GitHub gitHub = Mock(ShipkitConfiguration.GitHub) | ||
ShipkitConfiguration.Git git = Mock(ShipkitConfiguration.Git) | ||
shipkitConfiguration.getGitHub() >> gitHub | ||
shipkitConfiguration.getGit() >> git | ||
1 * git.commitMessagePostfix >> "[ci skip]" | ||
1 * gitHub.getRepository() >> "mockito/shipkit" | ||
0 * _ | ||
when: | ||
def url = CommitMessageUtils.generateCommitMessagePostfix(shipkitConfiguration, "123") | ||
then: | ||
url == "CI job: https://travis-ci.org/mockito/shipkit/builds/123 [ci skip]" | ||
} | ||
|
||
def "should build postfix without travis url if blank build number"() { | ||
given: | ||
ShipkitConfiguration shipkitConfiguration = Mock(ShipkitConfiguration) | ||
ShipkitConfiguration.GitHub gitHub = Mock(ShipkitConfiguration.GitHub) | ||
ShipkitConfiguration.Git git = Mock(ShipkitConfiguration.Git) | ||
shipkitConfiguration.getGitHub() >> gitHub | ||
shipkitConfiguration.getGit() >> git | ||
|
||
1 * git.commitMessagePostfix >> "[ci skip]" | ||
0 * _ | ||
when: | ||
def url = CommitMessageUtils.generateCommitMessagePostfix(shipkitConfiguration, "") | ||
then: | ||
url == "[ci skip]" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis exports env variables rather than system properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Thanks