public async Task UpdatePackageInProjects( IGitDriver git, PackageUpdateSet updateSet, RepositoryData repository) { try { _logger.Terse(UpdatesLogger.OldVersionsToBeUpdated(updateSet)); git.Checkout(repository.DefaultBranch); // branch var branchName = BranchNamer.MakeName(updateSet); _logger.Verbose($"Using branch name: '{branchName}'"); git.CheckoutNewBranch(branchName); await UpdateAllCurrentUsages(updateSet); var commitMessage = CommitWording.MakeCommitMessage(updateSet); git.Commit(commitMessage); git.Push("nukeeper_push", branchName); var prTitle = CommitWording.MakePullRequestTitle(updateSet); await MakeGitHubPullRequest(updateSet, repository, prTitle, branchName); git.Checkout(repository.DefaultBranch); } catch (Exception ex) { _logger.Error("Update failed", ex); } }
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); }
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); }
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); } }
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); }