Beispiel #1
0
        private async Task <bool> Notify(BatonRequest batonRequest, ITurnContext <IMessageActivity> turnContext)
        {
            if (batonRequest == null || string.IsNullOrEmpty(batonRequest.UserId) || batonRequest.Conversation == null)
            {
                return(false);
            }

            await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(this.appId, batonRequest.Conversation, async(context, token) =>
                                                                             await this.SendYourBatonMessage(batonRequest.BatonName, context, token), default(CancellationToken));

            var test = await this.releaseService.GotBaton(batonRequest, this.appId, true, turnContext, default(CancellationToken));

            return(true);
        }
        public async Task Handler(string type, string comment, int pullRequest, ITurnContext <IMessageActivity> turnContext,
                                  CancellationToken cancellationToken)
        {
            var batons = await service.GetQueues();

            var batonFireObject = batons?.FirstOrDefault(x => x.Object.Name.Equals(type));

            var conversationReference = turnContext.Activity.GetConversationReference();

            var name = turnContext.Activity.From.Name.Replace(" | Redington", "").Replace(" | Godel", "");

            if (batonFireObject == null)
            {
                var baton = new BatonQueue(type);

                baton.Queue.Enqueue(new BatonRequest()
                {
                    UserName          = name,
                    UserId            = conversationReference.User.Id,
                    DateRequested     = DateTime.Now.ToLocalTime(),
                    DateReceived      = DateTime.Now.ToLocalTime(),
                    Conversation      = conversationReference,
                    BatonName         = type,
                    Comment           = comment,
                    PullRequestNumber = pullRequest
                });

                service.SaveQueue(baton);

                SendItsAllYours(turnContext, cancellationToken);
            }
            else
            {
                if (batonFireObject.Object.Queue.Count == 0)
                {
                    var baton = new BatonRequest()
                    {
                        UserName          = name,
                        UserId            = conversationReference.User.Id,
                        BatonName         = type,
                        DateRequested     = DateTime.Now,
                        DateReceived      = DateTime.Now,
                        Conversation      = conversationReference,
                        Comment           = comment,
                        PullRequestNumber = pullRequest
                    };

                    batonFireObject.Object.Queue.Enqueue(baton);

                    await service.UpdateQueue(batonFireObject);

                    this.SendItsAllYours(turnContext, cancellationToken);
                    await this.releaseService.GotBaton(baton, string.Empty, false, turnContext, cancellationToken);
                }
                else
                {
                    batonFireObject.Object.Queue.Enqueue(new BatonRequest()
                    {
                        UserName = name, UserId = conversationReference.User.Id, BatonName = type, DateRequested = DateTime.Now, Conversation = conversationReference, Comment = comment, PullRequestNumber = pullRequest
                    });

                    await service.UpdateQueue(batonFireObject);

                    await this.SendAddedToTheQueue(turnContext, cancellationToken);

                    //TODO - just use the queue you have
                    await showBatonService.SendBatons(turnContext, cancellationToken);
                }
            }
        }
