Skip to content

Commit

Permalink
Add API for get single merge request, create note on merge request, g…
Browse files Browse the repository at this point in the history
…et pipelines for merge request, delete for webhooks (nmklotas#137)

Co-Authored-By: Joseph Petersen <[email protected]>
  • Loading branch information
2 people authored and MindaugasLaganeckas committed Mar 9, 2021
1 parent 4e8c21e commit 7e891a8
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/GitLabApiClient/IMergeRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GitLabApiClient.Models.MergeRequests.Responses;
using GitLabApiClient.Models.Notes.Requests;
using GitLabApiClient.Models.Notes.Responses;
using GitLabApiClient.Models.Pipelines.Responses;
using GitLabApiClient.Models.Projects.Responses;

namespace GitLabApiClient
Expand All @@ -31,6 +32,14 @@ public interface IMergeRequestsClient
/// <returns>Merge requests satisfying options.</returns>
Task<IList<MergeRequest>> GetAsync(Action<MergeRequestsQueryOptions> options = null);

/// <summary>
/// Get single Merge requests by id
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="mergeRequestId">The Internal Merge Request Id.</param>
/// <returns>Shows information about a single merge request.</returns>
Task<MergeRequest> GetAsync(ProjectId projectId, int mergeRequestId);

/// <summary>
/// Creates merge request.
/// </summary>
Expand Down Expand Up @@ -64,6 +73,14 @@ public interface IMergeRequestsClient
/// <param name="mergeRequestId">The Internal Merge Request Id.</param>
Task DeleteAsync(ProjectId projectId, int mergeRequestId);

/// <summary>
/// Creates a new note (comment) to a single Merge Request.
/// </summary>
/// <returns>The newly created issue note.</returns>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="mergeRequestId">The IID of an Merge Request.</param>
/// <param name="request">Create Merge Request note request.</param>
Task<Note> CreateNoteAsync(ProjectId projectId, int mergeRequestId, CreateMergeRequestNoteRequest request);

/// <summary>
/// Retrieves notes (comments) of a merge request.
Expand All @@ -74,6 +91,14 @@ public interface IMergeRequestsClient
/// <returns>Merge requests satisfying options.</returns>
Task<IList<Note>> GetNotesAsync(ProjectId projectId, int mergeRequestIid, Action<MergeRequestNotesQueryOptions> options = null);

/// <summary>
/// List erge request pipelines
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="mergeRequestId">The Internal Merge Request Id.</param>
/// <returns>Get a list of merge request pipelines.</returns>
Task<IList<Pipeline>> GetPipelinesAsync(ProjectId projectId, int mergeRequestId);

/// <summary>
/// Retrieves discussions of a merge request.
/// </summary>
Expand Down
13 changes: 11 additions & 2 deletions src/GitLabApiClient/IWebhookClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IWebhookClient
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="hookId">The hook ID, you want to retrieve.</param>
/// <returns></returns>
Task<Webhook> GetAsync(ProjectId projectId, int hookId);
Task<Webhook> GetAsync(ProjectId projectId, long hookId);

/// <summary>
/// Retrieves all project hooks
Expand All @@ -39,6 +39,15 @@ public interface IWebhookClient
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="hookId">The hook ID, you want to delete.</param>
Task DeleteAsync(ProjectId projectId, int hookId);
Task DeleteAsync(ProjectId projectId, long hookId);

/// <summary>
/// Update new webhook
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="hookId">The hook ID, you want to update.</param>
/// <param name="request">Create hook request.</param>
/// <returns>newly created hook</returns>
Task<Webhook> UpdateAsync(ProjectId projectId, long hookId, CreateWebhookRequest request);
}
}
28 changes: 28 additions & 0 deletions src/GitLabApiClient/MergeRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using GitLabApiClient.Models.MergeRequests.Responses;
using GitLabApiClient.Models.Notes.Requests;
using GitLabApiClient.Models.Notes.Responses;
using GitLabApiClient.Models.Pipelines.Responses;
using GitLabApiClient.Models.Projects.Responses;

namespace GitLabApiClient
Expand Down Expand Up @@ -75,6 +76,14 @@ public async Task<IList<MergeRequest>> GetAsync(Action<MergeRequestsQueryOptions
return await _httpFacade.GetPagedList<MergeRequest>(query);
}

