2
2
* Copyright © Magento, Inc. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
- import java.util.regex.Matcher
6
- import java.util.regex.Pattern
5
+
6
+ import groovy.json.JsonSlurper
7
7
8
8
/**
9
9
* Static Checks
@@ -64,74 +64,19 @@ task checkstyleCI(type: Checkstyle) {
64
64
* @return list of all changed files
65
65
*/
66
66
def 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" )
76
68
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} "
87
70
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+(.+)")
97
71
List<String > files = new ArrayList<> ()
98
72
99
73
// 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
+ }
108
79
109
80
// Return the list of touched files
110
81
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
- }
137
82
}
0 commit comments