freeleaps-ops/first-class-pipeline/src/com/freeleaps/devops/ChangedComponentsDetector.groovy

31 lines
709 B
Groovy
Raw Normal View History

package com.freeleaps.devops
class ChangedComponentsDetector {
def steps
def workspace
ChangedComponentsDetector(steps) {
this.steps = steps
}
def detect(workspace, components) {
def changedComponents = [] as Set
steps.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.name}/")) {
changedComponents.add(component.name)
}
}
}
}
return changedComponents.toList()
}
}