From 5d264fd111f8913ffd1a3a1ad42a32a9662a14ab Mon Sep 17 00:00:00 2001 From: Emil Stoev Date: Fri, 12 Mar 2021 17:06:41 -0500 Subject: [PATCH] Added job client --- src/GitLabApiClient/GitLabClient.cs | 8 +++++++- src/GitLabApiClient/IJobClient.cs | 15 +++++++++++++++ src/GitLabApiClient/JobClient.cs | 29 +++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/GitLabApiClient/IJobClient.cs create mode 100644 src/GitLabApiClient/JobClient.cs diff --git a/src/GitLabApiClient/GitLabClient.cs b/src/GitLabApiClient/GitLabClient.cs index 63705304..b9ffb321 100644 --- a/src/GitLabApiClient/GitLabClient.cs +++ b/src/GitLabApiClient/GitLabClient.cs @@ -73,6 +73,7 @@ public GitLabClient(string hostUrl, string authenticationToken = "", HttpMessage Commits = new CommitsClient(_httpFacade, commitQueryBuilder, commitRefsQueryBuilder, commitStatusesQueryBuilder); Markdown = new MarkdownClient(_httpFacade); Pipelines = new PipelineClient(_httpFacade, pipelineQueryBuilder, jobQueryBuilder); + Jobs = new JobClient(_httpFacade); Trees = new TreesClient(_httpFacade, treeQueryBuilder); Files = new FilesClient(_httpFacade); Runners = new RunnersClient(_httpFacade); @@ -151,10 +152,15 @@ public GitLabClient(string hostUrl, string authenticationToken = "", HttpMessage public IMarkdownClient Markdown { get; } /// - /// Acess GitLab's Pipeline API. + /// Access GitLab's Pipeline API. /// public IPipelineClient Pipelines { get; } + /// + /// Access GitLab's Job API. + /// + public IJobClient Jobs { get; } + /// /// Access GitLab's Runners API. /// diff --git a/src/GitLabApiClient/IJobClient.cs b/src/GitLabApiClient/IJobClient.cs new file mode 100644 index 00000000..28d36f2c --- /dev/null +++ b/src/GitLabApiClient/IJobClient.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; +using GitLabApiClient.Internal.Paths; +using GitLabApiClient.Models.Job.Responses; + +namespace GitLabApiClient +{ + public interface IJobClient + { + Task GetAsync(ProjectId projectId, int jobId); + Task RetryAsync(ProjectId projectId, int jobId); + Task PlayAsync(ProjectId projectId, int jobId); + Task CancelAsync(ProjectId projectId, int jobId); + Task EraseAsync(ProjectId projectId, int jobId); + } +} diff --git a/src/GitLabApiClient/JobClient.cs b/src/GitLabApiClient/JobClient.cs new file mode 100644 index 00000000..45f7438f --- /dev/null +++ b/src/GitLabApiClient/JobClient.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; +using GitLabApiClient.Internal.Http; +using GitLabApiClient.Internal.Paths; +using GitLabApiClient.Models.Job.Responses; + +namespace GitLabApiClient +{ + public sealed class JobClient : IJobClient + { + private readonly GitLabHttpFacade _httpFacade; + + internal JobClient(GitLabHttpFacade httpFacade) => _httpFacade = httpFacade; + + public async Task GetAsync(ProjectId projectId, int jobId) => + await _httpFacade.Get($"projects/{projectId}/jobs/{jobId}"); + + public async Task RetryAsync(ProjectId projectId, int jobId) => + await _httpFacade.Post($"projects/{projectId}/jobs/{jobId}/retry"); + + public async Task PlayAsync(ProjectId projectId, int jobId) => + await _httpFacade.Post($"projects/{projectId}/jobs/{jobId}/play"); + + public async Task CancelAsync(ProjectId projectId, int jobId) => + await _httpFacade.Post($"projects/{projectId}/jobs/{jobId}/cancel"); + + public async Task EraseAsync(ProjectId projectId, int jobId) => + await _httpFacade.Post($"projects/{projectId}/jobs/{jobId}/erase"); + } +}