< Summary

Information
Class: Orchestrator.Commands.Utility.UploadTransfers.UploadTransfersCommand.TransfersDocumentJson
Assembly: Orchestrator
File(s): /home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Utility/UploadTransfers/UploadTransfersCommand.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 122
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/Orchestrator/Commands/Utility/UploadTransfers/UploadTransfersCommand.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.FileProviders;
 3using Microsoft.Extensions.Logging;
 4using Spectre.Console.Cli;
 5using Spectre.Console;
 6using System.Text.Json;
 7using EHonda.KicktippAi.Core;
 8using Orchestrator.Infrastructure;
 9using Orchestrator.Infrastructure.Factories;
 10
 11namespace Orchestrator.Commands.Utility.UploadTransfers;
 12
 13public class UploadTransfersCommand : AsyncCommand<UploadTransfersSettings>
 14{
 15    private readonly IAnsiConsole _console;
 16    private readonly IFirebaseServiceFactory _firebaseServiceFactory;
 17    private readonly IFileProvider _fileProvider;
 18    private readonly ILogger<UploadTransfersCommand> _logger;
 19
 20    public UploadTransfersCommand(
 21        IAnsiConsole console,
 22        IFirebaseServiceFactory firebaseServiceFactory,
 23        [FromKeyedServices(ServiceRegistrationExtensions.TransfersDocumentsFileProviderKey)] IFileProvider fileProvider,
 24        ILogger<UploadTransfersCommand> logger)
 25    {
 26        _console = console;
 27        _firebaseServiceFactory = firebaseServiceFactory;
 28        _fileProvider = fileProvider;
 29        _logger = logger;
 30    }
 31
 32    protected override async Task<int> ExecuteAsync(CommandContext context, UploadTransfersSettings settings, Cancellati
 33    {
 34
 35        try
 36        {
 37            var docName = $"{settings.TeamAbbreviation.ToLowerInvariant()}-transfers.csv";
 38            _console.MarkupLine($"[green]Upload Transfers command initialized for document:[/] [yellow]{docName}[/]");
 39            _console.MarkupLine($"[blue]Using community context:[/] [yellow]{settings.CommunityContext}[/]");
 40            var competition = CompetitionResolver.ResolveCompetition(settings.Competition, settings.CommunityContext, se
 41            var repositoryCompetition = CompetitionResolver.ToRepositoryCompetitionArgument(competition);
 42            _console.MarkupLine($"[blue]Using competition:[/] [yellow]{competition}[/]");
 43            if (settings.Verbose) _console.MarkupLine("[dim]Verbose mode enabled[/]");
 44
 45            // JSON file path produced by Create-TransfersDocument.ps1 firebase mode
 46            var jsonPath = $"output/{settings.CommunityContext}/{docName}.json";
 47            var fileInfo = _fileProvider.GetFileInfo(jsonPath);
 48            if (!fileInfo.Exists)
 49            {
 50                _console.MarkupLine($"[red]Transfers document JSON not found:[/] {jsonPath}");
 51                _console.MarkupLine("[dim]Run Create-TransfersDocument.ps1 in firebase mode first.[/]");
 52                return 1;
 53            }
 54
 55            _console.MarkupLine($"[blue]Reading transfers document from:[/] {jsonPath}");
 56            using var stream = fileInfo.CreateReadStream();
 57            var transfersDoc = await JsonSerializer.DeserializeAsync<TransfersDocumentJson>(stream, new JsonSerializerOp
 58            if (transfersDoc == null)
 59            {
 60                _console.MarkupLine("[red]Failed to parse transfers document JSON[/]");
 61                return 1;
 62            }
 63
 64            if (settings.Verbose)
 65            {
 66                _console.MarkupLine($"[dim]Document Name: {transfersDoc.DocumentName}[/]");
 67                _console.MarkupLine($"[dim]Community Context: {transfersDoc.CommunityContext}[/]");
 68                _console.MarkupLine($"[dim]Content length: {transfersDoc.Content.Length} characters[/]");
 69            }
 70
 71            // Create Firebase services using factory (factory handles env var loading)
 72            var contextRepo = _firebaseServiceFactory.CreateContextRepository(repositoryCompetition);
 73            var existing = await contextRepo.GetLatestContextDocumentAsync(transfersDoc.DocumentName, transfersDoc.Commu
 74            if (existing != null)
 75            {
 76                _console.MarkupLine($"[blue]Found existing transfers document '{transfersDoc.DocumentName}' (version {ex
 77                if (settings.Verbose)
 78                {
 79                    _console.MarkupLine("[dim]Checking for changes...[/]");
 80                }
 81            }
 82            else
 83            {
 84                _console.MarkupLine($"[blue]No existing transfers document found - will create version 0[/]");
 85            }
 86
 87            var savedVersion = await contextRepo.SaveContextDocumentAsync(
 88                transfersDoc.DocumentName,
 89                transfersDoc.Content,
 90                transfersDoc.CommunityContext);
 91
 92            if (existing != null && savedVersion == null)
 93            {
 94                _console.MarkupLine($"[green]✓ Content unchanged - transfers document remains at version {existing.Versi
 95            }
 96            else if (existing != null)
 97            {
 98                _console.MarkupLine($"[green]✓ Content changed - created new version {savedVersion}[/]");
 99            }
 100            else
 101            {
 102                _console.MarkupLine($"[green]✓ Created transfers document version {savedVersion}[/]");
 103            }
 104
 105            return 0;
 106        }
 107        catch (Exception ex)
 108        {
 109            _logger.LogError(ex, "Error in upload-transfers command");
 110            _console.MarkupLine($"[red]Error: {ex.Message}[/]");
 111            return 1;
 112        }
 113    }
 114
 115    private class TransfersDocumentJson
 116    {
 1117        public string DocumentName { get; set; } = string.Empty;
 1118        public string Content { get; set; } = string.Empty;
 1119        public string Description { get; set; } = string.Empty;
 1120        public string CommunityContext { get; set; } = string.Empty;
 121    }
 122}

Methods/Properties

.ctor()