<commit_before>package platform

import org.yaml.snakeyaml.Yaml
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_LOG_ROTATOR
import static org.edx.jenkins.dsl.JenkinsPublicConstants.GHPRB_WHITELIST_BRANCH
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_GITHUB_STATUS_SUCCESS
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_GITHUB_STATUS_UNSTABLE_OR_WORSE
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_GITHUB_BASEURL
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_BASE_URL

/* stdout logger */
/* use this instead of println, because you can pass it into closures or other scripts. */
Map config = [:]
Binding bindings = getBinding()
config.putAll(bindings.getVariables())
PrintStream out = config['out']

/* Map to hold the k:v pairs parsed from the secret file */
Map mailingListMap = [:]
Map ghprbMap = [:]
Map securityGroupMap = [:]
try {
    out.println('Parsing secret YAML file')
    String mailingListSecretContents  = new File("${MAILING_LIST_SECRET}").text
    String ghprbConfigContents = new File("${GHPRB_SECRET}").text
    String securityGroupConfigContents = new File("${SECURITY_GROUP_SECRET}").text
    Yaml yaml = new Yaml()
    mailingListMap = yaml.load(mailingListSecretContents)
    ghprbMap = yaml.load(ghprbConfigContents)
    securityGroupMap = yaml.load(securityGroupConfigContents)
    out.println('Successfully parsed secret YAML file')
}
catch (any) {
    out.println('Jenkins DSL: Error parsing secret YAML file')
    out.println('Exiting with error code 1')
    return 1
}

assert mailingListMap.containsKey('e2e_test_mailing_list')
assert securityGroupMap.containsKey('e2eSecurityGroup')
assert ghprbMap.containsKey('admin')
assert ghprbMap.containsKey('userWhiteList')
assert ghprbMap.containsKey('orgWhiteList')

// This script generates a lot of jobs. Here is a breakdown of the configuration options
// for a job:
// Map exampleConfig = [ name: name of the job,
//                       deprecated: (TEMPORARY) this is used to distinguish between normal jobs and jobs used
//                               to test the kashif/white-label branch, which we are refactoring
//                       testSuite: the set of tests to run, i.e. regular e2e tests or whitelabel site tests,
//                       worker: label of the jenkins worker that this job should be run with,
//                       trigger: what triggers the job, i.e. pull requests (ghprb), merging into a branch (merge),
//                                or an outside trigger (pipeline),
//                       triggerPhrase: (for `ghprb` jobs) the ghprb phrase used to trigger a job from a github
//                                comment,
//                       branch: the branch of edx-e2e-tests to fetch,
//                       refspec: the git refspec used to fetch the branch,
//                       branchRegex: (for `ghprb` jobs) a regex to isolate which prs should be tested with this
//                                job,
//                       description: the description of the job,
//                       courseNumber: (used for the `e2e` test suite) the course number to run tests against,
//                       testScript: the script to run in order to trigger the tests,
//                       context: (for `ghprb` and `merge` jobs) the context,
//                       junitReportPath: path to the JUnit report xml files generated by the e2e tests
//                       ]
//

// Pipeline Triggered Jobs

// The edx-e2e-tests job is run automatically on every deployment of the edx-platform
// from the gocd pipeline.
Map pipelineJob = [ name: 'edx-e2e-tests',
                    deprecated: false,
                    testSuite: 'e2e',
                    worker: 'jenkins-precise-worker',
                    trigger: 'pipeline',
                    branch: '*/master',
                    refspec: '+refs/heads/master:refs/remotes/origin/master',
                    description: 'Run end-to-end tests against GoCD deployments',
                    courseNumber: 'AR-1000',
                    testScript: 'jenkins/end_to_end_tests.sh',
                    junitReportPath: 'reports/*.xml'
                    ]

// Pull Request Triggered Jobs

// The edx-e2e-tests-pr job is run on every PR to the edx-e2e-tests repo. This
// is used for development of the e2e tests themselves
Map prJob = [ name: 'edx-e2e-tests-pr',
              deprecated: false,
              testSuite: 'e2e',
              worker: 'jenkins-precise-worker',
              trigger: 'ghprb',
              triggerPhrase: 'jenkins run e2e',
              branch: '${ghprbActualCommit}',
              refspec: '+refs/pull/*:refs/remotes/origin/pr/*',
              branchRegex: "^(?!kashif/white-label)\$", // all branches except for kashif/white-label
              description: 'Verify the quality of changes made to the end-to-end tests',
              courseNumber: 'AR-1001',
              testScript: 'jenkins/end_to_end_tests.sh',
              context: 'jenkins/e2e',
              junitReportPath: 'reports/*.xml'
              ]

