Skip to content

Commit

Permalink
Change footer version info source
Browse files Browse the repository at this point in the history
  • Loading branch information
KocproZ committed Sep 3, 2024
1 parent 69113dc commit 8f28622
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/main/java/nz/co/jammehcow/jenkinsdiscord/WebhookPublisher.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package nz.co.jammehcow.jenkinsdiscord;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.Plugin;
import hudson.PluginWrapper;
import hudson.matrix.MatrixConfiguration;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
Expand All @@ -17,6 +20,8 @@
import java.io.IOException;
import java.util.Locale;
import java.util.Map;

import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import nz.co.jammehcow.jenkinsdiscord.exception.WebhookException;
import nz.co.jammehcow.jenkinsdiscord.util.EmbedDescription;
Expand Down Expand Up @@ -48,7 +53,7 @@ public class WebhookPublisher extends Notifier {
private boolean sendLogFile;
private boolean sendStartNotification;
private static final String NAME = "Discord Notifier";
private static final String VERSION = "1.4.11";
private static final String SHORT_NAME = "discord-notifier";
private final String scmWebUrl;

@DataBoundConstructor
Expand Down Expand Up @@ -328,7 +333,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
wh.setStatus(statusColor);

if (this.enableFooterInfo)
wh.setFooter("Jenkins v" + build.getHudsonVersion() + ", " + getDescriptor().getDisplayName() + " v" + getDescriptor().getVersion());
wh.setFooter("Jenkins v" + build.getHudsonVersion() + ", " + getDescriptor().getDisplayName() + " v" + getDescriptor().getPluginVersion());

Check warning on line 336 in src/main/java/nz/co/jammehcow/jenkinsdiscord/WebhookPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 336 is not covered by tests

try {
listener.getLogger().println("Sending notification to Discord.");
Expand Down Expand Up @@ -367,18 +372,29 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {
return true;
}

final Plugin p = Jenkins.get().getPlugin(SHORT_NAME);

public FormValidation doCheckWebhookURL(@QueryParameter String value) {
if (!value.matches("https://(canary\\.|ptb\\.|)discord(app)*\\.com/api/webhooks/\\d{18,19}/(\\w|-|_)*(/?)"))
return FormValidation.error("Please enter a valid Discord webhook URL.");
return FormValidation.ok();
}

@NonNull
public String getDisplayName() {
return NAME;
if (p == null) {

Check warning on line 385 in src/main/java/nz/co/jammehcow/jenkinsdiscord/WebhookPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 385 is only partially covered, one branch is missing
return NAME;
} else {
return p.getWrapper().getDisplayName();
}
}

public String getVersion() {
return VERSION;
public String getPluginVersion() {
if (p == null) {
return "";
} else {
return p.getWrapper().getVersion();

Check warning on line 396 in src/main/java/nz/co/jammehcow/jenkinsdiscord/WebhookPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 393-396 are not covered by tests
}
}
}

Expand Down

0 comments on commit 8f28622

Please sign in to comment.