Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/GitLabApiClient/GitLabApiClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>10</LangVersion>
<PackageId>Apiiro.GitLabApiClient</PackageId>
<Version>0.1.45</Version>
<Version>0.1.44</Version>
<Authors>Apiiro</Authors>
<Company>Apiiro</Company>
<PackageDescription>GitLabApiClient</PackageDescription>
Expand Down
19 changes: 3 additions & 16 deletions src/GitLabApiClient/WebhookClient.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System.Collections.Generic;
using System.Linq;
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;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace GitLabApiClient
{
Expand Down Expand Up @@ -40,23 +37,13 @@ public async Task<IList<Webhook>> GetAsync(ProjectId projectId)
}

/// <summary>
/// Create new webhook.
/// Some GitLab versions return a JSON array from POST /projects/:id/hooks
/// instead of a single object. We deserialize as JToken to handle both formats.
/// 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)
{
var token = await _httpFacade.Post<JToken>($"projects/{projectId}/hooks", request);
return token switch
{
JArray array => array.FirstOrDefault()?.ToObject<Webhook>(),
JObject obj => obj.ToObject<Webhook>(),
_ => null
};
}
public async Task<Webhook> CreateAsync(ProjectId projectId, CreateWebhookRequest request) =>
await _httpFacade.Post<Webhook>($"projects/{projectId}/hooks", request);

/// <summary>
/// Delete a webhook
Expand Down
Loading