mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
Add support for Workflows CreateDispatch via repository ID (#2960)
Add support for workflow dispatch via repository ID
This commit is contained in:
@@ -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
|
||||
@@ -24,7 +24,7 @@ namespace Octokit.Reactive
|
||||
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
|
||||
@@ -35,6 +35,27 @@ namespace Octokit.Reactive
|
||||
/// <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>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Octokit.Reactive
|
||||
}
|
||||
|
||||
/// <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
|
||||
@@ -43,7 +43,7 @@ namespace Octokit.Reactive
|
||||
}
|
||||
|
||||
/// <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
|
||||
@@ -61,6 +61,39 @@ namespace Octokit.Reactive
|
||||
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>
|
||||
|
||||
@@ -105,14 +105,17 @@ jobs:
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Octokit.Tests.Clients
|
||||
public class TheCreateDispatchMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlByWorkflowId()
|
||||
public async Task RequestsCorrectUrlByWorkflowIdRepoSlug()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActionsWorkflowsClient(connection);
|
||||
@@ -47,7 +47,7 @@ namespace Octokit.Tests.Clients
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlByWorkflowFileName()
|
||||
public async Task RequestsCorrectUrlByWorkflowFileNameRepoSlug()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActionsWorkflowsClient(connection);
|
||||
@@ -61,6 +61,36 @@ namespace Octokit.Tests.Clients
|
||||
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()
|
||||
{
|
||||
@@ -77,6 +107,9 @@ namespace Octokit.Tests.Clients
|
||||
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]
|
||||
@@ -93,6 +126,8 @@ namespace Octokit.Tests.Clients
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Octokit.Tests.Reactive
|
||||
public class TheCreateDispatchMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlByWorkflowId()
|
||||
public async Task RequestsCorrectUrlByWorkflowIdRepoSlug()
|
||||
{
|
||||
var connection = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableActionsWorkflowsClient(connection);
|
||||
@@ -46,7 +46,7 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlByWorkflowFileName()
|
||||
public async Task RequestsCorrectUrlByWorkflowFileNameRepoSlug()
|
||||
{
|
||||
var connection = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableActionsWorkflowsClient(connection);
|
||||
@@ -57,6 +57,31 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
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()
|
||||
@@ -74,6 +99,9 @@ namespace Octokit.Tests.Reactive
|
||||
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]
|
||||
@@ -90,6 +118,8 @@ namespace Octokit.Tests.Reactive
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,41 @@ namespace Octokit
|
||||
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>
|
||||
|
||||
@@ -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
|
||||
@@ -23,7 +23,7 @@ namespace Octokit
|
||||
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
|
||||
@@ -34,6 +34,28 @@ namespace Octokit
|
||||
/// <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>
|
||||
|
||||
@@ -5042,6 +5042,28 @@ namespace Octokit
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user