// The microsites-staging-tests-pr job is run on every PR into the edx-e2e-tests
// repo. This is used for development of the microsites tests themselves
Map micrositesPrJob = [ name: 'microsites-staging-tests-pr',
                        deprecated: false,
                        testSuite: 'microsites',
                        worker: 'jenkins-precise-worker',
                        trigger: 'ghprb',
                        triggerPhrase: 'jenkins run microsites',
                        branch: '${ghprbActualCommit}',
                        refspec: '+refs/pull/*:refs/remotes/origin/pr/*',
                        branchRegex: "^(?!kashif/white-label)\$", // all branches except for kashif/white-label
                        description: 'Verify the quality of changes made to the microsite tests',
                        testScript: 'edx-e2e-tests/jenkins/white_label.sh',
                        context: 'jenkins/microsites',
                        junitReportPath: 'edx-e2e-tests/*.xml,edx-e2e-tests/reports/*.xml'
                        ]

// The microsites-deprecated-tests-pr job is run on every PR into the kashif/white-label branch.
// NOTE: this is a temporary job. Remove it once kashif/white-label has been
// merged into edx/edx-e2e-tests
Map deprecatedPrJob = [ name: 'microsites-deprecated-tests-pr',
                        deprecated: true,
                        testSuite: 'microsites',
                        worker: 'jenkins-precise-worker',
                        trigger: 'ghprb',
                        triggerPhrase: 'jenkins run microsites',
                        branch: '${ghprbActualCommit}',
                        refspec: '+refs/pull/*:refs/remotes/origin/pr/*',
                        branchRegex: '^kashif/white-label\$', // ONLY the kashif/white-label branch
                        description: 'Verify the changes made to the microsites tests in kashif/white-label branch',
                        testScript: 'edx-e2e-tests/jenkins/white_label.sh',
                        context: 'jenkins/microsites',
                        junitReportPath: 'edx-e2e-tests/*.xml,edx-e2e-tests/reports/*.xml'
                        ]

// Merge Triggered Jobs
<commit_msg>adjust regexes for e2e pr jobs<commit_after>package platform

import org.yaml.snakeyaml.Yaml
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_LOG_ROTATOR
import static org.edx.jenkins.dsl.JenkinsPublicConstants.GHPRB_WHITELIST_BRANCH
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_GITHUB_STATUS_SUCCESS
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_GITHUB_STATUS_UNSTABLE_OR_WORSE
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_GITHUB_BASEURL
import static org.edx.jenkins.dsl.JenkinsPublicConstants.JENKINS_PUBLIC_BASE_URL

/* stdout logger */
/* use this instead of println, because you can pass it into closures or other scripts. */
Map config = [:]
Binding bindings = getBinding()
config.putAll(bindings.getVariables())
PrintStream out = config['out']

/* Map to hold the k:v pairs parsed from the secret file */
Map mailingListMap = [:]
Map ghprbMap = [:]
Map securityGroupMap = [:]
try {
    out.println('Parsing secret YAML file')
    String mailingListSecretContents  = new File("${MAILING_LIST_SECRET}").text
    String ghprbConfigContents = new File("${GHPRB_SECRET}").text
    String securityGroupConfigContents = new File("${SECURITY_GROUP_SECRET}").text
    Yaml yaml = new Yaml()
    mailingListMap = yaml.load(mailingListSecretContents)
    ghprbMap = yaml.load(ghprbConfigContents)
    securityGroupMap = yaml.load(securityGroupConfigContents)
    out.println('Successfully parsed secret YAML file')
}
catch (any) {
    out.println('Jenkins DSL: Error parsing secret YAML file')
    out.println('Exiting with error code 1')
    return 1
}

assert mailingListMap.containsKey('e2e_test_mailing_list')
assert securityGroupMap.containsKey('e2eSecurityGroup')
assert ghprbMap.containsKey('admin')
assert ghprbMap.containsKey('userWhiteList')
assert ghprbMap.containsKey('orgWhiteList')

