-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
547 additions
and
28 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
backend/ZiziBot.Application/Handlers/RestApis/Webhook/Partial/GitHubEventRequest.cs
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,41 @@ | ||
using Flurl; | ||
using Humanizer; | ||
using ZiziBot.Types.Vendor.GitHub; | ||
|
||
namespace ZiziBot.Application.Handlers.RestApis.Webhook.Partial; | ||
|
||
public class GitHubEventRequest : GitHubEvent, IWebhookRequestBase<bool> | ||
{ | ||
} | ||
|
||
public class GitHubEventHandler : IRequestHandler<GitHubEventRequest, WebhookResponseBase<bool>> | ||
{ | ||
public async Task<WebhookResponseBase<bool>> Handle(GitHubEventRequest request, CancellationToken cancellationToken) | ||
{ | ||
var response = new WebhookResponseBase<bool>(); | ||
|
||
var commits = request.Commits.ToList(); | ||
var commitCount = commits.Count; | ||
var repository = request.Repository; | ||
var branchName = request.Ref.Split('/').Last(); | ||
var treeUrl = repository.HtmlUrl.AppendPathSegment($"tree/{branchName}"); | ||
var commitsStr = "commit".ToQuantity(commitCount); | ||
|
||
var htmlMessage = HtmlMessage.Empty | ||
.Url(request.Compare, $"🏗 {commitsStr}").Bold($" to ").Url(repository.HtmlUrl, $"{repository.FullName}") | ||
.Text(":").Url(treeUrl, $"{branchName}") | ||
.Br().Br(); | ||
|
||
commits.ForEach(commit => { | ||
htmlMessage.Url(commit.Url.ToString(), commit.Id[..7]) | ||
.Text(": ") | ||
.TextBr($"{commit.Message} by {commit.Author.Name}"); | ||
}); | ||
|
||
await Task.Delay(0, cancellationToken); | ||
|
||
response.FormattedHtml = htmlMessage.ToString(); | ||
|
||
return response; | ||
} | ||
} |
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
Oops, something went wrong.