31 lines
693 B
Groovy
31 lines
693 B
Groovy
|
|
package com.freeleaps.devops
|
||
|
|
|
||
|
|
class ChangedComponentsDetector {
|
||
|
|
def steps
|
||
|
|
def workspace
|
||
|
|
|
||
|
|
ChangedComponentsDetector(steps) {
|
||
|
|
this.steps = steps
|
||
|
|
}
|
||
|
|
|
||
|
|
def detect(workspace, components) {
|
||
|
|
def changedComponents = [] as Set
|
||
|
|
|
||
|
|
dir(workspace) {
|
||
|
|
// using git command to get changed files list
|
||
|
|
def changedFiles = sh(script: 'git diff --name-only HEAD~1 HEAD', returnStdout: true)
|
||
|
|
.trim()
|
||
|
|
.split('\n')
|
||
|
|
|
||
|
|
changedFiles.each { file ->
|
||
|
|
components.each { component ->
|
||
|
|
if (file.startsWith("${component}/")) {
|
||
|
|
changedComponents.add(component)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return changedComponents.toList()
|
||
|
|
}
|
||
|
|
}
|