-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic operations to work with webhooks (#80)
Co-authored-by: Joseph Petersen <josephp90@gmail.com>
- Loading branch information
1 parent
e49a5c7
commit b6896b3
Showing
4 changed files
with
177 additions
and
0 deletions.
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
60 changes: 60 additions & 0 deletions
60
src/GitLabApiClient/Models/Webhooks/Requests/CreateWebhookRequest.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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Web; | ||
using GitLabApiClient.Internal.Utilities; | ||
using Newtonsoft.Json; | ||
|
||
namespace GitLabApiClient.Models.Webhooks.Requests | ||
{ | ||
/// <summary> | ||
/// Used to create a webhook in a project. | ||
/// </summary> | ||
public sealed class CreateWebhookRequest | ||
{ | ||
[JsonProperty("url")] | ||
public string Url { get; set; } | ||
|
||
[JsonProperty("push_events")] | ||
public bool PushEvents { get; set; } | ||
|
||
[JsonProperty("push_events_branch_filter")] | ||
public string PushEventsBranchFilter { get; set; } | ||
|
||
[JsonProperty("issues_events")] | ||
public bool IssuesEvents { get; set; } | ||
|
||
[JsonProperty("confidential_issues_events")] | ||
public bool ConfidentialIssuesEvents { get; set; } | ||
|
||
[JsonProperty("merge_requests_events")] | ||
public bool MergeRequestsEvents { get; set; } | ||
|
||
[JsonProperty("tag_push_events")] | ||
public bool TagPushEvents { get; set; } | ||
|
||
[JsonProperty("note_events")] | ||
public bool NoteEvents { get; set; } | ||
|
||
[JsonProperty("job_events")] | ||
public bool JobEvents { get; set; } | ||
|
||
[JsonProperty("pipeline_events")] | ||
public bool PipelineEvents { get; set; } | ||
|
||
[JsonProperty("wiki_page_events")] | ||
public bool WikiPageEvents { get; set; } | ||
|
||
[JsonProperty("enable_ssl_verification")] | ||
public bool EnableSslVerification { get; set; } | ||
|
||
[JsonProperty("token")] | ||
public string Token { get; set; } | ||
|
||
public CreateWebhookRequest(string url) | ||
{ | ||
Guard.NotEmpty(url, nameof(url)); | ||
Url = url; | ||
} | ||
} | ||
} |
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,51 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace GitLabApiClient.Models.Webhooks.Responses | ||
{ | ||
public sealed class Webhook | ||
{ | ||
[JsonProperty("id")] | ||
public long Id { get; set; } | ||
|
||
[JsonProperty("url")] | ||
public string Url { get; set; } | ||
|
||
[JsonProperty("push_events")] | ||
public bool PushEvents { get; set; } | ||
|
||
[JsonProperty("push_events_branch_filter")] | ||
public string PushEventsBranchFilter { get; set; } | ||
|
||
[JsonProperty("issues_events")] | ||
public bool IssuesEvents { get; set; } | ||
|
||
[JsonProperty("confidential_issues_events")] | ||
public bool ConfidentialIssuesEvents { get; set; } | ||
|
||
[JsonProperty("merge_requests_events")] | ||
public bool MergeRequestsEvents { get; set; } | ||
|
||
[JsonProperty("tag_push_events")] | ||
public bool TagPushEvents { get; set; } | ||
|
||
[JsonProperty("note_events")] | ||
public bool NoteEvents { get; set; } | ||
|
||
[JsonProperty("job_events")] | ||
public bool JobEvents { get; set; } | ||
|
||
[JsonProperty("pipeline_events")] | ||
public bool PipelineEvents { get; set; } | ||
|
||
[JsonProperty("wiki_page_events")] | ||
public bool WikiPageEvents { get; set; } | ||
|
||
[JsonProperty("enable_ssl_verification")] | ||
public bool EnableSslVerification { get; set; } | ||
|
||
[JsonProperty("created_at")] | ||
public DateTimeOffset CreatedAt { get; set; } | ||
|
||
} | ||
} |
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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using GitLabApiClient.Internal.Http; | ||
using GitLabApiClient.Internal.Paths; | ||
using GitLabApiClient.Models.Projects.Responses; | ||
using GitLabApiClient.Models.Webhooks.Requests; | ||
using GitLabApiClient.Models.Webhooks.Responses; | ||
|
||
namespace GitLabApiClient | ||
{ | ||
public sealed class WebhookClient | ||
{ | ||
private readonly GitLabHttpFacade _httpFacade; | ||
|
||
internal WebhookClient( | ||
GitLabHttpFacade httpFacade) | ||
{ | ||
_httpFacade = httpFacade; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a hook by its id | ||
/// </summary> | ||
/// <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) => | ||
await _httpFacade.Get<Webhook>($"projects/{projectId}/hooks/{hookId}"); | ||
|
||
/// <summary> | ||
/// Retrieves all project hooks | ||
/// </summary> | ||
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param> | ||
/// <returns></returns> | ||
public async Task<IList<Webhook>> GetAsync(ProjectId projectId) | ||
{ | ||
return await _httpFacade.GetPagedList<Webhook>($"projects/{projectId}/hooks"); | ||
} | ||
|
||
/// <summary> | ||
/// Create new webhook | ||
/// </summary> | ||
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param> | ||
/// <param name="request">Create hook request.</param> | ||
/// <returns>newly created hook</returns> | ||
public async Task<Webhook> CreateAsync(ProjectId projectId, CreateWebhookRequest request) => | ||
await _httpFacade.Post<Webhook>($"projects/{projectId}/hooks", request); | ||
|
||
/// <summary> | ||
/// Delete a 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 delete.</param> | ||
public async Task DeleteAsync(ProjectId projectId, int hookId) => | ||
await _httpFacade.Delete($"projects/{projectId}/hooks/${hookId}"); | ||
} | ||
|
||
|
||
} |