From 90de66fecb94616a2d8a368f2130630de8e1bd44 Mon Sep 17 00:00:00 2001 From: Ziya Suzen Date: Mon, 9 Mar 2026 14:59:43 +0000 Subject: [PATCH 1/2] Add support for workflows run id - Add DispatchesPostResponse model - Add unit test for DispatchesRequestBuilder --- .../Item/Dispatches/DispatchesPostResponse.cs | 57 +++++++++++++++ .../Dispatches/DispatchesRequestBuilder.cs | 6 +- .../DispatchesRequestBuilderTest.cs | 72 +++++++++++++++++++ 3 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs create mode 100644 test/Dispatches/DispatchesRequestBuilderTest.cs diff --git a/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs b/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs new file mode 100644 index 000000000..1ca618fb8 --- /dev/null +++ b/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs @@ -0,0 +1,57 @@ +using Microsoft.Kiota.Abstractions.Serialization; +using System; +using System.Collections.Generic; +using System.IO; + +namespace GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches; + +/// +/// Response from workflow dispatch when return_run_details is true. +/// +public class DispatchesPostResponse : IParsable +{ + /// The workflow run ID. + public long? WorkflowRunId { get; set; } + + /// The API URL for the workflow run. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? RunUrl { get; set; } +#nullable restore +#else + public string RunUrl { get; set; } +#endif + + /// The HTML URL for the workflow run. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? HtmlUrl { get; set; } +#nullable restore +#else + public string HtmlUrl { get; set; } +#endif + + public static DispatchesPostResponse CreateFromDiscriminatorValue(IParseNode parseNode) + { + _ = parseNode ?? throw new ArgumentNullException(nameof(parseNode)); + return new DispatchesPostResponse(); + } + + public IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "workflow_run_id", n => { WorkflowRunId = n.GetLongValue(); } }, + { "run_url", n => { RunUrl = n.GetStringValue(); } }, + { "html_url", n => { HtmlUrl = n.GetStringValue(); } }, + }; + } + + public void Serialize(ISerializationWriter writer) + { + _ = writer ?? throw new ArgumentNullException(nameof(writer)); + writer.WriteLongValue("workflow_run_id", WorkflowRunId); + writer.WriteStringValue("run_url", RunUrl); + writer.WriteStringValue("html_url", HtmlUrl); + } +} diff --git a/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesRequestBuilder.cs b/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesRequestBuilder.cs index 2315fa345..516f9a9eb 100644 --- a/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesRequestBuilder.cs +++ b/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesRequestBuilder.cs @@ -41,16 +41,16 @@ public DispatchesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : /// Configuration for the request such as headers, query parameters, and middleware options. #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER #nullable enable - public async Task PostAsync(global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + public async Task PostAsync(global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) { #nullable restore #else - public async Task PostAsync(global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + public async Task PostAsync(global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) { #endif _ = body ?? throw new ArgumentNullException(nameof(body)); var requestInfo = ToPostRequestInformation(body, requestConfiguration); - await RequestAdapter.SendNoContentAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + return await RequestAdapter.SendAsync(requestInfo, global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostResponse.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); } /// /// You can use this endpoint to manually trigger a GitHub Actions workflow run. You can replace `workflow_id` with the workflow file name. For example, you could use `main.yaml`.You must configure your GitHub Actions workflow to run when the [`workflow_dispatch` webhook](/developers/webhooks-and-events/webhook-events-and-payloads#workflow_dispatch) event occurs. The `inputs` are configured in the workflow file. For more information about how to configure the `workflow_dispatch` event in the workflow file, see "[Events that trigger workflows](/actions/reference/events-that-trigger-workflows#workflow_dispatch)."OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. diff --git a/test/Dispatches/DispatchesRequestBuilderTest.cs b/test/Dispatches/DispatchesRequestBuilderTest.cs new file mode 100644 index 000000000..7e0a0574b --- /dev/null +++ b/test/Dispatches/DispatchesRequestBuilderTest.cs @@ -0,0 +1,72 @@ +using GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Abstractions.Serialization; +using Moq; +using Xunit; + +public class DispatchesRequestBuilderTests +{ + private static (DispatchesRequestBuilder builder, Mock mockAdapter) CreateBuilder() + { + var mockAdapter = new Mock(); + var mockSerializationWriterFactory = new Mock(); + var mockSerializationWriter = new Mock(); + mockSerializationWriterFactory + .Setup(f => f.GetSerializationWriter(It.IsAny())) + .Returns(mockSerializationWriter.Object); + mockAdapter + .Setup(a => a.SerializationWriterFactory) + .Returns(mockSerializationWriterFactory.Object); + + var builder = new DispatchesRequestBuilder(new Dictionary + { + { "baseurl", "https://api.github.com" }, + { "owner%2Did", "org" }, + { "repo%2Did", "repo" }, + { "workflow_id", "main.yml" }, + }, mockAdapter.Object); + + return (builder, mockAdapter); + } + + [Fact] + public async Task PostAsync_ReturnsDispatchResponse() + { + var (builder, mockAdapter) = CreateBuilder(); + + var expectedResponse = new DispatchesPostResponse + { + WorkflowRunId = 22725043315, + RunUrl = "https://api.github.com/repos/org/repo/actions/runs/22725043315", + HtmlUrl = "https://github.com/org/repo/actions/runs/22725043315", + }; + + mockAdapter + .Setup(a => a.SendAsync( + It.IsAny(), + It.IsAny>(), + It.IsAny>>(), + It.IsAny())) + .ReturnsAsync(expectedResponse); + + var body = new DispatchesPostRequestBody + { + Ref = "main", + AdditionalData = { ["return_run_details"] = true }, + }; + + var result = await builder.PostAsync(body); + + Assert.NotNull(result); + Assert.Equal(22725043315, result!.WorkflowRunId); + Assert.Equal("https://api.github.com/repos/org/repo/actions/runs/22725043315", result.RunUrl); + Assert.Equal("https://github.com/org/repo/actions/runs/22725043315", result.HtmlUrl); + } + + [Fact] + public async Task PostAsync_ThrowsOnNullBody() + { + var (builder, _) = CreateBuilder(); + await Assert.ThrowsAsync(() => builder.PostAsync(null!)); + } +} From 08fbb96aded1d04de821f1951e8015abac1748de Mon Sep 17 00:00:00 2001 From: Ziya Suzen Date: Mon, 9 Mar 2026 15:08:48 +0000 Subject: [PATCH 2/2] fix format --- .../Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs b/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs index 1ca618fb8..273133df3 100644 --- a/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs +++ b/src/GitHub/Repos/Item/Item/Actions/Workflows/Item/Dispatches/DispatchesPostResponse.cs @@ -1,7 +1,7 @@ -using Microsoft.Kiota.Abstractions.Serialization; using System; using System.Collections.Generic; using System.IO; +using Microsoft.Kiota.Abstractions.Serialization; namespace GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches;