static void gitHubPullRequestTrigger()

in ossci/JobUtil.groovy [130:248]


  static void gitHubPullRequestTrigger(MultiJob context, String ownerAndProject, String githubAuthIdValue, Class users, boolean reportStatus = false) {
    context.with {
      parameters {
        // This defaults to ${ghprbActualCommit} so that the Git SCM plugin
        // will check out the HEAD of the pull request. Another parameter emitted
        // by the GitHub pull request builder plugin is ${sha1}, which points to
        // origin/pulls/1234/merge if and only if the PR could be merged to master.
        // This ref changes whenever anything is committed to master.
        // We use a multi job which triggers builds at different times.
        // Following this ref blindly can therefore lead to a single build
        // using different commits. To avoid this, we use ${ghprbActualCommit},
        // perform the merge to master ourselves, and capture the commit hash of
        // origin/master in this build. The raw version of this commit hash (and
        // not origin/master) is then propagated to downstream builds.
        ParametersUtil.GIT_COMMIT(delegate, '${ghprbActualCommit}')
        ParametersUtil.GIT_MERGE_TARGET(delegate, 'origin/${ghprbTargetBranch}')
      }
      commonTrigger(delegate)
      // Use reference instead...
      //wrappers {
      //  preScmSteps {
      //    steps {
      //      shell('cd /data/git-mirror/pytorch.git && git fetch')
      //    }
      //  }
      //}
      scm {
        git {
          remote {
            // It's important to UNCONDITIONALLY call github() in the
            // DSL, because it sets up com.coravy.hudson.plugins.github.GithubProjectProperty
            // which is checked by ghprb when it decides if it wants to
            // accept a job or not.  If you omit it, all hooks will
            // start failing!
            github(ownerAndProject)
            // // Actually, it's a better idea to use reference
            // if (ownerAndProject == "pytorch/pytorch") {
            //  url("/data/git-mirror/pytorch.git")
            // }
            refspec([
                // Fetch remote branches so we can merge the PR
                '+refs/heads/*:refs/remotes/origin/*',
                // Fetch PRs
                '+refs/pull/*:refs/remotes/origin/pr/*',
            ].join(' '))
          }
          branch('${GIT_COMMIT}')
          if (ownerAndProject == "pytorch/pytorch") {
            extensions {
              cloneOptions {
                reference("/data/git-mirror/pytorch.git")
              }
            }
          } else {
            GitUtil.defaultExtensions(delegate)
          }
        }
      }

      triggers {
        githubPullRequest {
          admins(users.githubAdmins)
          // userWhitelist(users.githubUserWhitelist)
          // Below: An experiment in LIVING DANGEROUSLY!
          permitAll()
          useGitHubHooks()
          // If labeled with skip-tests, don't run tests.  This is
          // currently only being used by caffe2
          blackListLabels(['skip-tests'])

          // No jenkins job should run on LTS branches
          blackListTargetBranches(['^lts*'])

          // Only build the PR if it targets 'master'
          // 'sending_pr' is a special case for ROCmSoftwarePlatform/pytorch
          // 'tensor-merge' is a temporary working branch for tensor
          // representation merge
          whiteListTargetBranches(['.*'])

          // It would be nice to require the CLA Signed label,
          // but as the label is added by the facebook github bot,
          // it races with the trigger sent to Jenkins.
          // To trigger builds immediately upon creating a PR,
          // we'll leave this disabled.
          //whiteListLabels(['CLA Signed'])
        }
      }

      // The configure block gives access to the raw XML.
      // This is needed here because the ghprb DSL extension doesn't
      // provide access to the credentials to use.
      configure { node ->
        def triggers = node / 'triggers'
        // Iterate and find the right trigger node so that this
        // doesn't depend on the version of the ghprb plugin.
        triggers.children().each { trigger ->
          if (trigger.name() == 'org.jenkinsci.plugins.ghprb.GhprbTrigger') {
            // This adds the <gitHubAuthId/> tag with the pytorchbot credentials
            def gitHubAuthId = trigger / 'gitHubAuthId'
            gitHubAuthId.setValue(githubAuthIdValue)

            def extensions = trigger / 'extensions'
            if (!reportStatus) {
              // Replace default extension with a single one that
              // instructs ghprb to not set any commit status.
              // We rely on the downstream jobs to do this.
              def statusNode = { "org.jenkinsci.plugins.ghprb.extensions.status.${it}" }
              extensions.remove(extensions / statusNode('GhprbSimpleStatus'))
              extensions / statusNode('GhprbNoCommitStatus')
            }

            // Cancel PR builds when there is an update
            def buildNode = { "org.jenkinsci.plugins.ghprb.extensions.build.${it}" }
            extensions / buildNode('GhprbCancelBuildsOnUpdate')
          }
        }
      }
    }
  }