コード例 #1
0
        public async Task ApplyAnUpdate(
            IReadOnlyCollection <PackageUpdateSet> updates,
            NuGetSources sources)
        {
            if (!updates.Any())
            {
                return;
            }

            var filtered = await _selection
                           .Filter(updates, p => Task.FromResult(true));

            if (!filtered.Any())
            {
                _logger.Detailed("All updates were filtered out");
                return;
            }

            var candidate = filtered.First();

            var reporter = new ConsoleReporter();

            _logger.Minimal("Updating " + reporter.Describe(candidate));

            await _updateRunner.Update(candidate, sources);
        }
コード例 #2
0
ファイル: PackageUpdater.cs プロジェクト: josesimoes/NuKeeper
        private async Task <int> MakeUpdatePullRequests(
            IGitDriver git, RepositoryData repository,
            NuGetSources sources, SettingsContainer settings,
            IReadOnlyCollection <PackageUpdateSet> updates)
        {
            _logger.Normal(UpdatesLogger.OldVersionsToBeUpdated(updates));

            git.Checkout(repository.DefaultBranch);

            // branch
            var branchName = BranchNamer.MakeName(updates);

            _logger.Detailed($"Using branch name: '{branchName}'");
            git.CheckoutNewBranch(branchName);

            foreach (var updateSet in updates)
            {
                await _updateRunner.Update(updateSet, sources);

                var commitMessage = CommitWording.MakeCommitMessage(updateSet);
                git.Commit(commitMessage);
            }

            git.Push("nukeeper_push", branchName);

            var title = CommitWording.MakePullRequestTitle(updates);
            var body  = CommitWording.MakeCommitDetails(updates);
            await _gitHub.CreatePullRequest(repository, title, body, branchName,
                                            settings.SourceControlServerSettings.Labels);

            git.Checkout(repository.DefaultBranch);
            return(updates.Count);
        }
コード例 #3
0
        private async Task ApplyUpdates(IReadOnlyCollection <PackageUpdateSet> updates, IFolder workingFolder, NuGetSources sources)
        {
            await _solutionsRestore.CheckRestore(updates, workingFolder, sources);

            foreach (var update in updates)
            {
                _logger.Minimal("Updating " + Description.ForUpdateSet(update));

                await _updateRunner.Update(update, sources);
            }
        }
コード例 #4
0
        private async Task ApplyUpdates(IReadOnlyCollection <PackageUpdateSet> updates, IFolder workingFolder, NuGetSources sources)
        {
            await _solutionsRestore.CheckRestore(updates, workingFolder, sources);

            foreach (var update in updates)
            {
                var reporter = new ConsoleReporter();
                _logger.Minimal("Updating " + reporter.Describe(update));

                await _updateRunner.Update(update, sources);
            }
        }
コード例 #5
0
        private async Task <int> MakeUpdatePullRequests(
            IGitDriver git, RepositoryData repository,
            NuGetSources sources, SettingsContainer settings,
            IReadOnlyCollection <PackageUpdateSet> updates)
        {
            _logger.Normal(UpdatesLogger.OldVersionsToBeUpdated(updates));

            await git.Checkout(repository.DefaultBranch);

            // branch
            var branchWithChanges = BranchNamer.MakeName(updates, settings.BranchSettings.BranchNamePrefix);

            _logger.Detailed($"Using branch name: '{branchWithChanges}'");
            await git.CheckoutNewBranch(branchWithChanges);

            foreach (var updateSet in updates)
            {
                await _updateRunner.Update(updateSet, sources);

                var commitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(updateSet);
                await git.Commit(commitMessage);
            }

            await git.Push(repository.Remote, branchWithChanges);

            var title = _collaborationFactory.CommitWorder.MakePullRequestTitle(updates);
            var body  = _collaborationFactory.CommitWorder.MakeCommitDetails(updates);

            string qualifiedBranch;

            if (!repository.IsFork) //check if we are on a fork, if so qualify the branch name
            {
                qualifiedBranch = branchWithChanges;
            }
            else
            {
                qualifiedBranch = repository.Push.Owner + ":" + branchWithChanges;
            }

            var pullRequestRequest = new PullRequestRequest(qualifiedBranch, title, repository.DefaultBranch, settings.BranchSettings.DeleteBranchAfterMerge)
            {
                Body = body
            };

            await _collaborationFactory.CollaborationPlatform.OpenPullRequest(repository.Pull, pullRequestRequest, settings.SourceControlServerSettings.Labels);


            await git.Checkout(repository.DefaultBranch);

            return(updates.Count);
        }
