From 56071d23eb2a8d12001043f173fd050dcb1f809e Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 14 May 2024 11:43:35 +0100 Subject: [PATCH] Octokit doesn't have dispatch event we want? --- Build/Build.csproj | 1 - Build/Github.cs | 39 ++++++++++++++++++++++++--------------- Build/packages.lock.json | 6 ------ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Build/Build.csproj b/Build/Build.csproj index 71e5acf99b..ab3cdcd6e1 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -7,7 +7,6 @@ - diff --git a/Build/Github.cs b/Build/Github.cs index d6d9a93a16..ea50611fe9 100644 --- a/Build/Github.cs +++ b/Build/Github.cs @@ -1,25 +1,34 @@ -using System.Collections.Generic; +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Mime; +using System.Text.Json; using System.Threading.Tasks; -using Octokit; -using Octokit.Internal; namespace Build; public static class Github { - private static GitHubClient GetClient(string secret) => - new(new ProductHeaderValue("Speckle.build"), new InMemoryCredentialStore(new Credentials(secret))); - public static async Task BuildInstallers(string secret, string runId) { - var client = GetClient(secret); - await client.Actions.Workflows - .CreateDispatch( - "specklesystems", - "connector-installers", - "build_installers.yml", - new CreateWorkflowDispatch("main") { Inputs = new Dictionary() { { "run_id", runId } } } - ) - .ConfigureAwait(false); + using var client = new HttpClient(); + var payload = new { event_type = "build-installers", client_payload = new { run_id = runId } }; + var content = new StringContent( + JsonSerializer.Serialize(payload), + new MediaTypeHeaderValue(MediaTypeNames.Application.Json) + ); + + var request = new HttpRequestMessage() + { + RequestUri = new Uri("https://api.github.com/repos/specklesystems/connector-installers/dispatches"), + Headers = { Authorization = new AuthenticationHeaderValue($"Bearer {secret}") }, + Content = content + }; + request.Headers.Add("X-GitHub-Api-Version", "2022-11-28"); + var response = await client.SendAsync(request).ConfigureAwait(false); + if (!response.IsSuccessStatusCode) + { + throw new InvalidOperationException(response.StatusCode + response.ReasonPhrase); + } } } diff --git a/Build/packages.lock.json b/Build/packages.lock.json index f67663ca4e..52565140d1 100644 --- a/Build/packages.lock.json +++ b/Build/packages.lock.json @@ -14,12 +14,6 @@ "resolved": "1.1.9", "contentHash": "AfK5+ECWYTP7G3AAdnU8IfVj+QpGjrh9GC2mpdcJzCvtQ4pnerAGwHsxJ9D4/RnhDUz2DSzd951O/lQjQby2Sw==" }, - "Octokit": { - "type": "Direct", - "requested": "[11.0.1, )", - "resolved": "11.0.1", - "contentHash": "fpwF/DxMJyGS+pIXDKQozx0wCIpOfG8VDr10ls+m9Gn9Lz8GslhhApxkKD9JCNO60HRUeMJsedsAS24gCjTD7Q==" - }, "SimpleExec": { "type": "Direct", "requested": "[12.0.0, )",