Skip to content
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

Added job client #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/GitLabApiClient/GitLabClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -151,10 +152,15 @@ public GitLabClient(string hostUrl, string authenticationToken = "", HttpMessage
public IMarkdownClient Markdown { get; }

/// <summary>
/// Acess GitLab's Pipeline API.
/// Access GitLab's Pipeline API.
/// </summary>
public IPipelineClient Pipelines { get; }

/// <summary>
/// Access GitLab's Job API.
/// </summary>
public IJobClient Jobs { get; }

/// <summary>
/// Access GitLab's Runners API.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/GitLabApiClient/IJobClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using GitLabApiClient.Internal.Paths;
using GitLabApiClient.Models.Job.Responses;

namespace GitLabApiClient
{
public interface IJobClient
{
Task<Job> GetAsync(ProjectId projectId, int jobId);
Task<Job> RetryAsync(ProjectId projectId, int jobId);
Task<Job> PlayAsync(ProjectId projectId, int jobId);
Task<Job> CancelAsync(ProjectId projectId, int jobId);
Task<Job> EraseAsync(ProjectId projectId, int jobId);
}
}
29 changes: 29 additions & 0 deletions src/GitLabApiClient/JobClient.cs
Original file line number Diff line number Diff line change
@@ -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<Job> GetAsync(ProjectId projectId, int jobId) =>
await _httpFacade.Get<Job>($"projects/{projectId}/jobs/{jobId}");

public async Task<Job> RetryAsync(ProjectId projectId, int jobId) =>
await _httpFacade.Post<Job>($"projects/{projectId}/jobs/{jobId}/retry");

public async Task<Job> PlayAsync(ProjectId projectId, int jobId) =>
await _httpFacade.Post<Job>($"projects/{projectId}/jobs/{jobId}/play");

public async Task<Job> CancelAsync(ProjectId projectId, int jobId) =>
await _httpFacade.Post<Job>($"projects/{projectId}/jobs/{jobId}/cancel");

public async Task<Job> EraseAsync(ProjectId projectId, int jobId) =>
await _httpFacade.Post<Job>($"projects/{projectId}/jobs/{jobId}/erase");
}
}