コード例 #1
0
        public int Process(DirectoryPath root, DirectoryPath repository, string version)
        {
            _log.Write("Processing packages.config files...");
            var packageProcessor = new PackageProcessor(_filesystem, _environment, _log);
            var processed        = packageProcessor.Process(root, repository, version);

            if (processed == 0)
            {
                _log.Error("Nothing was updated. Probably a newer repository.");
            }

            return(processed);
        }
コード例 #2
0
ファイル: UpdateCommand.cs プロジェクト: cake-contrib/Cup
        public override int Execute(UpdateSettings settings, ILookup <string, string> remaining)
        {
            // Get the user.
            var client = new GitHubClient(new ProductHeaderValue("Cake-Addin-Updater"))
            {
                Credentials = new Octokit.Credentials(settings.Token)
            };

            // Validate the provided version.
            if (!System.Version.TryParse(settings.Version, out var _))
            {
                _log.Error("The provided version is not valid.");
                return(1);
            }

            // Get the root.
            var root = settings.WorkingDirectory ?? new DirectoryPath(".");

            root = root.MakeAbsolute(_environment);

            // Get the user.
            var user      = client.User.Get(settings.User).Result;
            var userEmail = GetUserEmail(client);

            // Get the repository parts.
            var info = GetRepositoryInfo(settings);

            // Does the directory contains anything?
            var path = CreateRepositoryDirectory(root, info);

            if (_filesystem.Directory.GetFiles(path, "*.*", SearchScope.Current).Any() ||
                _filesystem.Directory.GetDirectories(path, "*.*", SearchScope.Current).Any())
            {
                _log.Error($"Repository '{path}' already exist on disk.");
                _log.Write("Remove it and try again.");
                return(1);
            }

            // Fork the repository.
            var repository = ForkRepository(client, info);

            if (string.IsNullOrWhiteSpace(repository?.Name))
            {
                _log.Error("Could not fork repository.");
                return(1);
            }

            // Get the default branch.
            var defaultBranch = repository.DefaultBranch;

            if (string.IsNullOrWhiteSpace(defaultBranch))
            {
                _log.Error("Could not get default branch for repository.");
                return(1);
            }

            // Clone the repository at the specified path.
            _log.Write("Cloning repository...");
            GitRepository.Clone($"https://github.com/{settings.User}/{repository.Name}", path.FullPath, new CloneOptions
            {
                Checkout = true
            });

            using (var gitRepository = new GitRepository(path.FullPath))
            {
                // Create a new branch in the repository.
                _log.Write("Creating branch...");
                gitRepository.CreateBranch($"feature/cake-{settings.Version}");
                _log.Write("Checking out branch...");
                GitCommands.Checkout(gitRepository, $"feature/cake-{settings.Version}");

                // Update all package references in project.
                var processed = _processor.Process(root, path, settings.Version);
                if (processed == 0)
                {
                    _log.Error("Nothing was updated. Probably a newer repository.");
                    return(1);
                }

                // Commit?
                if (settings.Commit)
                {
                    _log.Write("Staging changes...");
                    GitCommands.Stage(gitRepository, "*");

                    var status = gitRepository.RetrieveStatus();
                    if (status.Any())
                    {
                        _log.Write("Committing changes...");
                        var author = new GitSignature(user.Name, userEmail, DateTime.Now);
                        gitRepository.Commit($"Updated to Cake {settings.Version}.", author, author);

                        // Push?
                        if (settings.Push)
                        {
                            // Build everything first.
                            if (!BuildProject(path))
                            {
                                return(1);
                            }

                            // Push the commit.
                            if (!Push(settings, path))
                            {
                                return(1);
                            }

                            // Create a pull request?
                            if (settings.OpenPullRequest)
                            {
                                CreatePullRequest(client, settings, info);
                            }
                        }
                    }
                    else
                    {
                        _log.Error("No changes in repository. Already updated?");
                    }
                }
            }

            return(0);
        }