// This script generates a lot of jobs. Here is a breakdown of the configuration options
// for a job:
// Map exampleConfig = [ name: name of the job,
//                       deprecated: (TEMPORARY) this is used to distinguish between normal jobs and jobs used
//                               to test the kashif/white-label branch, which we are refactoring
//                       testSuite: the set of tests to run, i.e. regular e2e tests or whitelabel site tests,
//                       worker: label of the jenkins worker that this job should be run with,
//                       trigger: what triggers the job, i.e. pull requests (ghprb), merging into a branch (merge),
//                                or an outside trigger (pipeline),
//                       triggerPhrase: (for `ghprb` jobs) the ghprb phrase used to trigger a job from a github
//                                comment,
//                       branch: the branch of edx-e2e-tests to fetch,
//                       refspec: the git refspec used to fetch the branch,
//                       branchRegex: (for `ghprb` jobs) a regex to isolate which prs should be tested with this
//                                job,
//                       description: the description of the job,
//                       courseNumber: (used for the `e2e` test suite) the course number to run tests against,
//                       testScript: the script to run in order to trigger the tests,
//                       context: (for `ghprb` and `merge` jobs) the context,
//                       junitReportPath: path to the JUnit report xml files generated by the e2e tests
//                       ]
//

// Pipeline Triggered Jobs

// The edx-e2e-tests job is run automatically on every deployment of the edx-platform
// from the gocd pipeline.
Map pipelineJob = [ name: 'edx-e2e-tests',
                    deprecated: false,
                    testSuite: 'e2e',
                    worker: 'jenkins-precise-worker',
                    trigger: 'pipeline',
                    branch: '*/master',
                    refspec: '+refs/heads/master:refs/remotes/origin/master',
                    description: 'Run end-to-end tests against GoCD deployments',
                    courseNumber: 'AR-1000',
                    testScript: 'jenkins/end_to_end_tests.sh',
                    junitReportPath: 'reports/*.xml'
                    ]

// Pull Request Triggered Jobs

// The edx-e2e-tests-pr job is run on every PR to the edx-e2e-tests repo. This
// is used for development of the e2e tests themselves
Map prJob = [ name: 'edx-e2e-tests-pr',
              deprecated: false,
              testSuite: 'e2e',
              worker: 'jenkins-precise-worker',
              trigger: 'ghprb',
              triggerPhrase: 'jenkins run e2e',
              branch: '${ghprbActualCommit}',
              refspec: '+refs/pull/*:refs/remotes/origin/pr/*',
              branchRegex: '^(?!kashif/white_label).*$', // PRs targeting any branch except kashif/white-label
              description: 'Verify the quality of changes made to the end-to-end tests',
              courseNumber: 'AR-1001',
              testScript: 'jenkins/end_to_end_tests.sh',
              context: 'jenkins/e2e',
              junitReportPath: 'reports/*.xml'
              ]

// The microsites-staging-tests-pr job is run on every PR into the edx-e2e-tests
// repo. This is used for development of the microsites tests themselves
Map micrositesPrJob = [ name: 'microsites-staging-tests-pr',
                        deprecated: false,
                        testSuite: 'microsites',
                        worker: 'jenkins-precise-worker',
                        trigger: 'ghprb',
                        triggerPhrase: 'jenkins run microsites',
                        branch: '${ghprbActualCommit}',
                        refspec: '+refs/pull/*:refs/remotes/origin/pr/*',
                        branchRegex: '^(?!kashif/white_label).*$', // PRs targeting any branch except kashif/white-label
                        description: 'Verify the quality of changes made to the microsite tests',
                        testScript: 'edx-e2e-tests/jenkins/white_label.sh',
                        context: 'jenkins/microsites',
                        junitReportPath: 'edx-e2e-tests/*.xml,edx-e2e-tests/reports/*.xml'
                        ]

// The microsites-deprecated-tests-pr job is run on every PR into the kashif/white-label branch.
// NOTE: this is a temporary job. Remove it once kashif/white-label has been
// merged into edx/edx-e2e-tests
Map deprecatedPrJob = [ name: 'microsites-deprecated-tests-pr',
                        deprecated: true,
                        testSuite: 'microsites',
                        worker: 'jenkins-precise-worker',
                        trigger: 'ghprb',
                        triggerPhrase: 'jenkins run microsites',
                        branch: '${ghprbActualCommit}',
                        refspec: '+refs/pull/*:refs/remotes/origin/pr/*',
                        branchRegex: 'kashif/white_label', // ONLY PRs targeting the kashif/white-label branch
                        description: 'Verify the changes made to the microsites tests in kashif/white-label branch',
                        testScript: 'edx-e2e-tests/jenkins/white_label.sh',
                        context: 'jenkins/microsites',
                        junitReportPath: 'edx-e2e-tests/*.xml,edx-e2e-tests/reports/*.xml'
                        ]

// Merge Triggered Jobs

{'fraction_non_alphanumeric': 0.09438535074727346, 'fraction_numerical': 0.00464521341052915, 'mean_word_length': 2.0144074675324677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1355306', 'n_tokens_mistral': 4348, 'n_tokens_neox': 4067, 'n_words': 1163}