/// <summary>
/// Get single Merge requests by id
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="mergeRequestId">The Internal Merge Request Id.</param>
/// <returns>Shows information about a single merge request.</returns>
public async Task<MergeRequest> GetAsync(ProjectId projectId, int mergeRequestId)
=> await _httpFacade.Get<MergeRequest>($"projects/{projectId}/merge_requests/{mergeRequestId}");
/// <summary>
/// Creates merge request.
/// </summary>
Expand Down Expand Up @@ -115,6 +124,16 @@ public async Task<MergeRequest> AcceptAsync(ProjectId projectId, int mergeReques
public async Task DeleteAsync(ProjectId projectId, int mergeRequestId) =>
await _httpFacade.Delete($"projects/{projectId}/merge_requests/{mergeRequestId}");

/// <summary>
/// Creates a new note (comment) to a single Merge Request.
/// </summary>
/// <returns>The newly created issue note.</returns>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="mergeRequestId">The IID of an Merge Request.</param>
/// <param name="request">Create Merge Request note request.</param>
public async Task<Note> CreateNoteAsync(ProjectId projectId, int mergeRequestId, CreateMergeRequestNoteRequest request) =>
await _httpFacade.Post<Note>($"projects/{projectId}/merge_requests/{mergeRequestId}/notes", request);

/// <summary>
/// Retrieves notes (comments) of a merge request.
/// </summary>
Expand All @@ -131,6 +150,15 @@ public async Task<IList<Note>> GetNotesAsync(ProjectId projectId, int mergeReque
return await _httpFacade.GetPagedList<Note>(url);
}

/// <summary>
/// List erge request pipelines
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="mergeRequestId">The Internal Merge Request Id.</param>
/// <returns>Get a list of merge request pipelines.</returns>
public async Task<IList<Pipeline>> GetPipelinesAsync(ProjectId projectId, int mergeRequestId)
=> await _httpFacade.Get<List<Pipeline>>($"projects/{projectId}/merge_requests/{mergeRequestId}/pipelines");

/// <summary>
/// Retrieves discussions of a merge request.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using GitLabApiClient.Models.Issues.Responses;
using GitLabApiClient.Models.Milestones.Responses;
using GitLabApiClient.Models.Pipelines.Responses;
using Newtonsoft.Json;

namespace GitLabApiClient.Models.MergeRequests.Responses
Expand Down Expand Up @@ -85,5 +86,8 @@ public sealed class MergeRequest : ModifiableObject

[JsonProperty("time_stats")]
public MergeRequestTimeStatistic TimeStats { get; set; }

[JsonProperty("pipeline")]
public Pipeline Pipeline { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using GitLabApiClient.Internal.Utilities;
using Newtonsoft.Json;

namespace GitLabApiClient.Models.Notes.Requests
{
/// <summary>
/// Used to create issue notes in a project.
/// </summary>
public sealed class CreateMergeRequestNoteRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="CreateMergeRequestNoteRequest "/> class.
/// </summary>
/// <param name="body">The content of a note.</param>
public CreateMergeRequestNoteRequest(string body) => Body = body;

public CreateMergeRequestNoteRequest()
{
}

/// <summary>
/// The content of a note.
/// </summary>
[JsonProperty("body")]
public string Body { get; set; }

/// <summary>
/// Date time string, ISO 8601 formatted, e.g. 2016-03-11T03:45:40Z (requires admin or project/group owner rights)
/// </summary>
[JsonProperty("created_at")]
public DateTime? CreatedAt { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/GitLabApiClient/Models/Pipelines/Responses/Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class Pipeline
public Uri WebUrl { get; set; }

[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }
public DateTime? CreatedAt { get; set; }

[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
}
}
14 changes: 12 additions & 2 deletions src/GitLabApiClient/WebhookClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal WebhookClient(
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="hookId">The hook ID, you want to retrieve.</param>
/// <returns></returns>
public async Task<Webhook> GetAsync(ProjectId projectId, int hookId) =>
public async Task<Webhook> GetAsync(ProjectId projectId, long hookId) =>
await _httpFacade.Get<Webhook>($"projects/{projectId}/hooks/{hookId}");

/// <summary>
Expand All @@ -52,8 +52,18 @@ public async Task<Webhook> CreateAsync(ProjectId projectId, CreateWebhookRequest
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="hookId">The hook ID, you want to delete.</param>
public async Task DeleteAsync(ProjectId projectId, int hookId) =>
public async Task DeleteAsync(ProjectId projectId, long hookId) =>
await _httpFacade.Delete($"projects/{projectId}/hooks/{hookId}");

/// <summary>
/// Update new webhook
/// </summary>
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
/// <param name="hookId">The hook ID, you want to update.</param>
/// <param name="request">Create hook request.</param>
/// <returns>newly created hook</returns>
public async Task<Webhook> UpdateAsync(ProjectId projectId, long hookId, CreateWebhookRequest request) =>
await _httpFacade.Put<Webhook>($"projects/{projectId}/hooks/{hookId}", request);
}


Expand Down

0 comments on commit 7e891a8

Please sign in to comment.