<commit_before>package org.asu.apmg;

import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import org.apache.commons.io.FileUtils;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.File;
import java.util.ArrayList;

/**
 * @author aesanch2
 */
public class APMGBuilder extends Builder {

    private APMGGit git;
    private boolean rollbackEnabled, updatePackageEnabled, forceInitialBuild;

    // Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
    @DataBoundConstructor
    public APMGBuilder(Boolean rollbackEnabled,
                       Boolean updatePackageEnabled,
                       Boolean forceInitialBuild) {
        this.rollbackEnabled = rollbackEnabled;
        this.updatePackageEnabled = updatePackageEnabled;
        this.forceInitialBuild = forceInitialBuild;
    }

    @Override
    public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
        String newCommit;
        String prevCommit;
        String workspaceDirectory;
        String jobName;
        String buildTag;
        String jenkinsHome;
        ArrayList<String> listOfDestructions, listOfUpdates;
        ArrayList<APMGMetadataObject> members;
        EnvVars envVars;

        try{
            //Load our environment variables for the job
            envVars = build.getEnvironment(listener);

            newCommit = envVars.get("GIT_COMMIT");
            prevCommit = envVars.get("GIT_PREVIOUS_SUCCESSFUL_COMMIT");
            workspaceDirectory = envVars.get("WORKSPACE");
            jobName = envVars.get("JOB_NAME");
            buildTag = envVars.get("BUILD_TAG");
            jenkinsHome = envVars.get("JENKINS_HOME");

            //Create a deployment space for this job within the workspace
            File deployStage = new File(workspaceDirectory + "/apmg");
            if(deployStage.exists()){
                FileUtils.deleteDirectory(deployStage);
            }deployStage.mkdirs();

            //Put the deployment stage location into the environment as a variable
            build.getEnvironment(listener).put("APMG_DEPLOYSTG", deployStage.getPath());

            String pathToRepo = workspaceDirectory + "/.git";

            //This was the initial commit to the repo or the first build
            if (prevCommit == null || getForceInitialBuild()){
                prevCommit = null;
                git = new APMGGit(pathToRepo, prevCommit);
            }
            //If we have a previous successful commit from the git plugin
            else{
                git = new APMGGit(pathToRepo, newCommit, newCommit);
            }

            //Get our change sets
            listOfDestructions = git.getDeletions();<commit_msg>Fix git constructor in APMGBuilder for initial builds<commit_after>package org.asu.apmg;

import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import org.apache.commons.io.FileUtils;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.File;
import java.util.ArrayList;

/**
 * @author aesanch2
 */
public class APMGBuilder extends Builder {

    private APMGGit git;
    private boolean rollbackEnabled, updatePackageEnabled, forceInitialBuild;

    // Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
    @DataBoundConstructor
    public APMGBuilder(Boolean rollbackEnabled,
                       Boolean updatePackageEnabled,
                       Boolean forceInitialBuild) {
        this.rollbackEnabled = rollbackEnabled;
        this.updatePackageEnabled = updatePackageEnabled;
        this.forceInitialBuild = forceInitialBuild;
    }

    @Override
    public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
        String newCommit;
        String prevCommit;
        String workspaceDirectory;
        String jobName;
        String buildTag;
        String jenkinsHome;
        ArrayList<String> listOfDestructions, listOfUpdates;
        ArrayList<APMGMetadataObject> members;
        EnvVars envVars;

        try{
            //Load our environment variables for the job
            envVars = build.getEnvironment(listener);

            newCommit = envVars.get("GIT_COMMIT");
            prevCommit = envVars.get("GIT_PREVIOUS_SUCCESSFUL_COMMIT");
            workspaceDirectory = envVars.get("WORKSPACE");
            jobName = envVars.get("JOB_NAME");
            buildTag = envVars.get("BUILD_TAG");
            jenkinsHome = envVars.get("JENKINS_HOME");

            //Create a deployment space for this job within the workspace
            File deployStage = new File(workspaceDirectory + "/apmg");
            if(deployStage.exists()){
                FileUtils.deleteDirectory(deployStage);
            }deployStage.mkdirs();

            //Put the deployment stage location into the environment as a variable
            build.getEnvironment(listener).put("APMG_DEPLOYSTG", deployStage.getPath());

            String pathToRepo = workspaceDirectory + "/.git";

            //This was the initial commit to the repo or the first build
            if (prevCommit == null || getForceInitialBuild()){
                prevCommit = null;
                git = new APMGGit(pathToRepo, newCommit);
            }
            //If we have a previous successful commit from the git plugin
            else{
                git = new APMGGit(pathToRepo, newCommit, newCommit);
            }

            //Get our change sets
            listOfDestructions = git.getDeletions();
{'fraction_non_alphanumeric': 0.07724885651363714, 'fraction_numerical': 0.000338810774182619, 'mean_word_length': 2.5609167671893847, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7048735', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1531, 'n_words': 398}