-
Notifications
You must be signed in to change notification settings - Fork 21
refactor: Add error notify and change build version number. #41
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import com.github.playerforcehd.tcdiscordwebhooks.discord.embeds.DiscordEmbedColor; | ||
import com.github.playerforcehd.tcdiscordwebhooks.discord.embeds.DiscordEmbedField; | ||
import jetbrains.buildServer.Build; | ||
import jetbrains.buildServer.BuildProblemData; | ||
import jetbrains.buildServer.notification.Notificator; | ||
import jetbrains.buildServer.notification.NotificatorRegistry; | ||
import jetbrains.buildServer.responsibility.ResponsibilityEntry; | ||
|
@@ -193,8 +194,8 @@ private DiscordEmbedField[] buildFieldsForRunningBuild(SRunningBuild sRunningBui | |
@Override | ||
public void notifyBuildStarted(@NotNull SRunningBuild sRunningBuild, @NotNull Set<SUser> users) { | ||
String title = "Build started"; | ||
String description = "A build with the ID " + sRunningBuild.getBuildId() + " has been started!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildId(); | ||
String description = "A build with the ID " + sRunningBuild.getBuildNumber() + " has been started!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildNumber(); | ||
DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload(); | ||
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{ | ||
new DiscordEmbed( | ||
|
@@ -214,8 +215,8 @@ public void notifyBuildStarted(@NotNull SRunningBuild sRunningBuild, @NotNull Se | |
@Override | ||
public void notifyBuildSuccessful(@NotNull SRunningBuild sRunningBuild, @NotNull Set<SUser> users) { | ||
String title = "Build succeeded!"; | ||
String description = "The build with the ID " + sRunningBuild.getBuildId() + " has succeeded!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildId(); | ||
String description = "The build with the ID " + sRunningBuild.getBuildNumber() + " has succeeded!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildNumber(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please continue to use |
||
DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload(); | ||
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{ | ||
new DiscordEmbed( | ||
|
@@ -235,13 +236,27 @@ public void notifyBuildSuccessful(@NotNull SRunningBuild sRunningBuild, @NotNull | |
@Override | ||
public void notifyBuildFailed(@NotNull SRunningBuild sRunningBuild, @NotNull Set<SUser> users) { | ||
String title = "Build failed"; | ||
String description = "The build with the ID " + sRunningBuild.getBuildId() + " has failed!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildId(); | ||
StringBuilder description = new StringBuilder("The build with the ID " + sRunningBuild.getBuildNumber() + " has failed!"); | ||
|
||
description.append("\n" + "The build has failed with the following reason: "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd maybe add another linebreak here to have a blank line between build id line and failure reasons. Like:
I leave this decision up to you. Current layout would be also fine for me. |
||
// Iterate through the failure reasons of the running build | ||
|
||
// Append the failure reason to the description | ||
for (BuildProblemData failureReason : sRunningBuild.getFailureReasons()) | ||
description.append("\n").append(failureReason.getDescription()); | ||
|
||
// Check the length of the description | ||
if (description.length() > 1800) { | ||
// Truncate the description if it is too long | ||
description = new StringBuilder(description.substring(0, 1800)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest to suffixx the build log with |
||
} | ||
|
||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildNumber(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please continue to use |
||
DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload(); | ||
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{ | ||
new DiscordEmbed( | ||
title, | ||
description, | ||
description.toString(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please indent this one more level. |
||
url, | ||
DiscordEmbedColor.RED, | ||
null, | ||
|
@@ -256,8 +271,8 @@ public void notifyBuildFailed(@NotNull SRunningBuild sRunningBuild, @NotNull Set | |
@Override | ||
public void notifyBuildFailedToStart(@NotNull SRunningBuild sRunningBuild, @NotNull Set<SUser> users) { | ||
String title = "Build failed to start"; | ||
String description = "The build with the ID " + sRunningBuild.getBuildId() + " has failed to start!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildId(); | ||
String description = "The build with the ID " + sRunningBuild.getBuildNumber() + " has failed to start!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildNumber(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please continue to use |
||
DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload(); | ||
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{ | ||
new DiscordEmbed( | ||
|
@@ -277,8 +292,8 @@ public void notifyBuildFailedToStart(@NotNull SRunningBuild sRunningBuild, @NotN | |
@Override | ||
public void notifyLabelingFailed(@NotNull Build build, @NotNull VcsRoot vcsRoot, @NotNull Throwable throwable, @NotNull Set<SUser> users) { | ||
String title = "Labeling failed"; | ||
String description = "Labeling of build with the ID " + build.getBuildId() + " has failed!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + build.getBuildId(); | ||
String description = "Labeling of build with the ID " + build.getBuildNumber() + " has failed!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + build.getBuildNumber(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please continue to use |
||
DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload(); | ||
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{ | ||
new DiscordEmbed( | ||
|
@@ -298,8 +313,8 @@ public void notifyLabelingFailed(@NotNull Build build, @NotNull VcsRoot vcsRoot, | |
@Override | ||
public void notifyBuildFailing(@NotNull SRunningBuild sRunningBuild, @NotNull Set<SUser> users) { | ||
String title = "Build is failing"; | ||
String description = "The build with the ID " + sRunningBuild.getBuildId() + " is failing!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildId(); | ||
String description = "The build with the ID " + sRunningBuild.getBuildNumber() + " is failing!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildNumber(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please continue to use |
||
DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload(); | ||
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{ | ||
new DiscordEmbed( | ||
|
@@ -319,8 +334,8 @@ public void notifyBuildFailing(@NotNull SRunningBuild sRunningBuild, @NotNull Se | |
@Override | ||
public void notifyBuildProbablyHanging(@NotNull SRunningBuild sRunningBuild, @NotNull Set<SUser> users) { | ||
String title = "Build is probably hanging"; | ||
String description = "The build with the ID " + sRunningBuild.getBuildId() + " is probably hanging!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildId(); | ||
String description = "The build with the ID " + sRunningBuild.getBuildNumber() + " is probably hanging!"; | ||
String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildNumber(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please continue to use |
||
DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload(); | ||
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{ | ||
new DiscordEmbed( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please continue to use
sRunningBuild.getBuildId();
here.The URL expects the build id. If the build number is customized in the settings, the URL won't work anymore.