|
1 | 1 | namespace Cake.AzureDevOps
|
2 | 2 | {
|
3 | 3 | using System;
|
| 4 | + using System.Collections.Generic; |
4 | 5 | using Cake.AzureDevOps.PullRequest;
|
| 6 | + using Cake.AzureDevOps.Repos; |
5 | 7 | using Cake.Core;
|
6 | 8 | using Cake.Core.Annotations;
|
7 | 9 |
|
@@ -269,6 +271,56 @@ public static void AzureDevOpsAddCommentToPullRequest(
|
269 | 271 | .CreateComment(comment);
|
270 | 272 | }
|
271 | 273 |
|
| 274 | + /// <summary> |
| 275 | + /// Gets the commits contained in the Azure DevOps pull request using |
| 276 | + /// the specified settings. |
| 277 | + /// </summary> |
| 278 | + /// <param name="context">The context.</param> |
| 279 | + /// <param name="settings">Settings for accessing the pull request.</param> |
| 280 | + /// <example> |
| 281 | + /// <para>Lists id and message of commits of a pull request:</para> |
| 282 | + /// <code> |
| 283 | + /// <![CDATA[ |
| 284 | + /// var pullRequestSettings = |
| 285 | + /// new AzureDevOpsPullRequestSettings( |
| 286 | + /// new Uri("http://myserver:8080/defaultcollection/myproject/_git/myrepository"), |
| 287 | + /// "refs/heads/feature/myfeature", |
| 288 | + /// AzureDevOpsAuthenticationNtlm()); |
| 289 | + /// |
| 290 | + /// var commits = |
| 291 | + /// AzureDevOpsGetPullRequestCommits( |
| 292 | + /// pullRequestSettings); |
| 293 | + /// |
| 294 | + /// Information("Commits"); |
| 295 | + /// foreach (var commit in commits) |
| 296 | + /// { |
| 297 | + /// Information(" {0}: {1}", commit.Id, commit.Message); |
| 298 | + /// } |
| 299 | + /// ]]> |
| 300 | + /// </code> |
| 301 | + /// </example> |
| 302 | + /// <returns>The commits contained in the pull request. |
| 303 | + /// Returns an empty list if pull request could not be found and |
| 304 | + /// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>false</c>.</returns> |
| 305 | + /// <exception cref="AzureDevOpsPullRequestNotFoundException">If pull request could not be found and |
| 306 | + /// <see cref="AzureDevOpsPullRequestSettings.ThrowExceptionIfPullRequestCouldNotBeFound"/> is set to <c>true</c>.</exception> |
| 307 | + [CakeMethodAlias] |
| 308 | + [CakeAliasCategory("Pull Request")] |
| 309 | + [CakeNamespaceImport("Cake.AzureDevOps.Repos")] |
| 310 | + [CakeNamespaceImport("Cake.AzureDevOps.PullRequest")] |
| 311 | + [CakeNamespaceImport("Cake.AzureDevOps.PullRequest.CommentThread")] |
| 312 | + public static IEnumerable<AzureDevOpsCommit> AzureDevOpsGetPullRequestCommits( |
| 313 | + this ICakeContext context, |
| 314 | + AzureDevOpsPullRequestSettings settings) |
| 315 | + { |
| 316 | + context.NotNull(nameof(context)); |
| 317 | + settings.NotNull(nameof(settings)); |
| 318 | + |
| 319 | + return |
| 320 | + new AzureDevOpsPullRequest(context.Log, settings, new GitClientFactory()) |
| 321 | + .GetCommits(); |
| 322 | + } |
| 323 | + |
272 | 324 | /// <summary>
|
273 | 325 | /// Creates a pull request in Azure DevOps using the specified settings.
|
274 | 326 | /// </summary>
|
|
0 commit comments