Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Workflows CreateDispatch via repository ID #2960

Merged
merged 1 commit into from
Aug 16, 2024
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
25 changes: 23 additions & 2 deletions Octokit.Reactive/Clients/IObservableActionsWorkflowsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Octokit.Reactive
public interface IObservableActionsWorkflowsClient
{
/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// Manually triggers a GitHub Actions workflow run in a repository by slug.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
Expand All @@ -24,7 +24,7 @@ public interface IObservableActionsWorkflowsClient
IObservable<Unit> CreateDispatch(string owner, string name, string workflowFileName, CreateWorkflowDispatch createDispatch);

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// Manually triggers a GitHub Actions workflow run in a repository by slug.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
Expand All @@ -35,6 +35,27 @@ public interface IObservableActionsWorkflowsClient
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
IObservable<Unit> CreateDispatch(string owner, string name, long workflowId, CreateWorkflowDispatch createDispatch);

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowFileName">The workflow file name.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
IObservable<Unit> CreateDispatch(long repositoryId, string workflowFileName, CreateWorkflowDispatch createDispatch);

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowId">The Id of the workflow.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
IObservable<Unit> CreateDispatch(long repositoryId, long workflowId, CreateWorkflowDispatch createDispatch);
/// <summary>
/// Disables a specific workflow in a repository by Id.
/// </summary>
Expand Down
37 changes: 35 additions & 2 deletions Octokit.Reactive/Clients/ObservableActionsWorkflowsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ObservableActionsWorkflowsClient(IGitHubClient client)
}

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// Manually triggers a GitHub Actions workflow run in a repository by slug.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
Expand All @@ -43,7 +43,7 @@ public IObservable<Unit> CreateDispatch(string owner, string name, string workfl
}

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// Manually triggers a GitHub Actions workflow run in a repository by slug.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
Expand All @@ -61,6 +61,39 @@ public IObservable<Unit> CreateDispatch(string owner, string name, long workflow
return _client.CreateDispatch(owner, name, workflowId, createDispatch).ToObservable();
}

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by slug.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowFileName">The workflow file name.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
public IObservable<Unit> CreateDispatch(long repositoryId, string workflowFileName, CreateWorkflowDispatch createDispatch)
{
Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName));
Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch));

return _client.CreateDispatch(repositoryId, workflowFileName, createDispatch).ToObservable();
}

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowId">The Id of the workflow.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
public IObservable<Unit> CreateDispatch(long repositoryId, long workflowId, CreateWorkflowDispatch createDispatch)
{
Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch));

return _client.CreateDispatch(repositoryId, workflowId, createDispatch).ToObservable();
}

/// <summary>
/// Disables a specific workflow in a repository by Id.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ public async Task CanDispatchWorkflow()
{
var owner = context.Repository.Owner.Login;
var name = context.Repository.Name;
var repoId = context.Repository.Id;
var workflowFileName = await CreateWorkflow(github, context);
var reference = "main";

await fixture.CreateDispatch(owner, name, workflowFileName, new CreateWorkflowDispatch(reference));
await fixture.CreateDispatch(repoId, workflowFileName, new CreateWorkflowDispatch(reference));

var workflowId = await GetWorkflowId(github, context, workflowFileName);

await fixture.CreateDispatch(owner, name, workflowId, new CreateWorkflowDispatch(reference));
await fixture.CreateDispatch(repoId, workflowId, new CreateWorkflowDispatch(reference));
}
}

Expand Down
39 changes: 37 additions & 2 deletions Octokit.Tests/Clients/ActionsWorkflowsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AreNotNull()
public class TheCreateDispatchMethod
{
[Fact]
public async Task RequestsCorrectUrlByWorkflowId()
public async Task RequestsCorrectUrlByWorkflowIdRepoSlug()
{
var connection = Substitute.For<IApiConnection>();
var client = new ActionsWorkflowsClient(connection);
Expand All @@ -47,7 +47,7 @@ public async Task RequestsCorrectUrlByWorkflowId()
}

[Fact]
public async Task RequestsCorrectUrlByWorkflowFileName()
public async Task RequestsCorrectUrlByWorkflowFileNameRepoSlug()
{
var connection = Substitute.For<IApiConnection>();
var client = new ActionsWorkflowsClient(connection);
Expand All @@ -61,6 +61,36 @@ public async Task RequestsCorrectUrlByWorkflowFileName()
createDispatch);
}

