<commit_before>﻿using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using GitHub.Api;
using GitHub.Models;
using LibGit2Sharp;

namespace GitHub.Services
{
    [Export(typeof(IRepositoryPublishService))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class RepositoryPublishService : IRepositoryPublishService
    {
        readonly IGitClient gitClient;
        readonly IVSGitServices vsGitServices;

        [ImportingConstructor]
        public RepositoryPublishService(IGitClient gitClient, IVSGitServices vsGitServices)
        {
            this.gitClient = gitClient;
            this.vsGitServices = vsGitServices;
        }

        public string LocalRepositoryName
        {
            get
            {
                if (!string.IsNullOrEmpty(vsGitServices.GetActiveRepo()?.Info?.WorkingDirectory))
                    return new DirectoryInfo(vsGitServices.GetActiveRepo().Info.WorkingDirectory).Name ?? "";
                return string.Empty;
            }
        }

        public IObservable<Octokit.Repository> PublishRepository(
            Octokit.NewRepository newRepository,
            IAccount account,
            IApiClient apiClient)
        {
            return Observable.Defer(() => apiClient.CreateRepository(newRepository, account.Login, account.IsUser)
                                     .Select(remoteRepo => new { RemoteRepo = remoteRepo, LocalRepo = vsGitServices.GetActiveRepo() }))
                             .SelectMany(async repo =>
                             {
                                 await gitClient.SetRemote(repo.LocalRepo, "origin", new Uri(repo.RemoteRepo.CloneUrl));
                                 await gitClient.Push(repo.LocalRepo, "master", "origin");
                                 await gitClient.Fetch(repo.LocalRepo, "origin");
                                 await gitClient.SetTrackingBranch(repo.LocalRepo, "master", "origin");
                                 return repo.RemoteRepo;
                             });
        }
    }
}
<commit_msg>Cached active repo value to avoid heavy operation repetition<commit_after>﻿using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using GitHub.Api;
using GitHub.Models;
using LibGit2Sharp;

namespace GitHub.Services
{
    [Export(typeof(IRepositoryPublishService))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class RepositoryPublishService : IRepositoryPublishService
    {
        readonly IGitClient gitClient;
        readonly IVSGitServices vsGitServices;

        [ImportingConstructor]
        public RepositoryPublishService(IGitClient gitClient, IVSGitServices vsGitServices)
        {
            this.gitClient = gitClient;
            this.vsGitServices = vsGitServices;
        }

        public string LocalRepositoryName
        {
            get
            {
                var activeRepo = vsGitServices.GetActiveRepo();
                if (!string.IsNullOrEmpty(activeRepo?.Info?.WorkingDirectory))
                    return new DirectoryInfo(activeRepo.Info.WorkingDirectory).Name ?? "";
                return string.Empty;
            }
        }

        public IObservable<Octokit.Repository> PublishRepository(
            Octokit.NewRepository newRepository,
            IAccount account,
            IApiClient apiClient)
        {
            return Observable.Defer(() => apiClient.CreateRepository(newRepository, account.Login, account.IsUser)
                                     .Select(remoteRepo => new { RemoteRepo = remoteRepo, LocalRepo = vsGitServices.GetActiveRepo() }))
                             .SelectMany(async repo =>
                             {
                                 await gitClient.SetRemote(repo.LocalRepo, "origin", new Uri(repo.RemoteRepo.CloneUrl));
                                 await gitClient.Push(repo.LocalRepo, "master", "origin");
                                 await gitClient.Fetch(repo.LocalRepo, "origin");
                                 await gitClient.SetTrackingBranch(repo.LocalRepo, "master", "origin");
                                 return repo.RemoteRepo;
                             });
        }
    }
}

{'fraction_non_alphanumeric': 0.08100623124855758, 'fraction_numerical': 0.00046157396722824835, 'mean_word_length': 1.9165545087483176, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3429428', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1062, 'n_words': 193}