Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Kiota.Abstractions.Serialization;

namespace GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches;

/// <summary>
/// Response from workflow dispatch when return_run_details is true.
/// </summary>
public class DispatchesPostResponse : IParsable
{
/// <summary>The workflow run ID.</summary>
public long? WorkflowRunId { get; set; }

/// <summary>The API URL for the workflow run.</summary>
#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

/// <summary>The HTML URL for the workflow run.</summary>
#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<string, Action<IParseNode>> GetFieldDeserializers()
{
return new Dictionary<string, Action<IParseNode>>
{
{ "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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public DispatchesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) :
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#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<DefaultQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
public async Task<global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostResponse?> PostAsync(global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostRequestBody body, Action<RequestConfiguration<DefaultQueryParameters>>? 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<DefaultQueryParameters>> requestConfiguration = default, CancellationToken cancellationToken = default)
public async Task<global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostResponse> PostAsync(global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostRequestBody body, Action<RequestConfiguration<DefaultQueryParameters>> 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<global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostResponse>(requestInfo, global::GitHub.Repos.Item.Item.Actions.Workflows.Item.Dispatches.DispatchesPostResponse.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// 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 &quot;[Events that trigger workflows](/actions/reference/events-that-trigger-workflows#workflow_dispatch).&quot;OAuth tokens and personal access tokens (classic) need the `repo` scope to use this endpoint.
Expand Down
72 changes: 72 additions & 0 deletions test/Dispatches/DispatchesRequestBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -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<IRequestAdapter> mockAdapter) CreateBuilder()
{
var mockAdapter = new Mock<IRequestAdapter>();
var mockSerializationWriterFactory = new Mock<ISerializationWriterFactory>();
var mockSerializationWriter = new Mock<ISerializationWriter>();
mockSerializationWriterFactory
.Setup(f => f.GetSerializationWriter(It.IsAny<string>()))
.Returns(mockSerializationWriter.Object);
mockAdapter
.Setup(a => a.SerializationWriterFactory)
.Returns(mockSerializationWriterFactory.Object);

var builder = new DispatchesRequestBuilder(new Dictionary<string, object>
{
{ "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<RequestInformation>(),
It.IsAny<ParsableFactory<DispatchesPostResponse>>(),
It.IsAny<Dictionary<string, ParsableFactory<IParsable>>>(),
It.IsAny<CancellationToken>()))
.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<ArgumentNullException>(() => builder.PostAsync(null!));
}
}