-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* provide standard labels for Docker image #1 * perform docker login only if username is provided * show exceptions from tests * try to fix test failing on TravisCI * disable problematic assertions * different test of docker inspect output * intentialy break the test * fix the test * more stable tests * test the GitExecutor
- Loading branch information
Showing
8 changed files
with
170 additions
and
9 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
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
56 changes: 56 additions & 0 deletions
56
src/main/groovy/cz/augi/gradle/dockerjava/GitExecutor.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,56 @@ | ||
package cz.augi.gradle.dockerjava | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.logging.Logger | ||
import org.gradle.platform.base.Platform | ||
import org.gradle.process.ExecSpec | ||
|
||
class GitExecutor { | ||
private final Project project | ||
private final Logger logger | ||
|
||
GitExecutor(Project project) { | ||
this.project = project | ||
this.logger = project.logger | ||
} | ||
|
||
String execute(String... args) { | ||
new ByteArrayOutputStream().withStream { os -> | ||
project.exec { ExecSpec e -> | ||
def finalArgs = ['git'] | ||
finalArgs.addAll(args) | ||
e.commandLine finalArgs | ||
e.standardOutput os | ||
} | ||
os.toString().trim() | ||
} | ||
} | ||
|
||
String getUrl() { | ||
try { | ||
def remoteName = execute('remote').readLines().find() | ||
remoteName ? execute('remote', 'get-url', remoteName) : null | ||
} catch (RuntimeException e) { | ||
logger.debug("Cannot get Git remote url: ${e.message}", e) | ||
null | ||
} | ||
} | ||
|
||
String getRef() { | ||
try { | ||
execute('rev-parse', 'HEAD') | ||
} catch (RuntimeException e) { | ||
logger.debug("Cannot get Git revision: ${e.message}", e) | ||
null | ||
} | ||
} | ||
|
||
String getBranch() { | ||
try { | ||
execute('rev-parse', '--abbrev-ref', 'HEAD') | ||
} catch (RuntimeException e) { | ||
logger.debug("Cannot get Git revision: ${e.message}", e) | ||
null | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/test/groovy/cz/augi/gradle/dockerjava/GitExecutorTest.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,27 @@ | ||
package cz.augi.gradle.dockerjava | ||
|
||
import org.gradle.testfixtures.ProjectBuilder | ||
import spock.lang.Specification | ||
|
||
class GitExecutorTest extends Specification { | ||
def "reads url, ref and branch"() { | ||
def project = ProjectBuilder.builder().build() | ||
def target = new GitExecutor(project) | ||
target.execute('init') | ||
project.file('file.txt') << 'content' | ||
target.execute('checkout', '-b', 'master') | ||
target.execute('add', '.') | ||
target.execute('commit', '-m', 'first commit') | ||
target.execute('remote', 'add', 'origin', 'https://github.com/test/test') | ||
when: | ||
def url = target.url | ||
def ref = target.ref | ||
def branch = target.branch | ||
then: | ||
url == 'https://github.com/test/test' | ||
ref.size() == 40 | ||
branch == 'master' | ||
cleanup: | ||
project.projectDir.deleteDir() | ||
} | ||
} |