/// <summary> /// Votes for the pullrequest. /// </summary> /// <param name="vote">The vote for the pull request.</param> /// <exception cref="AzureDevOpsPullRequestNotFoundException">If pull request could not be found and /// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception> public void Vote(AzureDevOpsPullRequestVote vote) { if (!this.ValidatePullRequest()) { return; } using (var gitClient = this.gitClientFactory.CreateGitClient(this.CollectionUrl, this.credentials, out var authorizedIdenity)) { var createdReviewer = gitClient .CreatePullRequestReviewerAsync( new IdentityRefWithVote() { Vote = (short)vote }, this.pullRequest.Repository.Id, this.pullRequest.PullRequestId, authorizedIdenity.Id.ToString()) .ConfigureAwait(false) .GetAwaiter() .GetResult(); if (createdReviewer == null) { throw new AzureDevOpsPullRequestNotFoundException( this.pullRequest.Repository.Id, this.pullRequest.PullRequestId); } var createdVote = (AzureDevOpsPullRequestVote)createdReviewer.Vote; this.log.Verbose("Voted for pull request with '{0}'.", createdVote.ToString()); } }
public static void AzureDevOpsVotePullRequest( this ICakeContext context, AzureDevOpsPullRequestSettings settings, AzureDevOpsPullRequestVote vote) { context.NotNull(nameof(context)); settings.NotNull(nameof(settings)); new AzureDevOpsPullRequest(context.Log, settings, new GitClientFactory()).Vote(vote); }
/// <summary> /// Votes for the pullrequest. /// </summary> /// <param name="vote">The vote for the pull request.</param> /// <exception cref="AzureDevOpsPullRequestNotFoundException">If pull request could not be found and /// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception> public void Vote(AzureDevOpsPullRequestVote vote) { if (!this.ValidatePullRequest()) { return; } using (var gitClient = this.gitClientFactory.CreateGitClient(this.CollectionUrl, this.credentials, out var authorizedIdenity)) { var request = gitClient.CreatePullRequestReviewerAsync( new IdentityRefWithVote() { Vote = (short)vote }, this.pullRequest.Repository.Id, this.pullRequest.PullRequestId, authorizedIdenity.Id.ToString(), CancellationToken.None); try { var createdReviewer = request.Result; if (createdReviewer == null) { throw new AzureDevOpsPullRequestNotFoundException( this.pullRequest.Repository.Id, this.pullRequest.PullRequestId); } var createdVote = (AzureDevOpsPullRequestVote)createdReviewer.Vote; this.log.Verbose("Voted for pull request with '{0}'.", createdVote.ToString()); } catch (Exception ex) { this.log.Error("Error voting on pull request: " + ex.InnerException?.Message); throw; } } }