[Fact]
public async Task RequestsCorrectUrlByWorkflowIdRepoId()
{
var connection = Substitute.For<IApiConnection>();
var client = new ActionsWorkflowsClient(connection);

var createDispatch = new CreateWorkflowDispatch("ref");

await client.CreateDispatch(321, 123, createDispatch);

connection.Received().Post<object>(
Arg.Is<Uri>(u => u.ToString() == "repositories/321/actions/workflows/123/dispatches"),
createDispatch);
}

[Fact]
public async Task RequestsCorrectUrlByWorkflowFileNameRepoId()
{
var connection = Substitute.For<IApiConnection>();
var client = new ActionsWorkflowsClient(connection);

var createDispatch = new CreateWorkflowDispatch("ref");

await client.CreateDispatch(321, "main.yaml", createDispatch);

connection.Received().Post<object>(
Arg.Is<Uri>(u => u.ToString() == "repositories/321/actions/workflows/main.yaml/dispatches"),
createDispatch);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
Expand All @@ -77,6 +107,9 @@ public async Task EnsuresNonNullArguments()
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateDispatch("fake", null, "main.yaml", createDispatch));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateDispatch("fake", "repo", null, createDispatch));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateDispatch("fake", "repo", "main.yaml", null));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateDispatch(4321, 123, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateDispatch(4321, null, createDispatch));
}

[Fact]
Expand All @@ -93,6 +126,8 @@ public async Task EnsuresNonEmptyArguments()
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateDispatch("", "repo", "main.yaml", createDispatch));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateDispatch("fake", "", "main.yaml", createDispatch));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateDispatch("fake", "repo", "", createDispatch));

await Assert.ThrowsAsync<ArgumentException>(() => client.CreateDispatch(4321, "", createDispatch));
}
}

Expand Down
34 changes: 32 additions & 2 deletions Octokit.Tests/Reactive/ObservableActionsWorkflowsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void AreNotNull()
public class TheCreateDispatchMethod
{
[Fact]
public async Task RequestsCorrectUrlByWorkflowId()
public async Task RequestsCorrectUrlByWorkflowIdRepoSlug()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservableActionsWorkflowsClient(connection);
Expand All @@ -46,7 +46,7 @@ public async Task RequestsCorrectUrlByWorkflowId()
}

[Fact]
public async Task RequestsCorrectUrlByWorkflowFileName()
public async Task RequestsCorrectUrlByWorkflowFileNameRepoSlug()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservableActionsWorkflowsClient(connection);
Expand All @@ -57,6 +57,31 @@ public async Task RequestsCorrectUrlByWorkflowFileName()

connection.Received().Actions.Workflows.CreateDispatch("fake", "repo", "main.yaml", createDispatch);
}
[Fact]
public async Task RequestsCorrectUrlByWorkflowIdRepoId()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservableActionsWorkflowsClient(connection);

var createDispatch = new CreateWorkflowDispatch("ref");

client.CreateDispatch(1234, 123, createDispatch);

connection.Received().Actions.Workflows.CreateDispatch(1234, 123, createDispatch);
}

[Fact]
public async Task RequestsCorrectUrlByWorkflowFileNameRepoId()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservableActionsWorkflowsClient(connection);

var createDispatch = new CreateWorkflowDispatch("ref");

client.CreateDispatch(1234, "main.yaml", createDispatch);

connection.Received().Actions.Workflows.CreateDispatch(1234, "main.yaml", createDispatch);
}

[Fact]
public async Task EnsuresNonNullArguments()
Expand All @@ -74,6 +99,9 @@ public async Task EnsuresNonNullArguments()
Assert.Throws<ArgumentNullException>(() => client.CreateDispatch("fake", null, "main.yaml", createDispatch));
Assert.Throws<ArgumentNullException>(() => client.CreateDispatch("fake", "repo", null, createDispatch));
Assert.Throws<ArgumentNullException>(() => client.CreateDispatch("fake", "repo", "main.yaml", null));

Assert.Throws<ArgumentNullException>(() => client.CreateDispatch(4321, 123, null));
Assert.Throws<ArgumentNullException>(() => client.CreateDispatch(4321, null, createDispatch));
}

[Fact]
Expand All @@ -90,6 +118,8 @@ public async Task EnsuresNonEmptyArguments()
Assert.Throws<ArgumentException>(() => client.CreateDispatch("", "repo", "main.yaml", createDispatch));
Assert.Throws<ArgumentException>(() => client.CreateDispatch("fake", "", "main.yaml", createDispatch));
Assert.Throws<ArgumentException>(() => client.CreateDispatch("fake", "repo", "", createDispatch));

