Пример #1
0
        private static MattermostMessage GetMessagePullRequestReviewComment(PullRequestReviewCommentEvent payload)
        {
            var retVal = BaseMessageForRepo(payload.repository.full_name);
            MattermostAttachment att = null;

            var repoMd   = $"[{payload.repository.full_name}]({payload.repository.html_url})";
            var commitMd = $"[`{payload.comment.commit_id.Substring(0, 7)}`]({payload.comment.html_url})";
            var userMd   = $"[{payload.sender.login}]({payload.sender.html_url})";
            var titleMd  =
                $"[#{payload.pull_request.number} {payload.pull_request.title}]({payload.pull_request.html_url})";

            switch (payload.action)
            {
            case "created":
                retVal.Text = $"{userMd} commented on {titleMd}:{commitMd}  in {repoMd}";
                att         = new MattermostAttachment
                {
                    Text = payload.comment.body
                };

                break;

            default:
                throw new NotImplementedException($"Unhandled Event action: {payload.action}");
            }

            retVal.Attachments = new List <MattermostAttachment>
            {
                att
            };

            return(retVal);
        }
Пример #2
0
        private static MattermostMessage GetMessageCommitComment(CommitCommentEvent payload)
        {
            var retVal = BaseMessageForRepo(payload.repository.full_name);
            MattermostAttachment att = null;

            var repoMd   = $"[{payload.repository.full_name}]({payload.repository.html_url})";
            var commitMd = $"[`{payload.comment.commit_id.Substring(0, 7)}`]({payload.comment.html_url})";
            var userMd   = $"[{payload.sender.login}]({payload.sender.html_url})";

            if (payload.action == "created")
            {
                retVal.Text = $"{userMd} commented on {commitMd} in {repoMd}";
                att         = new MattermostAttachment
                {
                    Text = payload.comment.body
                };
            }
            else
            {
                throw new NotImplementedException($"Unhandled Event action: {payload.action}");
            }

            retVal.Attachments = new List <MattermostAttachment>
            {
                att
            };

            return(retVal);
        }
Пример #3
0
        private static MattermostMessage GetMessagePush(PushEvent payload)
        {
            if (!payload.deleted && !payload.forced)
            {
                if (!payload._ref.StartsWith("refs/tags/"))
                {
                    var retVal = BaseMessageForRepo(payload.repository.full_name);
                    MattermostAttachment att = null;


                    if (payload.commits.Count > 0)
                    {
                        var multi    = payload.commits.Count > 1 ? "s" : "";
                        var userMd   = $"[{payload.sender.login}]({payload.sender.html_url})";
                        var branch   = payload._ref.Replace("refs/heads/", "");
                        var branchMd = $"[{branch}]({payload.repository.html_url}/tree/{branch})";
                        var repoMd   = $"[{payload.repository.full_name}]({payload.repository.html_url})";
                        retVal.Text =
                            $"{userMd} pushed {payload.commits.Count} commit{multi} to {branchMd} on {repoMd}";

                        att = new MattermostAttachment();

                        foreach (var commit in payload.commits)
                        {
                            var sanitised = Regex.Replace(commit.message, @"\r\n?|\n", " ");
                            att.Text +=
                                $"- [`{commit.id.Substring(0, 8)}`]({commit.url}) - {sanitised}\n";
                        }
                    }
                    else
                    {
                        throw new WarningException("No commits in payload, no need to send message.");
                    }

                    retVal.Attachments = new List <MattermostAttachment>
                    {
                        att
                    };

                    return(retVal);
                }
            }

            throw new NotImplementedException($"Unhandled Push Type: {payload._ref}");
        }
Пример #4
0
        private static MattermostMessage GetMessageIssueComment(IssueCommentEvent payload)
        {
            var retVal = BaseMessageForRepo(payload.repository.full_name);
            MattermostAttachment att = null;
            var repoMd  = $"[{payload.repository.full_name}]({payload.repository.html_url})";
            var titleMd = $"[#{payload.issue.number} {payload.issue.title}]({payload.issue.html_url})";
            var userMd  = $"[{payload.sender.login}]({payload.sender.html_url})";

            if (payload.action == "created")
            {
                retVal.Text = $"{userMd} commented on issue {titleMd} in {repoMd}";
                if (!string.IsNullOrEmpty(payload.comment.body))
                {
                    att = new MattermostAttachment
                    {
                        Text = payload.comment.body
                    }
                }
                ;
            }
            else
            {
                throw new NotImplementedException($"Unhandled Event action: {payload.action}");
            }

            if (att != null)
            {
                retVal.Attachments = new List <MattermostAttachment>
                {
                    att
                }
            }
            ;

            return(retVal);
        }