Beispiel #3
0
        public async Task <bool> GotBaton(BatonRequest baton, string appId, bool notify, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (baton.PullRequestNumber == 0)
            {
                return(false);
            }

            var repoName = this.repoMapper.GetRepositoryNameFromBatonName(baton.BatonName);

            if (string.IsNullOrEmpty(repoName))
            {
                return(false);
            }

            var info = this.service.GetPRInfo(repoName, baton.PullRequestNumber);

            if (info == null)
            {
                if (notify)
                {
                    var reply1 = MessageFactory.Text("I cant find that pull request you going to have to do this on your own");

                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await SendMergeMessage(reply1, context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply1 = MessageFactory.Text("I cant find that pull request you going to have to do this on your own");
                    await turnContext.SendActivityAsync(reply1, cancellationToken);
                }

                return(false);
            }

            //if (notify)
            //{
            //    var reply2 = MessageFactory.Text(JsonConvert.SerializeObject(info));

            //    await ((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
            //        appId, baton.Conversation, async (context, token) =>
            //            await SendMergeMessage(reply2, context, token),
            //        default(CancellationToken));

            //    var reply1 = MessageFactory.Text("MergeState:"+ info.mergeable_state);

            //    await ((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
            //        appId, baton.Conversation, async (context, token) =>
            //            await SendMergeMessage(reply1, context, token),
            //        default(CancellationToken));

            //    await ((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
            //        appId, baton.Conversation, async (context, token) =>
            //            await SendYourBatonMessage(baton.BatonName, baton.PullRequestNumber, repoName, context, token),
            //        default(CancellationToken));
            //}
            //else
            //{
            //    var reply1 = MessageFactory.Text("merge status:" + info.mergeable_state);
            //    await turnContext.SendActivityAsync(reply1, cancellationToken);
            //}

            if (info.mergeable_state == "dirty")
            {
                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage($"### Cant merge. It requires attention", context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply = MessageFactory.Text($"### Cant merge. It requires attention");
                    _ = await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else if (info.mergeable_state == "blocked")
            {
                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage($"### Its not ready to go. Do you have enough reviews? Have any of the tests failed?", context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply = MessageFactory.Text($"### Its not ready to go. Do you have enough reviews? Have any of the tests failed?");
                    _ = await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else if (info.mergeable_state == "behind")
            {
                var reply = MessageFactory.Attachment(new List <Attachment>());
                reply.Attachments.Add(
                    cardCreator.GetUpdateYourBranchCardBeforeMerge(baton.BatonName, repoName, baton.PullRequestNumber)
                    .ToAttachment());

                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage(reply, context, token),
                        default(CancellationToken));
                }
                else
                {
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else if (info.mergeable_state == "clean")
            {
                var reply = MessageFactory.Attachment(new List <Attachment>());
                reply.Attachments.Add(
                    cardCreator.SquashAndMergeCard(baton.BatonName, repoName, baton.PullRequestNumber)
                    .ToAttachment());

                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage(reply, context, token),
                        default(CancellationToken));
                }
                else
                {
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else if (info.mergeable_state == "unknown")
            {
                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage($"The status is unknown can you run \"tryagain {baton.BatonName}\"", context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply = MessageFactory.Text($"The status is unknown can you run \"tryagain {baton.BatonName}\"");
                    _ = await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else
            {
                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage($"Something went wrong the merge status is {info.mergeable_state}", context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply = MessageFactory.Text($"Something went wrong the merge status is {info.mergeable_state}");
                    _ = await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }

            return(true);
        }
        public async Task GotBaton(BatonRequest baton, string appId, bool notify, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (baton.PullRequestNumber == 0)
            {
                return;
            }

            var repoName = this.repoMapper.GetRepositoryNameFromBatonName(baton.BatonName);

            if (string.IsNullOrEmpty(repoName))
            {
                return;
            }

            var info = this.service.GetPRInfo(repoName, baton.PullRequestNumber);

            if (notify)
            {
                var reply1 = MessageFactory.Text("MergeState:" + info.mergeable_state);

                await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                    appId, baton.Conversation, async(context, token) =>
                    await SendMergeMessage(reply1, context, token),
                    default(CancellationToken));

                await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                    appId, baton.Conversation, async(context, token) =>
                    await SendYourBatonMessage(baton.BatonName, baton.PullRequestNumber, repoName, context, token),
                    default(CancellationToken));
            }
            else
            {
                var reply1 = MessageFactory.Text("merge status:" + info.mergeable_state);
                await turnContext.SendActivityAsync(reply1, cancellationToken);
            }

            if (info.mergeable_state == "dirty")
            {
                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage($"### Cant merge. It requires attention", context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply = MessageFactory.Text($"### Cant merge. It requires attention");
                    _ = await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else if (info.mergeable_state == "blocked")
            {
                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage($"### Its not ready to go. Do you have enough reviews?", context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply = MessageFactory.Text($"### Its not ready to go. Do you have enough reviews?");
                    _ = await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else if (info.mergeable_state == "behind")
            {
                var reply = MessageFactory.Attachment(new List <Attachment>());
                reply.Attachments.Add(
                    cardCreator.GetUpdateYourBranchCardBeforeMerge(baton.BatonName, repoName, baton.PullRequestNumber)
                    .ToAttachment());

                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage(reply, context, token),
                        default(CancellationToken));
                }
                else
                {
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else if (info.mergeable_state == "clean")
            {
                var reply = MessageFactory.Attachment(new List <Attachment>());
                reply.Attachments.Add(
                    cardCreator.SquashAndMergeCard(baton.BatonName, repoName, baton.PullRequestNumber)
                    .ToAttachment());

                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage(reply, context, token),
                        default(CancellationToken));
                }
                else
                {
                    await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
            else
            {
                if (notify)
                {
                    await((BotAdapter)turnContext.Adapter).ContinueConversationAsync(
                        appId, baton.Conversation, async(context, token) =>
                        await this.SendMergeMessage($"Something went wrong the merge status is {info.mergeable_state}", context, token),
                        default(CancellationToken));
                }
                else
                {
                    var reply = MessageFactory.Text($"Something went wrong the merge status is {info.mergeable_state}");
                    _ = await turnContext.SendActivityAsync(reply, cancellationToken);
                }
            }
        }