Skip to content

Commit

Permalink
add delay message field and send with request
Browse files Browse the repository at this point in the history
  • Loading branch information
VardyNg committed Sep 15, 2023
1 parent 49fafb0 commit 7e57683
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/io/jenkins/plugins/sample/NTFYNotifierBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.function.BiConsumer;

public class NTFYNotifierBuilder extends Builder implements SimpleBuildStep {

Expand All @@ -30,15 +31,27 @@ public class NTFYNotifierBuilder extends Builder implements SimpleBuildStep {
private final String priority;
private final String tags;
private final Boolean useMarkdownFormatting;
private final String delayedMessage;

@DataBoundConstructor
public NTFYNotifierBuilder(String serverURL, String topic, String message, String title, String priority, String tags, Boolean useMarkdownFormatting) {
public NTFYNotifierBuilder(
String serverURL,
String topic,
String message,
String title,
String priority,
String tags,
Boolean useMarkdownFormatting,
String delayedMessage
) {
this.serverURL = serverURL;
this.topic = topic;
this.message = message;
this.title = title;
this.priority = priority;
this.tags = tags;
this.useMarkdownFormatting = useMarkdownFormatting;
this.delayedMessage = delayedMessage;
}

public String getServerURL() {
Expand All @@ -64,6 +77,7 @@ public void perform(Run<?, ?> run, FilePath workspace, EnvVars env, Launcher lau
listener.getLogger().println("Title: " + title);
listener.getLogger().println("Priority: " + priority);
listener.getLogger().println("Tags " + tags);
listener.getLogger().println("Delayed " + delayedMessage);

try {
HttpURLConnection conn = (HttpURLConnection) new URL(topicURL).openConnection();
Expand All @@ -75,6 +89,7 @@ public void perform(Run<?, ?> run, FilePath workspace, EnvVars env, Launcher lau
if (!title.isEmpty()) conn.setRequestProperty("Title", title);
if (!priority.isEmpty()) conn.setRequestProperty("Priority", priority);
if (!tags.isEmpty()) conn.setRequestProperty("Tags", tags.trim());
if (!delayedMessage.isEmpty()) conn.setRequestProperty("X-Delay", delayedMessage);
conn.setRequestProperty("Markdown", useMarkdownFormatting ? "yes" : "no");
// To send a POST request, we should set this to true
conn.setDoOutput(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
description="${%FrenchDescr}">
<f:checkbox />
</f:entry>
<f:entry title="${%DelayedMessage}" field="delayedMessage">
<f:textbox />
</f:entry>
</f:advanced>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Priority_3=default
Priority_2=low
Priority_1=min
Tags=Tags
DelayedMessage=Delayed message
MarkDownFormatting=MarkDown formatting
FrenchDescr=Check if we should say hello in French

0 comments on commit 7e57683

Please sign in to comment.