22 * Copyright © Magento, Inc. All rights reserved.
33 * See COPYING.txt for license details.
44 */
5- import java.util.regex.Matcher
6- import java.util.regex.Pattern
5+
6+ import groovy.json.JsonSlurper
77
88/**
99 * Static Checks
@@ -64,74 +64,19 @@ task checkstyleCI(type: Checkstyle) {
6464 * @return list of all changed files
6565 */
6666def getChangedFiles () {
67- // Get the target and source branch
68- // def envTargetBranch = System.getenv("TARGET_BRANCH")
69- // def envSourceBranch = System.getenv("WORKING_BRANCH")
70- def modifiedFiles = System . getenv(" MODIFIED_FILES" )
71-
72- println " Modified Files: ${ modifiedFiles} "
73-
74- // println "Target Branch: ${envTargetBranch}"
75- // println "Source Branch: ${envSourceBranch}"
67+ def modifiedFilesJson = System . getenv(" MODIFIED_FILES" )
7668
77- // Compare to master if no branch specified
78- // def targetBranch
79- // if (project.hasProperty("branch")) {
80- // targetBranch = project.property("branch")
81- // } else {
82- // targetBranch = envTargetBranch ? "origin/${envTargetBranch}" : getParentBranch()
83- // }
84- // def sourceBranch = envSourceBranch ? "origin/${envSourceBranch}" : ""
85- //
86- // println "Merging ${sourceBranch} into ${targetBranch}"
69+ println " Modified Files: ${ modifiedFilesJson} "
8770
88- // Get list of all changed files including status
89- // def systemOutStream = new ByteArrayOutputStream()
90- // def command = "git diff --name-status --diff-filter=dr $targetBranch $sourceBranch"
91- // command.execute().waitForProcessOutput(systemOutStream, System.err)
92- // def allFiles = systemOutStream.toString().trim().split('\n')
93- // systemOutStream.close()
94- //
95- // // Remove the status prefix
96- // Pattern statusPattern = Pattern.compile("(\\w)\\t+(.+)")
9771 List<String > files = new ArrayList<> ()
9872
9973 // println "Changed files:"
100-
101- // for (file in allFiles) {
102- // Matcher matcher = statusPattern.matcher(file)
103- // if (matcher.find()) {
104- // println "+ ${matcher.group(2)}"
105- // files.add(matcher.group(2))
106- // }
107- // }
74+ def modifiedFiles = new JsonSlurper (). parseText(modifiedFilesJson)
75+
76+ modifiedFiles. each {
77+ files. add(it. toString())
78+ }
10879
10980 // Return the list of touched files
11081 files
111- }
112-
113- /**
114- * Determines the parent branch.
115- *
116- * @return the found parent branch or master if not possible
117- */
118- def getParentBranch () {
119- def branch = " "
120- // Get short name of the HEAD branch
121- def branchDeterminer = " git rev-parse --abbrev-ref HEAD" . execute()
122- branchDeterminer. in . eachLine { line -> branch = line }
123- branchDeterminer. err. eachLine { line -> println line }
124- branchDeterminer. waitFor()
125- // Search all branches for parent
126- def branchLine = ' git show-branch -a' . execute(). text. readLines(). find {
127- it. contains(' *' ) && ! (it ==~ " .*\\ [$branch [~^\\ ]].*" )
128- }
129- try {
130- // Filter parent branch name
131- def parent = (branchLine =~ / \[ ([^~^\] ]*)[~^\] ]/ )[0 ][1 ]
132- return parent
133- } catch (Exception ignored) {
134- println " Could not determine parent branch, compare to master"
135- return " master"
136- }
13782}
0 commit comments