Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 56729d9

Browse files
author
Bernhard Grünewaldt
committed
minor fixes after name changes. and formatting of output
1 parent d70382b commit 56729d9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/main/java/io/codeclou/jenkins/githubwebhookbuildtriggerplugin/GithubWebhookBuildTriggerAction.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import javax.servlet.ServletException;
2121
import javax.servlet.http.HttpServletRequest;
22+
import javax.swing.plaf.basic.BasicToolTipUI;
2223
import java.io.IOException;
2324
import java.io.StringWriter;
2425
import java.util.ArrayList;
@@ -51,7 +52,11 @@ public HttpResponse doReceive(HttpServletRequest request, StaplerRequest stapler
5152
IOUtils.copy(request.getInputStream(), writer, "UTF-8");
5253
String requestBody = writer.toString();
5354
Gson gson = new Gson();
55+
GithubWebhookPayload githubWebhookPayload = gson.fromJson(requestBody, GithubWebhookPayload.class);
5456
StringBuilder info = new StringBuilder();
57+
if (githubWebhookPayload == null) {
58+
return HttpResponses.error(500, this.getTextEnvelopedInBanner(" ERROR: payload json is empty at least requestBody is empty!"));
59+
}
5560
try {
5661
//
5762
// WEBHOOK SECRET
@@ -71,11 +76,11 @@ public HttpResponse doReceive(HttpServletRequest request, StaplerRequest stapler
7176
}
7277
webhookSecretMessage = " ok. Webhook secret validates against " + githubSignature + "\n";
7378
}
74-
info.append(webhookSecretMessage).append("\n");
79+
info.append(webhookSecretMessage).append("\n\n");
7580
//
7681
// PAYLOAD TO ENVVARS
7782
//
78-
GithubWebhookPayload githubWebhookPayload = gson.fromJson(requestBody, GithubWebhookPayload.class);
83+
7984
EnvironmentContributionAction environmentContributionAction = new EnvironmentContributionAction(githubWebhookPayload);
8085
//
8186
// TRIGGER JOBS
@@ -92,7 +97,8 @@ public HttpResponse doReceive(HttpServletRequest request, StaplerRequest stapler
9297
Collection<Job> jobs = Jenkins.getInstance().getAllItems(Job.class);
9398
if (jobs.isEmpty()) {
9499
jobsTriggered.append(" WARNING NO JOBS FOUND!\n");
95-
jobsTriggered.append(" If you are using matrix-based security, please give the following rights to 'Anonymous'.\n");
100+
jobsTriggered.append(" You either have no jobs or if you are using matrix-based security,\n");
101+
jobsTriggered.append(" please give the following rights to 'Anonymous':\n");
96102
jobsTriggered.append(" 'Job' -> build, discover, read.\n");
97103
}
98104
for (Job job: jobs) {
@@ -126,8 +132,8 @@ private String normalizeRepoFullName(String reponame) {
126132

127133
private String getTextEnvelopedInBanner(String text) {
128134
StringBuilder banner = new StringBuilder();
129-
banner.append("----------------------------------------------------------------------------------\n");
130-
banner.append("github-webhook-build-trigger-plugin").append("\n");
135+
banner.append("\n----------------------------------------------------------------------------------\n");
136+
banner.append(" github-webhook-build-trigger-plugin").append("\n");
131137
banner.append("----------------------------------------------------------------------------------\n");
132138
banner.append(text);
133139
banner.append("\n----------------------------------------------------------------------------------\n");

0 commit comments

Comments
 (0)