import groovy.json.JsonOutput

def gerrit = new com.mirantis.mk.Gerrit()
def common = new com.mirantis.mk.Common()

// extraVarsYaml contains GERRIT_ vars from gate job
// or will contain GERRIT_ vars from reclass-system patch
def extraVarsYaml = env.EXTRA_VARIABLES_YAML ?: ''
if (extraVarsYaml != '') {
    common.mergeEnv(env, extraVarsYaml)
} else {
    extraVarsYaml = JsonOutput.toJson(env.getEnvironment().findAll{ it.key.startsWith('GERRIT_') })
}

def slaveNode = env.SLAVE_NODE ?: 'virtual'
def gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit'

def gerritRef = env.GERRIT_REFSPEC ?: null
def defaultGitRef = env.DEFAULT_GIT_REF ?: null
def defaultGitUrl = env.DEFAULT_GIT_URL ?: null

def checkouted = false
def merged = false
def systemRefspec = "HEAD"

timeout(time: 12, unit: 'HOURS') {
    node(slaveNode) {
        try {
            stage("Checkout") {
                if (gerritRef) {
                    // job is triggered by Gerrit
                    // test if change aren't already merged
                    def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials)
                    merged = gerritChange.status == "MERGED"
                    if (!merged) {
                        checkouted = gerrit.gerritPatchsetCheckout([
                            credentialsId: gerritCredentials
                        ])
                        systemRefspec = GERRIT_REFSPEC
                    }
                    // change defaultGit variables if job triggered from Gerrit
                    defaultGitUrl = "${GERRIT_SCHEME}://${GERRIT_NAME}@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
                } else if (defaultGitRef && defaultGitUrl) {
                    checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
                }
            }

            stage("Test") {
                if (merged) {
                    common.successMsg("Gerrit change is already merged, no need to test them")
                } else {
                    if (checkouted) {

                        def documentationOnly = false
                        if (gerritRef) {
                            documentationOnly = sh(script: "git diff-tree --no-commit-id --name-only -r HEAD | grep -v .releasenotes", returnStatus: true) == 1
                        }

                        sh("git diff-tree --no-commit-id --diff-filter=d --name-only -r HEAD  | grep .yml | xargs -I {}  python -c \"import yaml; yaml.load(open('{}', 'r'))\" \\;")

                        def branches = [:]
                        def testModels = documentationOnly ? [] : TEST_MODELS.split(',')
                        if (['master'].contains(env.GERRIT_BRANCH)) {
                            for (int i = 0; i < testModels.size(); i++) {
                                def cluster = testModels[i]
                                def clusterGitUrl = defaultGitUrl.substring(0, defaultGitUrl.lastIndexOf("/") + 1) + cluster
                                branches["${cluster}"] = {
                                    build job: "test-salt-model-${cluster}", parameters: [
                                        [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: clusterGitUrl],
                                        [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: "HEAD"],
                                        [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: defaultGitUrl],
                                        [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: systemRefspec]
                                    ]
                                }
                            }
                        } else {
                            common.warningMsg("Tests for ${testModels} skipped!")
                        }
                        branches["cookiecutter"] = {
                            build job: "test-mk-cookiecutter-templates", parameters: [
                                [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_URL', value: defaultGitUrl],
                                [$class: 'StringParameterValue', name: 'RECLASS_SYSTEM_GIT_REF', value: systemRefspec],
                                [$class: 'TextParameterValue', name: 'EXTRA_VARIABLES_YAML', value: extraVarsYaml ]
                            ]
                        }
                        parallel branches
                    } else {
                        error("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
                    }
                }
            }
        } catch (Throwable e) {
            currentBuild.result = "FAILURE"
            currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
            throw e
        } finally {
            common.sendNotification(currentBuild.result, "", ["slack"])
        }
    }
}
