public void Execute(JObject request, IEnumerable <ISlackAction> actions) { if (request.Get <string>(x => x.action) != "review_requested") { return; } ActionUtils.ParsePullRequestDefaultFields(request, out var prHtmlUrl, out var prTittle); var reviewers = request.Get <JArray>(x => x.pull_request.requested_reviewers) .Select(x => x["login"] ?? throw new InvalidOperationException($"Missing pull_request.requested_reviewers.login")) .Concat(request.Get <JArray>(x => x.pull_request.requested_teams) .Select(x => x["name"] ?? throw new InvalidOperationException($"Missing pull_request.requested_teams.name"))); actions .ToList() .ForEach(action => { this.logger.LogInformation($"Sending message to '{action.Channel}'"); this.slack.Send(action.Channel, new SlackMessageModel($"Review request for pull request '{prTittle}'", prHtmlUrl) { Text = $"Review is requested from {string.Join(", ", reviewers)}" }); }); }
public void Execute(JObject request, IEnumerable <ISlackAction> actions) { if (request.Get(x => x.action) != "opened") { return; } ActionUtils.ParsePullRequestDefaultFields(request, out var prHtmlUrl, out var prTittle); var draft = request.Get(x => x.pull_request.draft); var draftText = draft == "True" ? "draft " : ""; var color = draft == "True" ? "#7a7a7a" : "warning"; actions .ToList() .ForEach(action => { this.logger.LogInformation($"Sending message to '{action.Channel}'"); this.slack.Send(action.Channel, new SlackMessageModel($"New {draftText}pull request '{prTittle}'", prHtmlUrl) { Color = color }); }); }
public void Execute(JObject request, IEnumerable <ISlackAction> actions) { if (request.Get <string>(x => x.action) != "labeled") { return; } ActionUtils.ParsePullRequestDefaultFields(request, out var prHtmlUrl, out var prTittle); var label = request.Get(x => x.label.name); actions .Where(slackJsonAction => slackJsonAction.Data == null || slackJsonAction.Data.Value <JArray>().Any(x => x.Value <string>() == label)) .ToList() .ForEach(action => { this.logger.LogInformation($"Sending message to '{action.Channel}'"); this.slack.Send(action.Channel, new SlackMessageModel($"New label '{label}' on pull request '{prTittle}'", prHtmlUrl) { Color = $"#{request.Get(x => x.label.color)}" }); }); }
public void Execute(JObject request, IEnumerable <ISlackAction> actions) { if (request.Get <string>(x => x.action) != "closed") { return; } ActionUtils.ParsePullRequestDefaultFields(request, out var prHtmlUrl, out var prTittle); var isMerged = !string.IsNullOrEmpty(request.Get(x => x.pull_request.merged_at)); const string gray = "#6F42C1"; var color = isMerged ? gray : "danger"; var title = isMerged ? $"'{prTittle}' merged to '{request.Get(x => x.pull_request.@base.@ref)}'" : $"Pull request '{prTittle}' closed."; actions .ToList() .ForEach(action => { this.logger.LogInformation($"Sending message to '{action.Channel}'"); this.slack.Send(action.Channel, new SlackMessageModel(title, prHtmlUrl) { Color = color }); }); }
public void Execute(JObject request, IEnumerable <ISlackAction> actions) { if (request.Get(x => x.action) != "submitted") { return; } ActionUtils.ParsePullRequestDefaultFields(request, out var prHtmlUrl, out var prTittle); var reviewState = request.Require(x => x.review.state); var reviewer = request.Require(x => x.review.user.login); var reviewBody = request.Require(x => x.review.body); var(color, verb) = GetStateVariable(reviewState); actions .ToList() .ForEach(action => { this.slack.Send(action.Channel, new SlackMessageModel($"Reviewer {reviewer} {verb} changes for '{prTittle}'", prHtmlUrl) { Color = color, Text = reviewBody }); }); }
public void Execute(JObject request, IEnumerable <ISlackAction> actions) { if (request.Get <string>(x => x.action) != "ready_for_review") { return; } ActionUtils.ParsePullRequestDefaultFields(request, out var prHtmlUrl, out var prTittle); actions .ToList() .ForEach(action => { this.logger.LogInformation($"Sending message to '{action.Channel}'"); this.slack.Send(action.Channel, new SlackMessageModel($"Pull request '{prTittle}' is ready for review", prHtmlUrl) { Color = "#439FE0" }); }); }