<commit_before>﻿using Azure.Sdk.Tools.PipelineWitness.Entities.AzurePipelines;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Azure.Sdk.Tools.PipelineWitness.Services.FailureAnalysis
{
    public class MavenBrokenPipeFailureClassifier : IFailureClassifier
    {
        public MavenBrokenPipeFailureClassifier(VssConnection vssConnection)
        {
            this.vssConnection = vssConnection;
            buildClient = vssConnection.GetClient<BuildHttpClient>();
        }

        private VssConnection vssConnection;
        private BuildHttpClient buildClient;

        public async Task ClassifyAsync(FailureAnalyzerContext context)
        {
            var failedTasks = from r in context.Timeline.Records
                              where r.Result == TaskResult.Failed
                              where r.RecordType == "Task"
                              where r.Task.Name == "Maven"
                              where r.Log != null
                              select r;

            foreach (var failedTask in failedTasks)
            {
                var lines = await buildClient.GetBuildLogLinesAsync(
                    context.Build.Project.Id,
                    context.Build.Id,
                    failedTask.Log.Id
                    );<commit_msg>Fix null ref exception in Pipeline Witness. (#891)<commit_after>﻿using Azure.Sdk.Tools.PipelineWitness.Entities.AzurePipelines;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Azure.Sdk.Tools.PipelineWitness.Services.FailureAnalysis
{
    public class MavenBrokenPipeFailureClassifier : IFailureClassifier
    {
        public MavenBrokenPipeFailureClassifier(VssConnection vssConnection)
        {
            this.vssConnection = vssConnection;
            buildClient = vssConnection.GetClient<BuildHttpClient>();
        }

        private VssConnection vssConnection;
        private BuildHttpClient buildClient;

        public async Task ClassifyAsync(FailureAnalyzerContext context)
        {
            var failedTasks = from r in context.Timeline.Records
                                where r.Result == TaskResult.Failed
                                where r.RecordType == "Task"
                                where r.Task != null
                                where r.Task.Name == "Maven"
                                where r.Log != null
                                select r;

            foreach (var failedTask in failedTasks)
            {
                var lines = await buildClient.GetBuildLogLinesAsync(
                    context.Build.Project.Id,
                    context.Build.Id,
                    failedTask.Log.Id
                    );
{'fraction_non_alphanumeric': 0.06553559547571523, 'fraction_numerical': 0.000998003992015968, 'mean_word_length': 1.8421550094517958, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4270039', 'n_tokens_mistral': 733, 'n_tokens_neox': 709, 'n_words': 154}