Exemplo n.º 1
0
        protected async Task <EventHandlerResult> processComment(ICommentPayload <T> webhookPayload)
        {
            var gradeCommand = new GradeCommentParser(webhookPayload.CommentBody);

            if (gradeCommand.IsMatch)
            {
                if (!await isAllowed(webhookPayload))
                {
                    return(await handleUserNotAllowed(webhookPayload));
                }

                var pr = await getPullRequest(webhookPayload);

                if (pr == null)
                {
                    return(await handleNotPr(webhookPayload));
                }

                await handleApprove(webhookPayload, pr);
                await handleStoreGrade(webhookPayload, gradeCommand, pr);

                await handleReaction(webhookPayload, ReactionType.Plus1);

                return(EventHandlerResult.ActionPerformed($"comment operation to grade done; grades: {string.Join(" ", gradeCommand.Grades)}"));
            }
            else
            {
                return(EventHandlerResult.NoActionNeeded("not recognized as command"));
            }
        }
Exemplo n.º 2
0
        private async Task handleStoreGrade(ICommentPayload <T> webhookPayload, GradeCommentParser gradeCommand, PullRequest pr)
        {
            var neptun = await getNeptun(webhookPayload.Repository.Id, pr.Head.Ref);

            Logger.LogInformation($"storing grades for {neptun}");
            if (gradeCommand.HasGrades)
            {
                await gradeStore.StoreGrade(
                    neptun : neptun,
                    repository : webhookPayload.Repository.FullName,
                    prNumber : pr.Number,
                    prUrl : pr.HtmlUrl,
                    actor : webhookPayload.CommentingUser,
                    origin : webhookPayload.CommentHtmlUrl,
                    results : gradeCommand.Grades);
            }
            else
            {
                await gradeStore.ConfirmAutoGrade(
                    neptun : neptun,
                    repository : webhookPayload.Repository.FullName,
                    prNumber : pr.Number,
                    prUrl : pr.HtmlUrl,
                    actor : webhookPayload.CommentingUser,
                    origin : webhookPayload.CommentHtmlUrl);
            }
        }
Exemplo n.º 3
0
        public void GradesAreParsed(string value, params double[] expectedGrades)
        {
            var actualGrades = new GradeCommentParser(value);

            Assert.AreEqual(expectedGrades.Length > 0, actualGrades.HasGrades);
            CollectionAssert.AreEqual(expectedGrades, actualGrades.Grades.ToList());
        }