Skip to content

Commit

Permalink
Octokit doesn't have dispatch event we want?
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed May 14, 2024
1 parent 71f3a0d commit 56071d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
1 change: 0 additions & 1 deletion Build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<ItemGroup>
<PackageReference Include="Bullseye" Version="5.0.0"/>
<PackageReference Include="Glob" Version="1.1.9" />
<PackageReference Include="Octokit" Version="11.0.1" />
<PackageReference Include="SimpleExec" Version="12.0.0"/>
</ItemGroup>
</Project>
39 changes: 24 additions & 15 deletions Build/Github.cs
Original file line number Diff line number Diff line change
@@ -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<string, object>() { { "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);
}
}
}
6 changes: 0 additions & 6 deletions Build/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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, )",
Expand Down

0 comments on commit 56071d2

Please sign in to comment.