Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 9 additions & 8 deletions src/test/groovy/GetGitMatchingGroupStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ metricbeat/module/zookeeper/server/_meta/docs.asciidoc'''.stripMargin().stripInd
def changeset = 'foo/bar/file.txt'
helper.registerAllowedMethod('readFile', [String.class], { return changeset })
def module = script.call(pattern: '([^\\/]+)\\/.*')
assertTrue(assertMethodCallOccurrences('bat', 0))
assertTrue(assertMethodCallContainsPattern('sh', 'git diff'))
assertEquals('foo', module)
assertJobStatusSuccess()
}
Expand Down Expand Up @@ -147,15 +149,14 @@ bar/foo/subfolder'''.stripMargin().stripIndent()
@Test
void test_windows() throws Exception {
def script = loadScript(scriptName)
def changeset = 'foo/bar/file.txt'
helper.registerAllowedMethod('isUnix', [], { false })
try {
script.call()
} catch(e){
//NOOP
}
printCallStack()
assertTrue(assertMethodCallContainsPattern('error', 'windows is not supported yet.'))
assertJobStatusFailure()
helper.registerAllowedMethod('readFile', [String.class], { return changeset })
def module = script.call(pattern: '([^\\/]+)\\/.*')
assertTrue(assertMethodCallOccurrences('sh', 0))
assertTrue(assertMethodCallContainsPattern('bat', 'git diff'))
assertEquals('foo', module)
assertJobStatusSuccess()
}

@Test
Expand Down
11 changes: 7 additions & 4 deletions vars/getGitMatchingGroup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@

*/
def call(Map params = [:]) {
if(!isUnix()){
error('getGitMatchingGroup: windows is not supported yet.')
}
def pattern = params.containsKey('pattern') ? params.pattern : error('getGitMatchingGroup: Missing pattern argument.')
def exclude = params.get('exclude', '')
def from = params.get('from', env.CHANGE_TARGET?.trim() ? "origin/${env.CHANGE_TARGET}" : env.GIT_PREVIOUS_COMMIT)
Expand All @@ -46,7 +43,13 @@ def call(Map params = [:]) {
def gitDiffFile = 'git-diff.txt'
def group = ''
if (from?.trim() && to?.trim()) {
def changes = sh(script: "git diff --name-only ${from}...${to} > ${gitDiffFile}", returnStdout: true)
def changes
def command = "git diff --name-only ${from}...${to} > ${gitDiffFile}"
if (isUnix()) {
changes = sh(script: command, returnStdout: true)
} else {
changes = bat(script: command, returnStdout: true)
}
group = getGroup(gitDiffFile, pattern, exclude)
log(level: 'INFO', text: "getGitMatchingGroup: ${group.trim() ?: 'not found'} with regex ${pattern}")
} else {
Expand Down