Skip to content

Commit e26d747

Browse files
authored
Merge pull request #1 from sneha-krip/copilot/fix-workflow-dispatch-response
Support return_run_details parameter in workflow_dispatch
2 parents 6d02a4b + 6bada3c commit e26d747

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

lib/octokit/client/actions_workflows.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ def workflow(repo, id, options = {})
3535
# @param repo [Integer, String, Repository, Hash] A GitHub repository
3636
# @param id [Integer, String] Id or file name of the workflow
3737
# @param ref [String] A SHA, branch name, or tag name
38+
# @param options [Hash] Optional parameters
39+
# @option options [Boolean] :return_run_details Fetch run details (needs API 2022-11-28)
3840
#
39-
# @return [Boolean] True if event was dispatched, false otherwise
41+
# @return [Boolean, Sawyer::Resource] Boolean success or run details
4042
# @see https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
4143
def workflow_dispatch(repo, id, ref, options = {})
42-
boolean_from_response :post, "#{Repository.path repo}/actions/workflows/#{id}/dispatches", options.merge({ ref: ref })
44+
merged_params = options.merge({ ref: ref })
45+
endpoint_path = "#{Repository.path repo}/actions/workflows/#{id}/dispatches"
46+
47+
wants_details = merged_params[:return_run_details]
48+
wants_details ? post(endpoint_path, merged_params) : boolean_from_response(:post, endpoint_path, merged_params)
4349
end
4450

4551
# Enable a workflow

spec/octokit/client/actions_workflows_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@
5454
@client.workflow_dispatch(@test_repo, workflow_file_name, 'main')
5555
assert_requested request
5656
end
57+
58+
context 'with return_run_details option' do
59+
it 'gets run details from API response' do
60+
wf_file = 'simple_workflow.yml'
61+
# rubocop:disable Style/NumericLiterals
62+
api_response_body = {
63+
workflow_run_id: 22103568458,
64+
run_url: "https://api.github.com/repos/#{@test_repo}/actions/runs/22103568458",
65+
html_url: "https://github.com/#{@test_repo}/actions/runs/22103568458"
66+
}.to_json
67+
# rubocop:enable Style/NumericLiterals
68+
69+
http_stub = stub_post("/repos/#{@test_repo}/actions/workflows/#{wf_file}/dispatches")
70+
.to_return(
71+
status: 200,
72+
body: api_response_body,
73+
headers: { 'Content-Type' => 'application/json' }
74+
)
75+
76+
output = @client.workflow_dispatch(@test_repo, wf_file, 'main', return_run_details: true)
77+
78+
expect(output.class.name).to eq('Sawyer::Resource')
79+
expect(output.workflow_run_id).to be(22103568458) # rubocop:disable Style/NumericLiterals
80+
expect(output.run_url).to match('actions/runs/22103568458')
81+
expect(output.html_url).to match("github.com/#{@test_repo}/actions/runs/22103568458")
82+
assert_requested http_stub
83+
end
84+
end
5785
end # .workflow_dispatch
5886

5987
describe '.workflow_enable' do

0 commit comments

Comments
 (0)