Skip to content

Commit 7226d37

Browse files
Merge pull request #47 from apiiro/barnon/revert-webhook-array-fix
2 parents f8fd832 + 5b67a24 commit 7226d37

2 files changed

Lines changed: 4 additions & 17 deletions

File tree

src/GitLabApiClient/GitLabApiClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>10</LangVersion>
66
<PackageId>Apiiro.GitLabApiClient</PackageId>
7-
<Version>0.1.45</Version>
7+
<Version>0.1.44</Version>
88
<Authors>Apiiro</Authors>
99
<Company>Apiiro</Company>
1010
<PackageDescription>GitLabApiClient</PackageDescription>

src/GitLabApiClient/WebhookClient.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
using System.Collections.Generic;
2-
using System.Linq;
32
using System.Threading.Tasks;
43
using GitLabApiClient.Internal.Http;
54
using GitLabApiClient.Internal.Paths;
65
using GitLabApiClient.Models.Projects.Responses;
76
using GitLabApiClient.Models.Webhooks.Requests;
87
using GitLabApiClient.Models.Webhooks.Responses;
9-
using Newtonsoft.Json;
10-
using Newtonsoft.Json.Linq;
118

129
namespace GitLabApiClient
1310
{
@@ -40,23 +37,13 @@ public async Task<IList<Webhook>> GetAsync(ProjectId projectId)
4037
}
4138

4239
/// <summary>
43-
/// Create new webhook.
44-
/// Some GitLab versions return a JSON array from POST /projects/:id/hooks
45-
/// instead of a single object. We deserialize as JToken to handle both formats.
40+
/// Create new webhook
4641
/// </summary>
4742
/// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param>
4843
/// <param name="request">Create hook request.</param>
4944
/// <returns>newly created hook</returns>
50-
public async Task<Webhook> CreateAsync(ProjectId projectId, CreateWebhookRequest request)
51-
{
52-
var token = await _httpFacade.Post<JToken>($"projects/{projectId}/hooks", request);
53-
return token switch
54-
{
55-
JArray array => array.FirstOrDefault()?.ToObject<Webhook>(),
56-
JObject obj => obj.ToObject<Webhook>(),
57-
_ => null
58-
};
59-
}
45+
public async Task<Webhook> CreateAsync(ProjectId projectId, CreateWebhookRequest request) =>
46+
await _httpFacade.Post<Webhook>($"projects/{projectId}/hooks", request);
6047

6148
/// <summary>
6249
/// Delete a webhook

0 commit comments

Comments
 (0)