コード例 #6
0
ファイル: PackageUpdater.cs プロジェクト: GeradeDev/NuKeeper
        public async Task <bool> MakeUpdatePullRequest(
            IGitDriver git,
            RepositoryData repository,
            PackageUpdateSet updateSet,
            NuGetSources sources,
            SourceControlServerSettings serverSettings)
        {
            try
            {
                _logger.Minimal(UpdatesLogger.OldVersionsToBeUpdated(updateSet));

                git.Checkout(repository.DefaultBranch);

                // branch
                var branchName = BranchNamer.MakeName(updateSet);
                _logger.Detailed($"Using branch name: '{branchName}'");
                git.CheckoutNewBranch(branchName);

                await _updateRunner.Update(updateSet, sources);

                var commitMessage = CommitWording.MakeCommitMessage(updateSet);
                git.Commit(commitMessage);

                git.Push("nukeeper_push", branchName);

                var prTitle = CommitWording.MakePullRequestTitle(updateSet);
                await MakeGitHubPullRequest(updateSet, repository, prTitle,
                                            branchName, serverSettings.Labels);

                git.Checkout(repository.DefaultBranch);
                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error("Update failed", ex);
                return(false);
            }
        }
コード例 #7
0
ファイル: PackageUpdater.cs プロジェクト: zubivan/NuKeeper
        private async Task <int> MakeUpdatePullRequests(
            IGitDriver git, RepositoryData repository,
            NuGetSources sources, SettingsContainer settings,
            IReadOnlyCollection <PackageUpdateSet> updates)
        {
            _logger.Normal(UpdatesLogger.OldVersionsToBeUpdated(updates));

            await git.Checkout(repository.DefaultBranch);

            // branch
            var branchWithChanges = BranchNamer.MakeName(updates, settings.BranchSettings.BranchNameTemplate);

            _logger.Detailed($"Using branch name: '{branchWithChanges}'");

            var ditCheckOut = await git.CheckoutNewBranch(branchWithChanges);

            if (!ditCheckOut)
            {
                await git.CheckoutRemoteToLocal(branchWithChanges);
            }

            var filteredUpdates = await _existingCommitFilter.Filter(git, updates, repository.DefaultBranch, branchWithChanges);

            foreach (var filtered in updates.Where(u => !filteredUpdates.Contains(u)))
            {
                var commitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(filtered);
                _logger.Normal($"Commit '{commitMessage}' already in branch '{branchWithChanges}'");
            }

            var haveUpdates = filteredUpdates.Any();

            foreach (var updateSet in filteredUpdates)
            {
                var commitMessage = _collaborationFactory.CommitWorder.MakeCommitMessage(updateSet);

                await _updateRunner.Update(updateSet, sources);

                await git.Commit(commitMessage);
            }

            if (haveUpdates)
            {
                await git.Push(repository.Remote, branchWithChanges);

                string qualifiedBranch;
                if (!repository.IsFork) //check if we are on a fork, if so qualify the branch name
                {
                    qualifiedBranch = branchWithChanges;
                }
                else
                {
                    qualifiedBranch = repository.Push.Owner + ":" + branchWithChanges;
                }

                bool pullRequestExists = await _collaborationFactory.CollaborationPlatform.PullRequestExists(repository.Pull, qualifiedBranch, repository.DefaultBranch);

                if (!pullRequestExists)
                {
                    var title = _collaborationFactory.CommitWorder.MakePullRequestTitle(updates);
                    var body  = _collaborationFactory.CommitWorder.MakeCommitDetails(updates);

                    var pullRequestRequest = new PullRequestRequest(qualifiedBranch, title, repository.DefaultBranch, settings.BranchSettings.DeleteBranchAfterMerge)
                    {
                        Body = body
                    };

                    await _collaborationFactory.CollaborationPlatform.OpenPullRequest(repository.Pull, pullRequestRequest, settings.SourceControlServerSettings.Labels);
                }
                else
                {
                    _logger.Normal($"A pull request already exists for {repository.DefaultBranch} <= {qualifiedBranch}");
                }
            }
            await git.Checkout(repository.DefaultBranch);

            return(filteredUpdates.Count);
        }