package com.freeleaps.devops

class SourceFetcher {
  def steps

  SourceFetcher(steps) {
    this.steps = steps
  }

  def fetch(configurations) {
    if (configurations.serviceGitRepo == null || configurations.serviceGitRepo.isEmpty()) {
      steps.error("serviceGitRepo is required")
    }

    if (configurations.serviceGitBranch == null || configurations.serviceGitBranch.isEmpty()) {
      steps.error("serviceGitBranch is required")
    }

    steps.env.workroot = "${steps.env.WORKSPACE}/devops-workspace/${configurations.serviceName}"

    steps.dir(steps.env.workroot) {
      steps.git branch: configurations.serviceGitBranch, credentialsId: configurations.serviceGitCredentialsId, url: configurations.serviceGitRepo
    }
  }
}