<commit_before>package org.dotnet.ci.triggers;

import jobs.generation.JobReport
import jobs.generation.Utilities

/**
* Trigger builder for VSTS
*
*/
class VSTSTriggerBuilder implements TriggerBuilder {
    public enum TriggerType {
        COMMIT,
        PULLREQUEST
    }
    
    TriggerType _triggerType;
    
    /**
     * Construct a new VSTS trigger builder
     *
     * @param triggerType Type of VSTS trigger
     */
    private def VSTSTriggerBuilder(TriggerType triggerType) {
        this._triggerType = triggerType
    }
    
    /**
     * Trigger the pipeline job on a commit
     *
     * @return New trigger builder
     */
    def static VSTSTriggerBuilder triggerOnCommit() {
        return new VSTSTriggerBuilder(TriggerType.COMMIT)
    }
    
    /**
     * Trigger the pipeline job on a PR
     *
     * @return New trigger builder
     */
    def static VSTSTriggerBuilder triggerOnPullRequest() {
        assert false : "nyi"
    }

    /**
     * Returns true if the trigger is a PR trigger
     *
     * @return True if the trigger is a PR trigger
     */
    public boolean isPRTrigger() {
        return (this._triggerType == TriggerType.PULLREQUEST)
    }
    
    // Emits the trigger for a job
    // Parameters:
    //  job - Job to emit the trigger for.
    void emitTrigger(def job) {
    
        if (this._triggerType == TriggerType.PULLREQUEST) {
            assert false : "nyi"
        }
        else if (this._triggerType == TriggerType.COMMIT) {
            this.emitCommitTrigger(job)
        }
        else {
            assert false
        }
    }
    
    def private emitCommitTrigger(def job) {
        job.with {
            triggers {
                teamPushTrigger()
            }
        }

        // Record the push trigger.  We look up in the side table to see what branches this
        // job was set up to build
        JobReport.Report.addPushTriggeredJob(job.name)
        Utilities.addJobRetry(job)
    }
}<commit_msg>Temporarily work around the VSTS push bug by polling (#713)<commit_after>package org.dotnet.ci.triggers;

import jobs.generation.JobReport
import jobs.generation.Utilities

/**
* Trigger builder for VSTS
*
*/
class VSTSTriggerBuilder implements TriggerBuilder {
    public enum TriggerType {
        COMMIT,
        PULLREQUEST
    }
    
    TriggerType _triggerType;
    
    /**
     * Construct a new VSTS trigger builder
     *
     * @param triggerType Type of VSTS trigger
     */
    private def VSTSTriggerBuilder(TriggerType triggerType) {
        this._triggerType = triggerType
    }
    
    /**
     * Trigger the pipeline job on a commit
     *
     * @return New trigger builder
     */
    def static VSTSTriggerBuilder triggerOnCommit() {
        return new VSTSTriggerBuilder(TriggerType.COMMIT)
    }
    
    /**
     * Trigger the pipeline job on a PR
     *
     * @return New trigger builder
     */
    def static VSTSTriggerBuilder triggerOnPullRequest() {
        assert false : "nyi"
    }

    /**
     * Returns true if the trigger is a PR trigger
     *
     * @return True if the trigger is a PR trigger
     */
    public boolean isPRTrigger() {
        return (this._triggerType == TriggerType.PULLREQUEST)
    }
    
    // Emits the trigger for a job
    // Parameters:
    //  job - Job to emit the trigger for.
    void emitTrigger(def job) {
    
        if (this._triggerType == TriggerType.PULLREQUEST) {
            assert false : "nyi"
        }
        else if (this._triggerType == TriggerType.COMMIT) {
            this.emitCommitTrigger(job)
        }
        else {
            assert false
        }
    }
    
    /**
     * Emits a commit trigger.
     *
     */
    def private emitCommitTrigger(def job) {
        job.with {
            triggers {
                // ISSUE: Today the push trigger has a bug, which causes it to not
                // work for all configured projects and all branches.  This is being fixed.  In the meantime,
                // set up an scm trigger instead.  This is inefficient but doable in the interim.
                // Uncomment this when fixed.
                // teamPushTrigger()

                // poll every 5 mins.
                scm('H/5 * * * *') {
                    ignorePostCommitHooks(true)
                }
            }
        }

        // Record the push trigger.  We look up in the side table to see what branches this
        // job was set up to build
        JobReport.Report.addPushTriggeredJob(job.name)
        Utilities.addJobRetry(job)
    }
}
{'fraction_non_alphanumeric': 0.07626373626373627, 'fraction_numerical': 0.001098901098901099, 'mean_word_length': 1.7598544572468162, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3013875', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1270, 'n_words': 387}