-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from shipkit/empty-release
Graceful task behavior if there is no previous version
- Loading branch information
Showing
4 changed files
with
69 additions
and
30 deletions.
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
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
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,18 +1,31 @@ | ||
package org.shipkit.changelog; | ||
|
||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
|
||
class GitLogProvider { | ||
|
||
private final static Logger LOG = Logging.getLogger(GitLogProvider.class); | ||
|
||
private final ProcessRunner runner; | ||
|
||
GitLogProvider(ProcessRunner runner) { | ||
this.runner = runner; | ||
} | ||
|
||
public String getLog(String fromRev, String toRev, String format) { | ||
|
||
String getLog(String fromRev, String toRev, String format) { | ||
String fetch = "+refs/tags/" + fromRev + ":refs/tags/" + fromRev; | ||
String log = fromRev + ".." + toRev; | ||
|
||
runner.run("git", "fetch", "origin", fetch); | ||
try { | ||
runner.run("git", "fetch", "origin", fetch); | ||
} catch (Exception e) { | ||
//This is a non blocking problem because we still are able to run git log locally | ||
LOG.info("'git fetch' did not work, continuing running 'git log' locally."); | ||
//To avoid confusion, no stack trace in debug log, just the message: | ||
LOG.debug("'git fetch' problem: {}", e.getMessage()); | ||
} | ||
return runner.run("git", "log", format, log); | ||
} | ||
} |
42 changes: 30 additions & 12 deletions
42
src/test/groovy/org/shipkit/changelog/GitLogProviderTest.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 |
---|---|---|
@@ -1,27 +1,45 @@ | ||
package org.shipkit.changelog | ||
|
||
|
||
import org.junit.Rule | ||
import org.junit.rules.TemporaryFolder | ||
import spock.lang.Specification | ||
|
||
class GitLogProviderTest extends Specification { | ||
|
||
def "smoke test"() { | ||
File rootDir = findRootDir() | ||
def provider = new GitLogProvider(new ProcessRunner(rootDir)) | ||
@Rule TemporaryFolder tmp = new TemporaryFolder() | ||
ProcessRunner runner | ||
GitLogProvider provider | ||
|
||
def setup() { | ||
runner = new ProcessRunner(tmp.root) | ||
|
||
runner.run("git", "init") | ||
runner.run("git", "config", "user.email", "[email protected]") | ||
runner.run("git", "config", "user.name", "Dummy For Testing") | ||
|
||
runner.run("git", "commit", "--allow-empty", "-m", "the initial commit") | ||
runner.run("git", "tag", "v0.0.0") | ||
runner.run("git", "commit", "--allow-empty", "-m", "the second test commit") | ||
runner.run("git", "tag", "v0.0.1") | ||
|
||
provider = new GitLogProvider(runner) | ||
} | ||
|
||
def "smoke test"() { | ||
when: | ||
def log = provider.getLog("v0.0.0", "v0.0.1", "--pretty=short") | ||
|
||
then: | ||
log //TODO add assertions when we have more releases with small amount of commits | ||
!log.contains("the initial commit") | ||
log.contains("the second test commit") | ||
} | ||
|
||
private File findRootDir() { | ||
def testDir = new File(".") | ||
while (!new File(testDir, ".git").directory && testDir != null) { | ||
testDir = testDir.parentFile | ||
} | ||
assert testDir != null | ||
testDir | ||
def "no previous revision"() { | ||
//this is the "first release" use case | ||
when: | ||
def log = provider.getLog("HEAD", "v0.0.1", "--pretty=short") | ||
|
||
then: | ||
log == "" | ||
} | ||
} |