forked from cake-contrib/Cake.Recipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cake-contrib#510) post to mastodon on successful publishing
- Loading branch information
Showing
8 changed files
with
130 additions
and
2 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
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
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
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,43 @@ | ||
public class MastodonReporter : SuccessReporter | ||
{ | ||
private MastodonCredentials _credentials; | ||
private string _messageTemplate; | ||
|
||
public MastodonReporter(MastodonCredentials credentials, string messageTemplate) | ||
{ | ||
_credentials = credentials; | ||
_messageTemplate = messageTemplate; | ||
} | ||
|
||
public override string Name { get; } = "Mastodon"; | ||
|
||
public override bool CanBeUsed | ||
{ | ||
get => !string.IsNullOrEmpty(_credentials.AccessToken) && | ||
!string.IsNullOrEmpty(_credentials.InstanceUrl); | ||
} | ||
|
||
|
||
public override void ReportSuccess(ICakeContext context, BuildVersion buildVersion) | ||
{ | ||
try | ||
{ | ||
context.Information("Sending message to Mastodon..."); | ||
|
||
var messageArguments = BuildParameters.MessageArguments(buildVersion); | ||
var message = string.Format(_messageTemplate, messageArguments); | ||
var idempotencyKey = Guid.NewGuid().ToString("d"); | ||
|
||
context.MastodonSendToot(_credentials.InstanceUrl, | ||
_credentials.AccessToken, | ||
message, | ||
idempotencyKey); | ||
|
||
context.Information("Message successfully sent."); | ||
} | ||
catch(Exception ex) | ||
{ | ||
context.Error("{0}", ex); | ||
} | ||
} | ||
} |
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
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
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
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