Beispiel #1
0
        public async Task <bool> HandleUpdatedPullRequest(PullRequest update, string identifier)
        {
            var profilePicture = await GetAuthorProfilePictureUrl(update).ConfigureAwait(false);

            var payload = profilePicture != null
                ? SlackMessageFormatter.FormatUpdatedPullRequestWithImage(update, _configuration.Channel, identifier, profilePicture)
                : SlackMessageFormatter.FormatUpdatedPullRequest(update, _configuration.Channel, identifier);

            var success = await _client.UpdateMessage(payload).ConfigureAwait(false);

            return(success.Ok);
        }
Beispiel #2
0
        public async Task <string> NotifyNewPullRequest(PullRequest pr)
        {
            var profilePicture = await GetAuthorProfilePictureUrl(pr).ConfigureAwait(false);

            var payload = profilePicture != null
                ? SlackMessageFormatter.FormatNewPullRequestWithImage(pr, _configuration.Channel, profilePicture)
                : SlackMessageFormatter.FormatNewPullRequest(pr, _configuration.Channel);

            var success = await _client.PostMessage(payload);

            if (success.Ok)
            {
                return(success.Timestamp);
            }

            return(null);
        }
Beispiel #3
0
        public async Task <bool> NotifyFailedPullRequestBuild(Build build, string identifier)
        {
            SlackUserResponse pullRequestOwner = null;

            try
            {
                pullRequestOwner = await _client.GetUserByEmail(build.PullRequest.AuthorEmail).ConfigureAwait(false);
            }
            catch (SlackClientException e) when("users_not_found".Equals(e.Message, StringComparison.OrdinalIgnoreCase))
            {
                // When the user wasn't found we cannot notify them directly,
                // by leaving pullRequestOwner null the FormatFailedBuild will
                // create a generic message.
            }

            var payload = SlackMessageFormatter.FormatFailedBuild(build, _configuration.Channel, identifier, pullRequestOwner);
            var success = await _client.PostMessage(payload).ConfigureAwait(false);

            return(success.Ok);
        }