예제 #1
0
        private async Task AutoCommitAndPushSingleCakeFileAsync(string nugetFeedId, IFolder repositoryFolder, bool onlyIfNecessary, IErrorsAndInfos errorsAndInfos)
        {
            var files = GitUtilities.FilesWithUncommittedChanges(repositoryFolder).ToList();

            if (files.Count == 0)
            {
                if (onlyIfNecessary)
                {
                    return;
                }

                errorsAndInfos.Errors.Add(Properties.Resources.NoFileWithUncommittedChanges);
            }
            else if (files.Count != 1)
            {
                errorsAndInfos.Errors.Add(string.Format(Properties.Resources.ExactlyOneFileExpected, string.Join(", ", files)));
                return;
            }

            var file = files[0];

            if (!file.EndsWith(".cake", StringComparison.InvariantCultureIgnoreCase))
            {
                errorsAndInfos.Errors.Add(Properties.Resources.OnlyCakeFilesExpected);
                return;
            }

            var shortName = file.Substring(file.LastIndexOf('\\') + 1);

            var message = string.Format(Properties.Resources.AutoUpdateOfCakeFile, shortName);

            await AutoCommitAndPushAsync(nugetFeedId, repositoryFolder, files, onlyIfNecessary, message, true, errorsAndInfos);
        }
예제 #2
0
        public async Task <YesNoInconclusive> UpdateNugetPackagesInRepositoryAsync(IFolder repositoryFolder, IErrorsAndInfos errorsAndInfos)
        {
            using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(UpdateNugetPackagesInRepositoryAsync), Guid.NewGuid().ToString()))) {
                SimpleLogger.LogInformation("Determining files with uncommitted changes");
                var yesNoInconclusive = new YesNoInconclusive();
                var files             = GitUtilities.FilesWithUncommittedChanges(repositoryFolder);
                yesNoInconclusive.Inconclusive = files.Any(f => EndingsThatAllowReset.All(e => !f.EndsWith("." + e, StringComparison.InvariantCultureIgnoreCase)));
                yesNoInconclusive.YesNo        = false;
                if (yesNoInconclusive.Inconclusive)
                {
                    errorsAndInfos.Infos.Add("Not all files allow a reset");
                    SimpleLogger.LogInformation($"Returning {yesNoInconclusive}");
                    return(yesNoInconclusive);
                }

                SimpleLogger.LogInformation("Resetting repository");
                GitUtilities.Reset(repositoryFolder, GitUtilities.HeadTipIdSha(repositoryFolder), errorsAndInfos);
                if (errorsAndInfos.AnyErrors())
                {
                    errorsAndInfos.Infos.Add("Could not reset");
                    SimpleLogger.LogInformation($"Returning {yesNoInconclusive}");
                    return(yesNoInconclusive);
                }

                SimpleLogger.LogInformation("Searching for project files");
                var projectFileFullNames = Directory.GetFiles(repositoryFolder.SubFolder("src").FullName, "*.csproj", SearchOption.AllDirectories).ToList();
                if (!projectFileFullNames.Any())
                {
                    errorsAndInfos.Infos.Add("No project files found");
                    SimpleLogger.LogInformation($"Returning {yesNoInconclusive}");
                    return(yesNoInconclusive);
                }

                foreach (var projectFileFullName in projectFileFullNames)
                {
                    SimpleLogger.LogInformation($"Analyzing project file {projectFileFullName}");
                    var projectErrorsAndInfos = new ErrorsAndInfos();
                    if (!await UpdateNugetPackagesForProjectAsync(projectFileFullName, yesNoInconclusive.YesNo, projectErrorsAndInfos))
                    {
                        continue;
                    }

                    yesNoInconclusive.YesNo = true;
                }

                if (yesNoInconclusive.YesNo)
                {
                    errorsAndInfos.Infos.Add("No project was updated");
                    SimpleLogger.LogInformation($"Returning {yesNoInconclusive}");
                    return(yesNoInconclusive);
                }

                SimpleLogger.LogInformation("Resetting repository");
                GitUtilities.Reset(repositoryFolder, GitUtilities.HeadTipIdSha(repositoryFolder), errorsAndInfos);
                SimpleLogger.LogInformation($"Returning {yesNoInconclusive}");
                return(yesNoInconclusive);
            }
        }