Пример #5
0
        private static MattermostMessage GetMessagePullRequest(PullRequestEvent payload)
        {
            var retVal = BaseMessageForRepo(payload.repository.full_name);
            MattermostAttachment att = null;

            var repoMd  = $"[{payload.repository.full_name}]({payload.repository.html_url})";
            var titleMd =
                $"[#{payload.pull_request.number} {payload.pull_request.title}]({payload.pull_request.html_url})";
            var userMd = $"[{payload.sender.login}]({payload.sender.html_url})";

            switch (payload.action)
            {
            case "opened":
                retVal.Text = $"{userMd} opened a [new pull request]({payload.pull_request.html_url}) in {repoMd}";

                if (!string.IsNullOrEmpty(payload.pull_request.body))
                {
                    att = new MattermostAttachment
                    {
                        Title     = $"#{payload.pull_request.number} {payload.pull_request.title}",
                        TitleLink = new Uri(payload.pull_request.html_url),
                        Text      = payload.pull_request.body
                    }
                }
                ;
                break;

            case "labeled":
                retVal.Text = $"{userMd} added label: `{payload.label.name}` to {titleMd} in {repoMd}";
                break;

            case "unlabeled":
                retVal.Text = $"{userMd} removed label: `{payload.label.name}` from {titleMd} in {repoMd}";
                break;

            case "closed":
                retVal.Text = $"{userMd} closed pull request {titleMd} in {repoMd}";
                break;

            case "assigned":
                var asignMd = $"[{payload.assignee.login}]({payload.assignee.html_url})";
                retVal.Text = $"{userMd} assigned {asignMd} to {titleMd} in {repoMd}";
                break;

            case "unassigned":
                var unasignMd = $"[{payload.assignee.login}]({payload.assignee.html_url})";
                retVal.Text = $"{userMd} unassigned {unasignMd} from {titleMd} in {repoMd}";
                break;

            default:
                throw new NotImplementedException($"Unhandled Event action: {payload.action}");
            }

            if (att != null)
            {
                retVal.Attachments = new List <MattermostAttachment>
                {
                    att
                }
            }
            ;

            return(retVal);
        }
Пример #6
0
        private static MattermostMessage GetMessagePullRequestReview(PullRequestReviewEvent payload)
        {
            var retVal = BaseMessageForRepo(payload.repository.full_name);
            MattermostAttachment att = null;

            var repoMd  = $"[{payload.repository.full_name}]({payload.repository.html_url})";
            var titleMd =
                $"[#{payload.pull_request.number} {payload.pull_request.title}]({payload.pull_request.html_url})";
            var userMd     = $"[{payload.sender.login}]({payload.sender.html_url})";
            var reviewerMd = $"[{payload.review.user.login}]({payload.review.user.html_url})";

            switch (payload.action)
            {
            case "submitted":
                switch (payload.review.state)
                {
                //case "commented":
                //retVal.Text = $"{userMd} created a [review]({payload.review.html_url}) on {titleMd} in {repoMd}";
                //break;
                case "approved":
                    retVal.Text = $"{userMd} [approved]({payload.review.html_url}) {titleMd} in {repoMd}";
                    break;

                case "changes_requested":
                    retVal.Text =
                        $"{userMd} [requested changes]({payload.review.html_url}) on {titleMd} in {repoMd}";
                    break;

                default:
                    retVal.Text =
                        $"{userMd} submitted a [review]({payload.review.html_url}) on {titleMd} in {repoMd}";
                    break;
                }

                if (!string.IsNullOrEmpty(payload.review.body))
                {
                    att = new MattermostAttachment
                    {
                        Text = payload.review.body
                    }
                }
                ;
                break;

            case "dismissed":
                retVal.Text =
                    $"A [review]({payload.review.html_url}) by {reviewerMd} was dismissed on {titleMd} in {repoMd}";
                break;

            default:
                throw new NotImplementedException($"Unhandled Event action: {payload.action}");
            }

            if (att != null)
            {
                retVal.Attachments = new List <MattermostAttachment>
                {
                    att
                }
            }
            ;

            return(retVal);
        }