@Override
  public WebhookPayload create(ProjectAnalysis analysis) {
    Writer string = new StringWriter();
    try (JsonWriter writer = JsonWriter.of(string)) {
      writer.beginObject();
      writeServer(writer);
      writeTask(writer, analysis.getCeTask());
      writeAnalysis(writer, analysis, system2);
      writeProject(analysis, writer, analysis.getProject());
      analysis.getBranch().ifPresent(b -> writeBranch(writer, analysis.getProject(), b));
      analysis.getQualityGate().ifPresent(qualityGate -> writeQualityGate(writer, qualityGate));
      writeAnalysisProperties(writer, analysis.getProperties());
      writer.endObject().close();
      return new WebhookPayload(analysis.getProject().getKey(), string.toString());
    }
  }
@Test
  public void create_payload_on_pull_request() {
    CeTask task = new CeTask("#1", CeTask.Status.SUCCESS);
    ProjectAnalysis analysis = newAnalysis(task, null, new Branch(false, "pr/foo", Branch.Type.PULL_REQUEST), 1_500_000_000_000L, emptyMap());

    WebhookPayload payload = underTest.create(analysis);
    assertJson(payload.getJson())
      .isSimilarTo("{" +
        "\"branch\": {" +
        "  \"name\": \"pr/foo\"," +
        "  \"type\": \"PULL_REQUEST\"," +
        "  \"isMain\": false," +
        "  \"url\": \"http://foo/dashboard?id=P1&pullRequest=pr%2Ffoo\"" +
        "}" +
        "}");
  }