Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

refactor: Add error notify and change build version number. #41

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Copy link
Owner

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.

DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload();
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{
new DiscordEmbed(
Expand All @@ -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();
Copy link
Owner

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.

DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload();
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{
new DiscordEmbed(
Expand All @@ -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: ");
Copy link
Owner

Choose a reason for hiding this comment

The 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:

The build with the ID 1 has failed!

The build has failed with the following reason:
[reason]

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));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to suffixx the build log with ... if it is too long. This way, the user will know that this is not the entire log.

}

String url = this.sBuildServer.getRootUrl() + "/viewLog.html?buildId=" + sRunningBuild.getBuildNumber();
Copy link
Owner

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.

DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload();
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{
new DiscordEmbed(
title,
description,
description.toString(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent this one more level.

url,
DiscordEmbedColor.RED,
null,
Expand All @@ -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();
Copy link
Owner

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.

DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload();
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{
new DiscordEmbed(
Expand All @@ -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();
Copy link
Owner

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.

DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload();
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{
new DiscordEmbed(
Expand All @@ -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();
Copy link
Owner

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.

DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload();
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{
new DiscordEmbed(
Expand All @@ -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();
Copy link
Owner

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.

DiscordWebHookPayload discordWebHookPayload = new DiscordWebHookPayload();
discordWebHookPayload.setEmbeds(new DiscordEmbed[]{
new DiscordEmbed(
Expand Down