Skip to content

Commit

Permalink
Update Slack message header
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Apr 6, 2021
1 parent b4c3184 commit 89d4d55
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions build/Build.Enterprise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#if ENTERPRISE

using System;
using System.Linq;
using Nuke.Common;
using Nuke.Common.CI.AppVeyor;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Git;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using Nuke.Enterprise.Auditing;
using Nuke.Enterprise.Notifications;

Expand All @@ -21,7 +24,7 @@ partial class Build : IHazSlackCredentials, IHazAzurePipelinesAccessToken, IHazG
{
string IHazGitHubAccessToken.AccessToken => GitHubToken;

public class DeploymentSlackNotificationAttribute : SlackNotificationAttribute
public class DeploymentSlackNotificationAttribute : CustomSlackNotificationAttribute
{
public override bool ReportBuildAlways => Host is AppVeyor { ProjectSlug: "nuke-deployment" };

Expand All @@ -33,7 +36,7 @@ public class DeploymentSlackNotificationAttribute : SlackNotificationAttribute
};
}

public class BuildStatusSlackNotificationAttribute : SlackNotificationAttribute
public class BuildStatusSlackNotificationAttribute : CustomSlackNotificationAttribute
{
public override bool ReportBuildAlways => true;
public override string ReceiverId => Host is GitHubActions _ or AppVeyor _ ? "U9S0MU8A3" : null;
Expand All @@ -52,5 +55,21 @@ public class BuildStatusSlackNotificationAttribute : SlackNotificationAttribute

public override bool ShouldNotify(NukeBuild build) => ((Build) build).GitRepository.IsOnDevelopBranch();
}

public abstract class CustomSlackNotificationAttribute : SlackNotificationAttribute
{
protected override string GetMessage(NukeBuild build, (string Sha, string Message, string Author, string Email, string UserId) lastCommitData)
{
var gitVersion = ((Build) build).GitVersion;
if (gitVersion == null)
return base.GetMessage(build, lastCommitData);

var header = new[] { (Text: $"#{gitVersion.FullSemVer}", BuildServer.CommonUrls.First().Url) }
.Concat(BuildServer.CommonUrls.Last())
.Select(x => $"*<{x.Url}|{x.Text}>*").Join(" | ");

return $":{GetIcon()}: {header}";
}
}
}
#endif

0 comments on commit 89d4d55

Please sign in to comment.