<commit_before>﻿using Azure.Sdk.Tools.CheckEnforcer.Configuration;
using Azure.Sdk.Tools.CheckEnforcer.Integrations.GitHub;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Microsoft.Identity.Client;
using Octokit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Azure.Sdk.Tools.CheckEnforcer.Handlers
{
    public class IssueCommentHandler : Handler<IssueCommentPayload>
    {
        public IssueCommentHandler(IGlobalConfigurationProvider globalConfigurationProvider, IGitHubClientProvider gitHubClientProvider, IRepositoryConfigurationProvider repositoryConfigurationProvider, ILogger logger) : base(globalConfigurationProvider, gitHubClientProvider, repositoryConfigurationProvider, logger)
        {
        }

        protected override async Task HandleCoreAsync(HandlerContext<IssueCommentPayload> context, CancellationToken cancellationToken)
        {
            var payload = context.Payload;
            var installationId = payload.Installation.Id;
            var repositoryId = payload.Repository.Id;
            var comment = payload.Comment.Body.ToLower().Trim();
            var issueId = payload.Issue.Number;

            // Bail early if we aren't even a check enforcer comment. Reduces exception noise.
            if (!comment.StartsWith("/check-enforcer")) return;

            var pullRequest = await context.Client.PullRequest.Get(repositoryId, issueId);
            var sha = pullRequest.Head.Sha;

            switch (comment)
            {
                case "/check-enforcer override":
                    await SetSuccessAsync(context.Client, repositoryId, sha, cancellationToken);
                    break;

                case "/check-enforcer reset":
                    await CreateCheckAsync(context.Client, installationId, repositoryId, sha, true, cancellationToken);
                    break;

                case "/check-enforcer evaluate":
                    await EvaluatePullRequestAsync(context.Client, installationId, repositoryId, sha, cancellationToken);
                    break;

                default:
                    this.Logger.LogInformation("Unrecognized command: {comment}", comment);
                    break;
            }<commit_msg>Combine make reset and evaluate do the same thing. (#665)<commit_after>﻿using Azure.Sdk.Tools.CheckEnforcer.Configuration;
using Azure.Sdk.Tools.CheckEnforcer.Integrations.GitHub;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Microsoft.Identity.Client;
using Octokit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Azure.Sdk.Tools.CheckEnforcer.Handlers
{
    public class IssueCommentHandler : Handler<IssueCommentPayload>
    {
        public IssueCommentHandler(IGlobalConfigurationProvider globalConfigurationProvider, IGitHubClientProvider gitHubClientProvider, IRepositoryConfigurationProvider repositoryConfigurationProvider, ILogger logger) : base(globalConfigurationProvider, gitHubClientProvider, repositoryConfigurationProvider, logger)
        {
        }

        protected override async Task HandleCoreAsync(HandlerContext<IssueCommentPayload> context, CancellationToken cancellationToken)
        {
            var payload = context.Payload;
            var installationId = payload.Installation.Id;
            var repositoryId = payload.Repository.Id;
            var comment = payload.Comment.Body.ToLower().Trim();
            var issueId = payload.Issue.Number;

            // Bail early if we aren't even a check enforcer comment. Reduces exception noise.
            if (!comment.StartsWith("/check-enforcer")) return;

            var pullRequest = await context.Client.PullRequest.Get(repositoryId, issueId);
            var sha = pullRequest.Head.Sha;

            switch (comment)
            {
                case "/check-enforcer override":
                    await SetSuccessAsync(context.Client, repositoryId, sha, cancellationToken);
                    break;

                case "/check-enforcer reset":
                    await CreateCheckAsync(context.Client, installationId, repositoryId, sha, true, cancellationToken);
                    await EvaluatePullRequestAsync(context.Client, installationId, repositoryId, sha, cancellationToken);
                    break;

                case "/check-enforcer evaluate":
                    await CreateCheckAsync(context.Client, installationId, repositoryId, sha, true, cancellationToken);
                    await EvaluatePullRequestAsync(context.Client, installationId, repositoryId, sha, cancellationToken);
                    break;

                default:
                    this.Logger.LogInformation("Unrecognized command: {comment}", comment);
                    break;
            }
{'fraction_non_alphanumeric': 0.07585513078470825, 'fraction_numerical': 0.0006036217303822937, 'mean_word_length': 2.7602118003025717, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4048441', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1135, 'n_words': 278}