Exemple #1
0
 private void PushKeys(LocalizationDataManager localizationDataManager)
 {
     foreach (var configLocale in Config.Locales)
     {
         PushForLocale(configLocale, localizationDataManager);
     }
 }
Exemple #2
0
        private void PushForLocale(LocaleInfo locale, LocalizationDataManager localizationDataManager)
        {
            var client = GetPhraseAppClient();

            var localizationNamespacesToPush = localizationDataManager.GetNamespaces(locale.Name).Where(ns => ns.DoesHaveData());

            var localeData = client.Pull(locale.Id);

            foreach (var namespaceToPush in localizationNamespacesToPush)
            {
                var addedKeys = namespaceToPush.GetAddedKeys(localeData);

                if (!addedKeys.Any())
                {
                    Console.WriteLine($"Nothing to push in namespace {namespaceToPush.Name}: {namespaceToPush.DataFilePath}");
                    continue;
                }

                Console.WriteLine($"Pushing {namespaceToPush.Name}: {namespaceToPush.DataFilePath}");

                namespaceToPush.CheckData();

                client.Push(
                    locale.Id,
                    namespaceToPush.Name,
                    namespaceToPush.DataFilePath);
            }
        }
        private void PullForLocale(LocaleInfo locale, LocalizationDataManager localizationDataManager)
        {
            var client = GetPhraseAppClient();

            var sourceLocalizationData = client.Pull(locale.Id);

            foreach (var namespaceInfo in localizationDataManager.GetNamespaces(locale.Name))
            {
                namespaceInfo.ApplyNewTranslations(sourceLocalizationData);
            }
        }
Exemple #4
0
        protected override void ExecuteCore()
        {
            var referenceLocale         = Config.GetReferenceLocale();
            var localizationDataManager = new LocalizationDataManager(referenceLocale.Name, Config.WorkingDirectory);

            var client = GetPhraseAppClient();

            Console.WriteLine("Performing pull from phraseapp for diff check");
            var referenceLocaleData = client.Pull(referenceLocale.Id);

            var diffResult = CheckKeysDiff(localizationDataManager, referenceLocale, referenceLocaleData);

            RemoveKeys(client, diffResult.RemovedKeys);
            PushKeys(localizationDataManager);
            NotifyAboutNewKeys(client, diffResult.AddedKeys);
        }
Exemple #5
0
        private static (IEnumerable <string> AddedKeys, IEnumerable <string> RemovedKeys) CheckKeysDiff(
            LocalizationDataManager localizationDataManager,
            LocaleInfo locale,
            IReadOnlyDictionary <string, string> localeData)
        {
            var addedKeys   = new List <string>();
            var removedKeys = new List <string>();

            Console.WriteLine("Performing diff check");
            foreach (var localizationNamespace in localizationDataManager.GetNamespaces(locale.Name))
            {
                var addedKeysToCurrentNamespace     = localizationNamespace.GetAddedKeys(localeData);
                var removedKeysFromCurrentNamespace = localizationNamespace.RemovedKeys(localeData);

                addedKeys.AddRange(addedKeysToCurrentNamespace);
                removedKeys.AddRange(removedKeysFromCurrentNamespace);
            }

            return(addedKeys, removedKeys);
        }
        protected override void ExecuteCore()
        {
            var localizationDataManager = new LocalizationDataManager(Config.GetReferenceLocale().Name, Config.WorkingDirectory);

            Directory.SetCurrentDirectory(Config.WorkingDirectory);

            foreach (var configLocale in Config.Locales)
            {
                PullForLocale(configLocale, localizationDataManager);
            }

            var gitClient = GetGitHubClient();

            var hasChanges = gitClient.HasChanges();

            if (!hasChanges)
            {
                Console.WriteLine("There are no changes in translations, exiting");
                return;
            }

            var branchName = $"LocalizationPull{DateTime.Now.Ticks}";

            gitClient.CommitAllChangesToBranchAndPush(branchName, "fix: localization (automatic integration commit)");

            string pullRequestNumber   = null;
            var    isPullRequestMerged = false;

            var waitCount = 0;

            try
            {
                var createPullRequestResponse = gitClient.CreatePullRequest(branchName);
                pullRequestNumber = createPullRequestResponse.Number;

                while (true)
                {
                    var pullRequestStatus = gitClient.GetPullRequestStatus(createPullRequestResponse);

                    var shouldWait = ProcessPullRequestStatusAndGetShouldWait(
                        gitClient,
                        pullRequestStatus,
                        createPullRequestResponse.Number,
                        createPullRequestResponse.Head.Sha);

                    if (!shouldWait)
                    {
                        isPullRequestMerged = true;
                        break;
                    }

                    if (waitCount > TotalWaitsLimit)
                    {
                        throw new InvalidOperationException(
                                  $"Have waited for {gitClient.GetPullRequestLink(pullRequestNumber)} for too long");
                    }

                    waitCount++;
                    Thread.Sleep(TimeSpan.FromMinutes(1));
                }
            }
            finally
            {
                if (pullRequestNumber != null && !isPullRequestMerged)
                {
                    gitClient.ClosePullRequest(pullRequestNumber);
                }

                gitClient.DeleteBranch(branchName);
            }
        }