Skip to content

Commit

Permalink
Merge pull request #114 from jenkinsci/fix-113
Browse files Browse the repository at this point in the history
fixes 113
  • Loading branch information
KocproZ authored May 15, 2023
2 parents 10baefb + ccfbcd8 commit 57c742b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void setNotes(String notes) {
public String getNotes() {
return notes;
}

@DataBoundSetter
public void setCustomAvatarUrl(String customAvatarUrl) {
this.customAvatarUrl = customAvatarUrl;
Expand All @@ -149,7 +149,7 @@ public void setCustomAvatarUrl(String customAvatarUrl) {
public String getCustomAvatarUrl() {
return customAvatarUrl;
}

@DataBoundSetter
public void setCustomUsername(String customUsername) {
this.customUsername = customUsername;
Expand Down Expand Up @@ -201,7 +201,7 @@ public static class DiscordPipelineStepExecution extends AbstractSynchronousNonB
transient DiscordPipelineStep step;

@StepContextParameter
private transient TaskListener listener;
transient TaskListener listener;

@Override
protected Void run() throws Exception {
Expand Down Expand Up @@ -233,9 +233,14 @@ protected Void run() throws Exception {
if (step.getEnableArtifactsList() || step.getShowChangeset()) {
JenkinsLocationConfiguration globalConfig = JenkinsLocationConfiguration.get();
Run build = getContext().get(Run.class);
wh.setDescription(new EmbedDescription(build, globalConfig, step.getDescription(), step.getEnableArtifactsList(), step.getShowChangeset(),
step.getScmWebUrl())
.toString()
wh.setDescription(new EmbedDescription(
build,
globalConfig,
step.getDescription(),
step.getEnableArtifactsList(),
step.getShowChangeset(),
step.getScmWebUrl()
).toString()
);
} else {
wh.setDescription(checkLimitAndTruncate("description", step.getDescription(), DESCRIPTION_LIMIT));
Expand All @@ -255,9 +260,11 @@ protected Void run() throws Exception {
}

// Add all key value field pairs to the webhook by splitting them with the delimiter
step.fields.stream()
.map(s -> s.split(":"))
.forEach(pair -> wh.addField(pair[0], pair[1]));
if (step.fields != null) {
step.fields.stream()
.map(s -> s.split(":"))
.forEach(pair -> wh.addField(pair[0], pair[1]));
}

try {
wh.send();
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/nz/co/jammehcow/jenkinsdiscord/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ public void webhookClassDoesntThrow() {
wh.setContent("content");
wh.setDescription("desc");
wh.setStatus(DiscordWebhook.StatusColor.GREEN);
wh.send();
} catch (Exception e) {
fail();
}
}

@Test
public void pipelineDoesntThrow() {
try {
DiscordPipelineStep step = new DiscordPipelineStep("http://exampl.e");
step.setTitle("Test title");
DiscordPipelineStep.DiscordPipelineStepExecution execution =
new DiscordPipelineStep.DiscordPipelineStepExecution();
execution.step = step;
execution.listener = () -> System.out;
execution.run();
} catch (Exception e) {
fail();
}
Expand Down

0 comments on commit 57c742b

Please sign in to comment.