-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional logging for notification conditions (#516)
- Extracted Condition interface that let's us log both if the condition was met and if the user preference allowed the notification to be sent - Conditions that have interesting logic are unit-tested - Moves to the message supplier style of logging, which is not invoked unless that level of logging is enabled - Introduces a build key format - [ProjectFullDisplayName #<build>] to better indicate which build the messaging is coming from - Introduce SlackFactory in ActiveNotifier instead of passing in the dependencies to create a slack factory method - Introduce SlackNotificationsLogger - which writes to the system log with the build key embedded, and writes info-level messages to the build log with the plugin name embedded
- Loading branch information
Showing
26 changed files
with
853 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/jenkins/plugins/slack/JenkinsTokenExpander.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package jenkins.plugins.slack; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.TaskListener; | ||
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; | ||
import org.jenkinsci.plugins.tokenmacro.TokenMacro; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class JenkinsTokenExpander implements TokenExpander { | ||
private static final Logger logger = Logger.getLogger(JenkinsTokenExpander.class.getName()); | ||
private final TaskListener listener; | ||
|
||
public JenkinsTokenExpander(TaskListener listener) { | ||
this.listener = listener; | ||
} | ||
|
||
@Override | ||
public String expand(String template, AbstractBuild<?, ?> build) { | ||
try { | ||
return TokenMacro.expandAll(build, listener, template, false, null); | ||
} catch (MacroEvaluationException | IOException | InterruptedException e) { | ||
logger.log(Level.SEVERE, "Failed to process custom message", e); | ||
return "[UNPROCESSABLE] " + template; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.