-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #35 Start with pipeline get implementation * #35 Add create method * #35 Add delete pipeline * #35 add cancel implementation * #35 Retry implementation * #35 Make request properties readonly
- Loading branch information
Showing
18 changed files
with
496 additions
and
1 deletion.
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
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,21 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace GitLabApiClient.Models.Pipelines | ||
{ | ||
public enum PipelineStatus | ||
{ | ||
All, | ||
[EnumMember(Value = "running")] | ||
Running, | ||
[EnumMember(Value = "pending")] | ||
Pending, | ||
[EnumMember(Value = "success")] | ||
Success, | ||
[EnumMember(Value = "failed")] | ||
Failed, | ||
[EnumMember(Value = "canceled")] | ||
Canceled, | ||
[EnumMember(Value = "skipped")] | ||
Skipped | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/GitLabApiClient/Models/Pipelines/Requests/BasePipelineRequest.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 @@ | ||
using GitLabApiClient.Internal.Utilities; | ||
using Newtonsoft.Json; | ||
|
||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public abstract class BasePipelineRequest | ||
{ | ||
protected BasePipelineRequest(string projectId, int pipelineId) | ||
{ | ||
Guard.NotEmpty(projectId, nameof(projectId)); | ||
Guard.IsTrue(pipelineId > 0, nameof(pipelineId)); | ||
|
||
ProjectId = projectId; | ||
PipelineId = pipelineId; | ||
} | ||
|
||
/// <summary> | ||
/// The ID or URL-encoded path of the project owned by the authenticated user | ||
/// </summary> | ||
[JsonProperty("id")] | ||
public string ProjectId { get; } | ||
|
||
/// <summary> | ||
/// The ID of a pipeline | ||
/// </summary> | ||
[JsonProperty("pipeline_id")] | ||
public int PipelineId { get; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/GitLabApiClient/Models/Pipelines/Requests/CancelPipelineRequest.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,9 @@ | ||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public sealed class CancelPipelineRequest : BasePipelineRequest | ||
{ | ||
public CancelPipelineRequest(string projectId, int pipelineId) : base(projectId, pipelineId) | ||
{ | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/GitLabApiClient/Models/Pipelines/Requests/CreatePipelineRequest.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,40 @@ | ||
using System.Collections.Generic; | ||
using GitLabApiClient.Internal.Utilities; | ||
using GitLabApiClient.Models.Pipelines.Responses; | ||
using Newtonsoft.Json; | ||
|
||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public sealed class CreatePipelineRequest | ||
{ | ||
public CreatePipelineRequest(string projectId, string reference, IList<PipelineVariable> variables = null) | ||
{ | ||
Guard.NotEmpty(projectId, nameof(projectId)); | ||
Guard.NotEmpty(reference, nameof(reference)); | ||
|
||
ProjectId = projectId; | ||
Reference = reference; | ||
|
||
Variables = variables ?? new List<PipelineVariable>(); | ||
} | ||
|
||
/// <summary> | ||
/// The ID or URL-encoded path of the project owned by the authenticated user | ||
/// </summary> | ||
[JsonProperty("id")] | ||
public string ProjectId { get; } | ||
|
||
/// <summary> | ||
/// Reference to commit | ||
/// </summary> | ||
[JsonProperty("ref")] | ||
public string Reference { get; } | ||
|
||
/// <summary> | ||
/// An array containing the variables available in the pipeline, matching the structure [{ 'key' => 'UPLOAD_TO_S3', | ||
/// 'variable_type' => 'file', 'value' => 'true' }] | ||
/// </summary> | ||
[JsonProperty("variables")] | ||
public IList<PipelineVariable> Variables { get; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/GitLabApiClient/Models/Pipelines/Requests/DeletePipelineRequest.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,9 @@ | ||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public class DeletePipelineRequest : BasePipelineRequest | ||
{ | ||
public DeletePipelineRequest(string projectId, int pipelineId) : base(projectId, pipelineId) | ||
{ | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/GitLabApiClient/Models/Pipelines/Requests/PipelineOrder.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,16 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public enum PipelineOrder | ||
{ | ||
[EnumMember(Value = "id")] | ||
Id, | ||
[EnumMember(Value = "status")] | ||
Status, | ||
[EnumMember(Value = "ref")] | ||
Ref, | ||
[EnumMember(Value = "user_id")] | ||
UserId | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/GitLabApiClient/Models/Pipelines/Requests/PipelineQueryBuilder.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,67 @@ | ||
using System; | ||
using GitLabApiClient.Internal.Queries; | ||
using GitLabApiClient.Internal.Utilities; | ||
|
||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
internal sealed class PipelineQueryBuilder : QueryBuilder<PipelineQueryOptions> | ||
{ | ||
#region Overrides of QueryBuilder<PipelineQueryOptions> | ||
|
||
/// <inheritdoc /> | ||
protected override void BuildCore(PipelineQueryOptions options) | ||
{ | ||
if (!options.Ref.IsNullOrEmpty()) | ||
{ | ||
Add("ref", options.Ref); | ||
} | ||
|
||
if (options.YamlErrors.HasValue) | ||
{ | ||
Add("yaml_errors", options.YamlErrors.Value); | ||
} | ||
|
||
if (!options.Sha.IsNullOrEmpty()) | ||
{ | ||
Add("sha", options.Sha); | ||
} | ||
|
||
if (options.Status != PipelineStatus.All) | ||
{ | ||
Add("status", options.Status.ToLowerCaseString()); | ||
} | ||
|
||
if (options.Scope != PipelineScope.All) | ||
{ | ||
Add("scope", options.Scope.ToLowerCaseString()); | ||
} | ||
|
||
if (options.Order != PipelineOrder.Id) | ||
{ | ||
Add("order_by", AsString(options.Order)); | ||
} | ||
|
||
if (options.SortOrder != SortOrder.Descending) | ||
{ | ||
Add("sort", "asc"); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
private string AsString(PipelineOrder order) | ||
{ | ||
switch (order) | ||
{ | ||
case PipelineOrder.UserId: | ||
return "user_id"; | ||
case PipelineOrder.Id: | ||
case PipelineOrder.Ref: | ||
case PipelineOrder.Status: | ||
return order.ToLowerCaseString(); | ||
default: | ||
throw new ArgumentException("Unknown order type", nameof(order)); | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/GitLabApiClient/Models/Pipelines/Requests/PipelineQueryOptions.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,42 @@ | ||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public class PipelineQueryOptions | ||
{ | ||
internal PipelineQueryOptions() { } | ||
|
||
/// <summary> | ||
/// The scope of pipelines, one of: running, pending, finished, branches, tags | ||
/// </summary> | ||
public PipelineScope Scope { get; set; } = PipelineScope.All; | ||
|
||
/// <summary> | ||
/// The status of pipelines, one of: running, pending, success, failed, canceled, skipped | ||
/// </summary> | ||
public PipelineStatus Status { get; set; } = PipelineStatus.All; | ||
|
||
/// <summary> | ||
/// The ref of pipelines | ||
/// </summary> | ||
public string Ref { get; set; } | ||
|
||
/// <summary> | ||
/// The sha or pipelines | ||
/// </summary> | ||
public string Sha { get; set; } | ||
|
||
/// <summary> | ||
/// Returns pipelines with invalid configurations | ||
/// </summary> | ||
public bool? YamlErrors { get; set; } | ||
|
||
/// <summary> | ||
/// Order pipelines by id, status, ref, or user_id (default: id) | ||
/// </summary> | ||
public PipelineOrder Order { get; set; } = PipelineOrder.Id; | ||
|
||
/// <summary> | ||
/// Sort pipelines in asc or desc order (default: desc) | ||
/// </summary> | ||
public SortOrder SortOrder { get; set; } = SortOrder.Descending; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/GitLabApiClient/Models/Pipelines/Requests/PipelineScope.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,19 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public enum PipelineScope | ||
{ | ||
All, | ||
[EnumMember(Value = "running")] | ||
Running, | ||
[EnumMember(Value = "pending")] | ||
Pending, | ||
[EnumMember(Value = "finished")] | ||
Finished, | ||
[EnumMember(Value = "branches")] | ||
Branches, | ||
[EnumMember(Value = "tags")] | ||
Tags | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/GitLabApiClient/Models/Pipelines/Requests/RetryPipelineRequest.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,9 @@ | ||
namespace GitLabApiClient.Models.Pipelines.Requests | ||
{ | ||
public sealed class RetryPipelineRequest : BasePipelineRequest | ||
{ | ||
public RetryPipelineRequest(string projectId, int pipelineId) : base(projectId, pipelineId) | ||
{ | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/GitLabApiClient/Models/Pipelines/Responses/Pipeline.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 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace GitLabApiClient.Models.Pipelines.Responses | ||
{ | ||
public class Pipeline | ||
{ | ||
[JsonProperty("id")] | ||
public int Id { get; set; } | ||
|
||
[JsonProperty("status")] | ||
public PipelineStatus Status { get; set; } | ||
|
||
[JsonProperty("ref")] | ||
public string Ref { get; set; } | ||
|
||
[JsonProperty("sha")] | ||
public string Sha { get; set; } | ||
|
||
[JsonProperty("web_url")] | ||
public Uri WebUrl { get; set; } | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/GitLabApiClient/Models/Pipelines/Responses/PipelineDetail.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,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using GitLabApiClient.Models.Users.Responses; | ||
using Newtonsoft.Json; | ||
|
||
namespace GitLabApiClient.Models.Pipelines.Responses | ||
{ | ||
public class PipelineDetail | ||
{ | ||
[JsonProperty("id")] | ||
public int Id { get; set; } | ||
|
||
[JsonProperty("sha")] | ||
public string Sha { get; set; } | ||
|
||
[JsonProperty("ref")] | ||
public string Ref { get; set; } | ||
|
||
[JsonProperty("status")] | ||
public PipelineStatus Status { get; set; } | ||
|
||
[JsonProperty("web_url")] | ||
public Uri WebUrl { get; set; } | ||
|
||
[JsonProperty("before_sha")] | ||
public string BeforeSha { get; set; } | ||
|
||
[JsonProperty("tag")] | ||
public bool Tag { get; set; } | ||
|
||
[JsonProperty("yaml_errors")] | ||
public string YamlErrors { get; set; } | ||
|
||
[JsonProperty("user")] | ||
public PipelineUser User { get; set; } | ||
|
||
[JsonProperty("created_at")] | ||
public DateTime CreatedAt { get; set; } | ||
|
||
[JsonProperty("updated_at")] | ||
public DateTime? UpdatedAt { get; set; } | ||
|
||
[JsonProperty("started_at")] | ||
public DateTime? StartedAt { get; set; } | ||
|
||
[JsonProperty("finished_at")] | ||
public DateTime? FinishedAt { get; set; } | ||
|
||
[JsonProperty("committed_at")] | ||
public DateTime? CommittedAt { get; set; } | ||
|
||
[JsonProperty("duration")] | ||
public int Duration { get; set; } | ||
|
||
[JsonProperty("coverage")] | ||
public string Coverage { get; set; } | ||
} | ||
} |
Oops, something went wrong.