private void build(GHPullRequest pr, GHUser buildRequester, TriggerCause cause)
      throws IOException {
    ArrayList<ParameterValue> parameters = getDefaultBuildParameters();
    parameters.add(new StringParameterValue(PR_COMMIT, pr.getHead().getSha()));
    parameters.add(new StringParameterValue(PR_BRANCH, pr.getHead().getRef()));
    if (buildRequester != null) {
      parameters.add(new StringParameterValue(BUILD_REQUESTER, buildRequester.getLogin()));
      if (buildRequester.getEmail() != null) {
        parameters.add(new StringParameterValue(BUILD_REQUEST_EMAIL, buildRequester.getEmail()));
      }
    }
    parameters.add(new StringParameterValue(PR_NUMBER, String.valueOf(pr.getNumber())));
    parameters.add(new StringParameterValue(PR_MERGE_BRANCH, pr.getBase().getRef()));
    parameters.add(new StringParameterValue(PR_OWNER, pr.getUser().getLogin()));
    if (pr.getUser().getEmail() != null) {
      parameters.add(new StringParameterValue(PR_OWNER_EMAIL, pr.getUser().getEmail()));
    }
    final StringParameterValue prUrlParam =
        new StringParameterValue(PR_URL, pr.getHtmlUrl().toString());
    parameters.add(prUrlParam);

    project.scheduleBuild2(
        project.getQuietPeriod(),
        cause,
        new ParametersAction(parameters),
        getBuildData(prUrlParam),
        new RevisionParameterAction(pr.getHead().getSha()));
  }
 protected Future schedule(AbstractBuild<?, ?> build, AbstractProject project, List<Action> list)
     throws InterruptedException, IOException {
   return project.scheduleBuild2(
       project.getQuietPeriod(),
       new UpstreamCause((Run) build),
       list.toArray(new Action[list.size()]));
 }
  /*
   * Path: /auto/scheduleBuild
   *
   * POST to create automation requests to schedule builds.
   */
  public void doScheduleBuild(StaplerRequest request, StaplerResponse response) throws Exception {
    requirePOST();

    OSLC4JUnmarshaller unmarshaller = OSLC4JContext.newInstance().createUnmarshaller();

    String contentType = request.getContentType();
    if (contentType == null) {
      throw HttpResponses.status(HttpServletResponse.SC_BAD_REQUEST);
    }
    unmarshaller.setMediaType(MediaType.valueOf(contentType));

    final AutomationRequest autoRequest =
        unmarshaller.unmarshal(request.getInputStream(), AutomationRequest.class);
    if (autoRequest == null) {
      throw HttpResponses.status(HttpServletResponse.SC_BAD_REQUEST);
    }

    Link planLink = autoRequest.getExecutesAutomationPlan();
    if (planLink == null) {
      throw HttpResponses.status(HttpServletResponse.SC_BAD_REQUEST);
    }

    URI planURI = planLink.getValue();
    String jobName = getJobNameFromURI(planURI);
    if (jobName == null) {
      throw HttpResponses.status(HttpServletResponse.SC_BAD_REQUEST);
    }

    Job<?, ?> job = getJob(jobName);
    if (job == null) {
      throw HttpResponses.status(HttpServletResponse.SC_BAD_REQUEST);
    }

    if (!job.isBuildable()) {
      throw HttpResponses.status(HttpServletResponse.SC_BAD_REQUEST);
    }

    if (!(job instanceof AbstractProject)) {
      LOG.log(
          Level.WARNING,
          "Cannot schedule builds for jobs that don't extend AbstractProject: " + jobName);
      throw HttpResponses.status(HttpServletResponse.SC_BAD_REQUEST);
    }

    AbstractProject<?, ?> project = (AbstractProject<?, ?>) job;
    int nextBuildNumber = project.getNextBuildNumber();
    Cause cause =
        new Cause() {
          @Override
          public String getShortDescription() {
            String description = autoRequest.getDescription();
            return description != null ? description : "OSLC Automation Request";
          }
        };

    ParameterInstance[] parameters = autoRequest.getInputParameters();
    boolean suceeded;
    if (parameters.length == 0) {
      suceeded = project.scheduleBuild(cause);
    } else {
      List<ParameterValue> values = getParameterValues(project, parameters);
      suceeded =
          project.scheduleBuild2(project.getQuietPeriod(), cause, new ParametersAction(values))
              != null;
    }

    if (!suceeded) {
      // Build already queued.
      LOG.log(
          Level.WARNING,
          "Automation request rejected (409 conflict) since build is already queued: " + jobName);
      throw HttpResponses.status(HttpServletResponse.SC_CONFLICT);
    }

    URI requestURI = getAutoRequestURI(job, nextBuildNumber);
    response.setStatus(HttpServletResponse.SC_CREATED);
    response.setHeader("Location", requestURI.toString());
  }