|
1 | 1 | using System.Collections.Generic; |
2 | | -using System.Linq; |
3 | 2 | using System.Threading.Tasks; |
4 | 3 | using GitLabApiClient.Internal.Http; |
5 | 4 | using GitLabApiClient.Internal.Paths; |
6 | 5 | using GitLabApiClient.Models.Projects.Responses; |
7 | 6 | using GitLabApiClient.Models.Webhooks.Requests; |
8 | 7 | using GitLabApiClient.Models.Webhooks.Responses; |
9 | | -using Newtonsoft.Json; |
10 | | -using Newtonsoft.Json.Linq; |
11 | 8 |
|
12 | 9 | namespace GitLabApiClient |
13 | 10 | { |
@@ -40,23 +37,13 @@ public async Task<IList<Webhook>> GetAsync(ProjectId projectId) |
40 | 37 | } |
41 | 38 |
|
42 | 39 | /// <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 |
46 | 41 | /// </summary> |
47 | 42 | /// <param name="projectId">The ID, path or <see cref="Project"/> of the project.</param> |
48 | 43 | /// <param name="request">Create hook request.</param> |
49 | 44 | /// <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); |
60 | 47 |
|
61 | 48 | /// <summary> |
62 | 49 | /// Delete a webhook |
|
0 commit comments