-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(GH-263) Add an alias to update a build definition #267
Closed
christianbumann
wants to merge
2
commits into
cake-contrib:develop
from
christianbumann:feature/gh-263
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Cake.AzureDevOps/Pipelines/AzureDevOpsBuildDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Cake.AzureDevOps.Pipelines | ||
{ | ||
/// <summary> | ||
/// Represents of an build definition. | ||
/// </summary> | ||
public class AzureDevOpsBuildDefinition | ||
{ | ||
/// <summary> | ||
/// Gets the attempt of the build. | ||
/// </summary> | ||
public int Id { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the name of the build definition reference. | ||
/// </summary> | ||
public string Name { get; internal set; } | ||
|
||
/// <summary> | ||
/// Gets the queue status. | ||
/// </summary> | ||
public AzureDevOpsDefinitionQueueStatus QueueStatus { get; internal set; } | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
src/Cake.AzureDevOps/Pipelines/AzureDevOpsBuildsDefinitionHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
namespace Cake.AzureDevOps.Pipelines | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cake.Core.Diagnostics; | ||
using Microsoft.TeamFoundation.Build.WebApi; | ||
|
||
/// <summary> | ||
/// Provides functions for AzureDevOps build definitions. | ||
/// </summary> | ||
internal static class AzureDevOpsBuildsDefinitionHelper | ||
{ | ||
/// <summary> | ||
/// Returns the build definitions for the <paramref name="settings"/>. | ||
/// </summary> | ||
/// <param name="log">The Cake log context.</param> | ||
/// <param name="settings">Settings for accessing AzureDevOps.</param> | ||
/// <returns>The build definitions for the the <paramref name="settings"/>.</returns> | ||
internal static IEnumerable<AzureDevOpsBuildDefinition> GetAzureDevOpsBuildDefinitions( | ||
ICakeLog log, | ||
AzureDevOpsBuildsSettings settings) | ||
{ | ||
log.NotNull(nameof(log)); | ||
settings.NotNull(nameof(settings)); | ||
|
||
List<BuildDefinitionReference> buildDefinitions = null; | ||
|
||
using (var buildHttpClient = new BuildClientFactory().CreateBuildClient(settings.CollectionUrl, settings.Credentials)) | ||
{ | ||
if (settings.ProjectGuid != Guid.Empty) | ||
{ | ||
buildDefinitions = | ||
buildHttpClient | ||
.GetDefinitionsAsync(settings.ProjectGuid) | ||
.ConfigureAwait(false) | ||
.GetAwaiter() | ||
.GetResult(); | ||
} | ||
else if (!string.IsNullOrWhiteSpace(settings.ProjectName)) | ||
{ | ||
buildDefinitions = | ||
buildHttpClient | ||
.GetDefinitionsAsync(settings.ProjectName) | ||
.ConfigureAwait(false) | ||
.GetAwaiter() | ||
.GetResult(); | ||
} | ||
else | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
nameof(settings), | ||
"Either ProjectGuid or ProjectName needs to be set"); | ||
} | ||
|
||
log.Verbose( | ||
"{0} Build definitions found", | ||
buildDefinitions.Count); | ||
|
||
return buildDefinitions | ||
.Select(x => x.ToAzureDevOpsBuildDefinition()) | ||
.ToList(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Updates a build definition with the new build definition settings and returns the updated build definition. | ||
/// </summary> | ||
/// <param name="log">The Cake log context.</param> | ||
/// <param name="settings">Settings for accessing AzureDevOps.</param> | ||
/// <param name="updateBuildDefinitionSettings">The settings to update the build definition.</param> | ||
/// <returns>The updated Azure DevOps build definition.</returns> | ||
internal static AzureDevOpsBuildDefinition UpdateBuildDefinition( | ||
ICakeLog log, | ||
AzureDevOpsBuildsSettings settings, | ||
AzureDevOpsUpdateBuildDefinitionSettings updateBuildDefinitionSettings) | ||
{ | ||
log.NotNull(nameof(log)); | ||
settings.NotNull(nameof(settings)); | ||
updateBuildDefinitionSettings.NotNull(nameof(updateBuildDefinitionSettings)); | ||
|
||
using (var buildHttpClient = new BuildClientFactory().CreateBuildClient(settings.CollectionUrl, settings.Credentials)) | ||
{ | ||
BuildDefinition buildDefinitionToUpdate = null; | ||
|
||
if (settings.ProjectGuid != Guid.Empty) | ||
{ | ||
buildDefinitionToUpdate = | ||
buildHttpClient | ||
.GetDefinitionAsync(settings.ProjectGuid, updateBuildDefinitionSettings.Id) | ||
.ConfigureAwait(false) | ||
.GetAwaiter() | ||
.GetResult(); | ||
} | ||
else if (!string.IsNullOrWhiteSpace(settings.ProjectName)) | ||
{ | ||
buildDefinitionToUpdate = | ||
buildHttpClient | ||
.GetDefinitionAsync(settings.ProjectName, updateBuildDefinitionSettings.Id) | ||
.ConfigureAwait(false) | ||
.GetAwaiter() | ||
.GetResult(); | ||
} | ||
else | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
nameof(settings), | ||
"Either ProjectGuid or ProjectName needs to be set"); | ||
} | ||
|
||
buildDefinitionToUpdate.QueueStatus = updateBuildDefinitionSettings.QueueStatus.ToDefinitionQueueStatus(); | ||
buildDefinitionToUpdate.Comment = updateBuildDefinitionSettings.Comment; | ||
|
||
var updatedBuildDefinition = | ||
buildHttpClient | ||
.UpdateDefinitionAsync(buildDefinitionToUpdate) | ||
.ConfigureAwait(false) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
return updatedBuildDefinition.ToAzureDevOpsBuildDefinition(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Cake.AzureDevOps/Pipelines/AzureDevOpsDefinitionQueueStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace Cake.AzureDevOps.Pipelines | ||
{ | ||
/// <summary> | ||
/// Possible states of a build queue. | ||
/// </summary> | ||
public enum AzureDevOpsDefinitionQueueStatus : byte | ||
{ | ||
/// <summary> | ||
/// When enabled the definition queue allows builds to be queued by users, the system | ||
/// will queue scheduled, gated and continuous integration builds, and the queued | ||
/// builds will be started by the system. | ||
/// </summary> | ||
Enabled = 0, | ||
|
||
/// <summary> | ||
/// When paused the definition queue allows builds to be queued by users and the | ||
/// system will queue scheduled, gated and continuous integration builds. Builds | ||
/// in the queue will not be started by the system.$ | ||
/// </summary> | ||
Paused = 1, | ||
|
||
/// <summary> | ||
/// When disabled the definition queue will not allow builds to be queued by users | ||
/// and the system will not queue scheduled, gated or continuous integration builds. | ||
/// Builds already in the queue will not be started by the system. | ||
/// <summary> | ||
Disabled = 2, | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Cake.AzureDevOps/Pipelines/AzureDevOpsUpdateBuildDefinitionSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Cake.AzureDevOps.Pipelines | ||
{ | ||
using Microsoft.TeamFoundation.Build.WebApi; | ||
|
||
/// <summary> | ||
/// Class which contains settings for updating a build definition. | ||
/// </summary> | ||
public class AzureDevOpsUpdateBuildDefinitionSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets the id of the build definition. | ||
/// </summary> | ||
public int Id; | ||
|
||
/// <summary> | ||
/// Gets or sets the status of the queue. | ||
/// </summary> | ||
public AzureDevOpsDefinitionQueueStatus QueueStatus; | ||
|
||
/// <summary> | ||
/// Gets or sets the save-time comment of the queue. | ||
/// </summary> | ||
public string Comment; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Cake.AzureDevOps/Pipelines/BuildDefinitionReferenceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Cake.AzureDevOps.Pipelines | ||
{ | ||
using Microsoft.TeamFoundation.Build.WebApi; | ||
|
||
/// <summary> | ||
/// Extensions for the <see cref="BuildDefinitionReference"/> class. | ||
/// </summary> | ||
internal static class BuildDefinitionReferenceExtensions | ||
{ | ||
/// <summary> | ||
/// Converts a <see cref="BuildDefinitionReference"/> to an <see cref="AzureDevOpsBuildDefinition"/>. | ||
/// </summary> | ||
/// <param name="buildDefinitionReference">Build definition reference record to convert.</param> | ||
/// <returns>Converted build definition record.</returns> | ||
public static AzureDevOpsBuildDefinition ToAzureDevOpsBuildDefinition(this BuildDefinitionReference buildDefinitionReference) | ||
{ | ||
buildDefinitionReference.NotNull(nameof(buildDefinitionReference)); | ||
|
||
return | ||
new AzureDevOpsBuildDefinition | ||
{ | ||
Id = buildDefinitionReference.Id, | ||
Name = buildDefinitionReference.Name, | ||
QueueStatus = buildDefinitionReference.QueueStatus.ToAzureDevOpsDefinitionQueueStatus(), | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with other areas of this addin (e.g. for pull requestst) this should be implemented on the
AzureDevOpsBuildDefinition
class instead of a complete separate code flow.