<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Octopus.Client;

namespace DeployStatus.ApiClients
{
    public class OctopusClient
    {
        private readonly OctopusRepository repository;
        private readonly Uri serverUri;
        
        public OctopusClient(OctopusApiConfiguration octopusApiConfiguration)
        {
            repository = new OctopusRepository(new OctopusServerEndpoint(octopusApiConfiguration.ServerUri, octopusApiConfiguration.ApiKey));
            serverUri = new Uri(octopusApiConfiguration.ServerUri);
        }

        public IEnumerable<OctopusEnvironmentInfo> GetEnvironments()
        {
            var swanSystem = repository.Projects.FindByName("SwanSystem");
            var dashBoardResourceResult = repository.Dashboards.GetDynamicDashboard(new[] { swanSystem.Id }, new string[] { });

            foreach (var dashboardItemResource in dashBoardResourceResult.Items)
            {
                var environment = dashBoardResourceResult.Environments.First(x => x.Id == dashboardItemResource.EnvironmentId);
                var release = repository.Releases.Get(dashboardItemResource.ReleaseId);
                var task = repository.Tasks.Get(dashboardItemResource.TaskId);
                var events = repository.Events.List(regardingDocumentId: dashboardItemResource.DeploymentId);<commit_msg>do not include environments containing disabled machines in the dashboard<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Octopus.Client;

namespace DeployStatus.ApiClients
{
    public class OctopusClient
    {
        private readonly OctopusRepository repository;
        private readonly Uri serverUri;
        
        public OctopusClient(OctopusApiConfiguration octopusApiConfiguration)
        {
            repository = new OctopusRepository(new OctopusServerEndpoint(octopusApiConfiguration.ServerUri, octopusApiConfiguration.ApiKey));
            serverUri = new Uri(octopusApiConfiguration.ServerUri);
        }

        public IEnumerable<OctopusEnvironmentInfo> GetEnvironments()
        {
            var swanSystem = repository.Projects.FindByName("SwanSystem");
            var dashBoardResourceResult = repository.Dashboards.GetDynamicDashboard(new[] { swanSystem.Id }, new string[] { });

            foreach (var dashboardItemResource in dashBoardResourceResult.Items)
            {
                var environment = dashBoardResourceResult.Environments.First(x => x.Id == dashboardItemResource.EnvironmentId);

                var machines = repository.Machines.FindMany(x => x.EnvironmentIds.Contains(environment.Id));

                if (machines.Any(x => x.IsDisabled))
                    continue;

                var release = repository.Releases.Get(dashboardItemResource.ReleaseId);
                var task = repository.Tasks.Get(dashboardItemResource.TaskId);
                var events = repository.Events.List(regardingDocumentId: dashboardItemResource.DeploymentId);
{'fraction_non_alphanumeric': 0.07466138090518665, 'fraction_numerical': 0.0, 'mean_word_length': 3.1650618982118295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3007859', 'n_tokens_mistral': 757, 'n_tokens_neox': 707, 'n_words': 144}