Assert.Throws<ArgumentException>(() => client.CreateDispatch(4321, "", createDispatch));
}
}

Expand Down
35 changes: 35 additions & 0 deletions Octokit/Clients/ActionsWorkflowsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@ public Task CreateDispatch(string owner, string name, long workflowId, CreateWor
return ApiConnection.Post<object>(ApiUrls.ActionsDispatchWorkflow(owner, name, workflowId), createDispatch);
}

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by file name.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowFileName">The workflow file name.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
[ManualRoute("POST", "/repositories/{id}/actions/workflows/{workflow_id}/dispatches")]
public Task CreateDispatch(long repositoryId, string workflowFileName, CreateWorkflowDispatch createDispatch)
{
Ensure.ArgumentNotNullOrEmptyString(workflowFileName, nameof(workflowFileName));
Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch));

return ApiConnection.Post<object>(ApiUrls.ActionsDispatchWorkflow(repositoryId, workflowFileName), createDispatch);
}

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowId">The Id of the workflow.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
[ManualRoute("POST", "/repositories/{id}/actions/workflows/{workflow_id}/dispatches")]
public Task CreateDispatch(long repositoryId, long workflowId, CreateWorkflowDispatch createDispatch)
{
Ensure.ArgumentNotNull(createDispatch, nameof(createDispatch));

return ApiConnection.Post<object>(ApiUrls.ActionsDispatchWorkflow(repositoryId, workflowId), createDispatch);
}

/// <summary>
/// Disables a specific workflow in a repository by file name.
/// </summary>
Expand Down
26 changes: 24 additions & 2 deletions Octokit/Clients/IActionsWorkflowsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Octokit
public interface IActionsWorkflowsClient
{
/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// Manually triggers a GitHub Actions workflow run in a repository by slug.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
Expand All @@ -23,7 +23,7 @@ public interface IActionsWorkflowsClient
Task CreateDispatch(string owner, string name, string workflowFileName, CreateWorkflowDispatch createDispatch);

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// Manually triggers a GitHub Actions workflow run in a repository by slug.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
Expand All @@ -34,6 +34,28 @@ public interface IActionsWorkflowsClient
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
Task CreateDispatch(string owner, string name, long workflowId, CreateWorkflowDispatch createDispatch);

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowFileName">The workflow file name.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
Task CreateDispatch(long repositoryId, string workflowFileName, CreateWorkflowDispatch createDispatch);

/// <summary>
/// Manually triggers a GitHub Actions workflow run in a repository by Id.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/actions/workflows/#create-a-workflow-dispatch-event
/// </remarks>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowId">The Id of the workflow.</param>
/// <param name="createDispatch">The parameters to use to trigger the workflow run.</param>
Task CreateDispatch(long repositoryId, long workflowId, CreateWorkflowDispatch createDispatch);

/// <summary>
/// Disables a specific workflow in a repository by Id.
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5042,6 +5042,28 @@ public static Uri ActionsDispatchWorkflow(string owner, string repo, string work
return "repos/{0}/{1}/actions/workflows/{2}/dispatches".FormatUri(owner, repo, workflowFileName.UriEncode());
}

/// <summary>
/// Returns the <see cref="Uri"/> that disables an Actions workflow for a repository.
/// </summary>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowId">The Id of the workflow.</param>
/// <returns>The <see cref="Uri"/> that gets an Actions workflow for a repository.</returns>
public static Uri ActionsDispatchWorkflow(long repositoryId, long workflowId)
{
return "repositories/{0}/actions/workflows/{1}/dispatches".FormatUri(repositoryId, workflowId);
}

/// <summary>
/// Returns the <see cref="Uri"/> that disables an Actions workflow for a repository.
/// </summary>
/// <param name="repositoryId">The Id of the repository.</param>
/// <param name="workflowFileName">The workflow file name.</param>
/// <returns>The <see cref="Uri"/> that gets an Actions workflow for a repository.</returns>
public static Uri ActionsDispatchWorkflow(long repositoryId, string workflowFileName)
{
return "repositories/{0}/actions/workflows/{1}/dispatches".FormatUri(repositoryId, workflowFileName.UriEncode());
}

/// <summary>
/// Returns the <see cref="Uri"/> that disables an Actions workflow for a repository.
/// </summary>
Expand Down
Loading