Skip to content

Commit

Permalink
Merge pull request octokit#1252 from petar-lazarov/action-workflows
Browse files Browse the repository at this point in the history
Introduce Client methods for Workflows/WorkflowRun
  • Loading branch information
Heather Harvey authored May 21, 2020
2 parents 266acbf + de38a50 commit 3af5739
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/octokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
require 'octokit/user'
require 'octokit/organization'
require 'octokit/preview'
require 'octokit/client/actions_workflows'
require 'octokit/client/actions_workflow_runs'
require 'octokit/client/apps'
require 'octokit/client/authorizations'
require 'octokit/client/checks'
Expand Down Expand Up @@ -88,6 +90,8 @@ class Client
include Octokit::Client::Gists
include Octokit::Client::Gitignore
include Octokit::Client::Hooks
include Octokit::Client::ActionsWorkflows
include Octokit::Client::ActionsWorkflowRuns
include Octokit::Client::Apps
include Octokit::Client::Issues
include Octokit::Client::Labels
Expand Down
94 changes: 94 additions & 0 deletions lib/octokit/client/actions_workflow_runs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
module Octokit
class Client
module ActionsWorkflowRuns
# List all runs for a repository workflow
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param workflow [Integer, String] Id or file name of the workflow
# @option options [String] :actor Optional filtering by a user
# @option options [String] :branch Optional filtering by a branch
# @option options [String] :event Optional filtering by the event type
# @option options [String] :status Optional filtering by a status or conclusion
#
# @return [Sawyer::Resource] the total count and an array of workflows
# @see https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
def workflow_runs(repo, workflow, options = {})
paginate "#{Repository.path repo}/actions/workflows/#{workflow}/runs", options
end
alias list_workflow_runs workflow_runs

# List all workflow runs for a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @option options [String] :actor Optional filtering by the login of a user
# @option options [String] :branch Optional filtering by a branch
# @option options [String] :event Optional filtering by the event type (e.g. push, pull_request, issue)
# @option options [String] :status Optional filtering by a status or conclusion (e.g. success, completed...)
#
# @return [Sawyer::Resource] the total count and an array of workflows
# @see https://developer.github.com/v3/actions/workflow-runs/#list-repository-workflow-runs
def repository_workflow_runs(repo, options = {})
paginate "#{Repository.path repo}/actions/runs", options
end
alias list_repository_workflow_runs repository_workflow_runs

# Get a workflow run
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of a workflow run
#
# @return [Sawyer::Resource] Run information
# @see https://developer.github.com/v3/actions/workflow-runs/#get-a-workflow-run
def workflow_run(repo, id, options = {})
get "#{Repository.path repo}/actions/runs/#{id}", options
end

# Re-runs a workflow run
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of a workflow run
#
# @return [Boolean] Returns true if the re-run request was accepted
# @see https://developer.github.com/v3/actions/workflow-runs/#re-run-a-workflow
def rerun_workflow_run(repo, id, options = {})
boolean_from_response :post, "#{Repository.path repo}/actions/runs/#{id}/rerun", options
end

# Cancels a workflow run
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of a workflow run
#
# @return [Boolean] Returns true if the cancellation was accepted
# @see https://developer.github.com/v3/actions/workflow-runs/#cancel-a-workflow-run
def cancel_workflow_run(repo, id, options = {})
boolean_from_response :post, "#{Repository.path repo}/actions/runs/#{id}/cancel", options
end

# Get a download url for archived log files of a workflow run
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of a workflow run
#
# @return [String] URL to the archived log files of the run
# @see https://developer.github.com/v3/actions/workflow-runs/#download-workflow-run-logs
def workflow_run_logs(repo, id, options = {})
url = "#{Repository.path repo}/actions/runs/#{id}/logs"

response = client_without_redirects.head(url, options)
response.headers['Location']
end

# Delets all log files of a workflow run
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of a workflow run
#
# @return [Boolean] Returns true if the logs are deleted
# @see https://developer.github.com/v3/actions/workflow-runs/#delete-workflow-run-logs
def delete_workflow_run_logs(repo, id, options = {})
boolean_from_response :delete, "#{Repository.path repo}/actions/runs/#{id}/logs", options
end
end
end
end
31 changes: 31 additions & 0 deletions lib/octokit/client/actions_workflows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Octokit
class Client
# Methods for the Actions Workflows API
#
# @see https://developer.github.com/v3/actions/workflows
module ActionsWorkflows

# Get the workflows in a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
#
# @return [Sawyer::Resource] the total count and an array of workflows
# @see https://developer.github.com/v3/actions/workflows/#list-repository-workflows
def workflows(repo, options = {})
paginate "#{Repository.path repo}/actions/workflows", options
end
alias list_workflows workflows

# Get single workflow in a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer, String] Id or file name of the workflow
#
# @return [Sawyer::Resource] A single workflow
# @see https://developer.github.com/v3/actions/workflows/#get-a-workflow
def workflow(repo, id, options = {})
get "#{Repository.path repo}/actions/workflows/#{id}", options
end
end
end
end
13 changes: 13 additions & 0 deletions lib/octokit/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,19 @@ def update_subscription(repo, options = {})
def delete_subscription(repo, options = {})
boolean_from_response :delete, "#{Repository.path repo}/subscription", options
end

# Create a repository dispatch event
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
# @param event_type [String] A custom webhook event name.
# @option options [Hash] :client_payload payload with extra information
# about the webhook event that your action or worklow may use.
#
# @return [Boolean] True if event was dispatched, false otherwise.
# @see https://developer.github.com/v3/repos/#create-a-repository-dispatch-event
def dispatch_event(repo, event_type, options = {})
boolean_from_response :post, "#{Repository.path repo}/dispatches", options.merge({ event_type: event_type })
end
end
end
end
2 changes: 1 addition & 1 deletion lib/octokit/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def request(method, path, data, options = {})
# @return [Boolean] True on success, false otherwise
def boolean_from_response(method, path, options = {})
request(method, path, options)
@last_response.status == 204
[201, 202, 204].include? @last_response.status
rescue Octokit::NotFound
false
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/actions/runs","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 4.18.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Date":["Wed, 06 May 2020 11:57:16 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Server":["GitHub.com"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4987"],"X-Ratelimit-Reset":["1588769530"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding, Accept, X-Requested-With"],"Etag":["W/\"d83cfc16727ae54b8d36f02ffcb63c36\""],"X-Oauth-Scopes":["admin:org, delete_repo, repo, workflow"],"X-Accepted-Oauth-Scopes":[""],"X-Github-Media-Type":["github.v3; format=json"],"Access-Control-Expose-Headers":["ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset"],"Access-Control-Allow-Origin":["*"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Frame-Options":["deny"],"X-Content-Type-Options":["nosniff"],"X-Xss-Protection":["1; mode=block"],"Referrer-Policy":["origin-when-cross-origin, strict-origin-when-cross-origin"],"Content-Security-Policy":["default-src 'none'"],"X-Github-Request-Id":["8088:2D3E6:478AF0:5478F7:5EB2A61C"]},"body":{"encoding":"ASCII-8BIT","base64_string":"eyJ0b3RhbF9jb3VudCI6MCwid29ya2Zsb3dfcnVucyI6W119\n"},"http_version":null},"recorded_at":"Wed, 06 May 2020 11:57:17 GMT"}],"recorded_with":"VCR 5.1.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/actions/workflows","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.v3+json"],"User-Agent":["Octokit Ruby Gem 4.18.0"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Date":["Wed, 06 May 2020 11:57:18 GMT"],"Content-Type":["application/json; charset=utf-8"],"Transfer-Encoding":["chunked"],"Server":["GitHub.com"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4984"],"X-Ratelimit-Reset":["1588769531"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding, Accept, X-Requested-With"],"Etag":["W/\"125a96a0dec4d32c8419772cfa8f5a32\""],"X-Oauth-Scopes":["admin:org, delete_repo, repo, workflow"],"X-Accepted-Oauth-Scopes":[""],"X-Github-Media-Type":["github.v3; format=json"],"Access-Control-Expose-Headers":["ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset"],"Access-Control-Allow-Origin":["*"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Frame-Options":["deny"],"X-Content-Type-Options":["nosniff"],"X-Xss-Protection":["1; mode=block"],"Referrer-Policy":["origin-when-cross-origin, strict-origin-when-cross-origin"],"Content-Security-Policy":["default-src 'none'"],"X-Github-Request-Id":["9338:342E:4BA04A:58BDDF:5EB2A61E"]},"body":{"encoding":"ASCII-8BIT","base64_string":"eyJ0b3RhbF9jb3VudCI6MCwid29ya2Zsb3dzIjpbXX0=\n"},"http_version":null},"recorded_at":"Wed, 06 May 2020 11:57:18 GMT"}],"recorded_with":"VCR 5.1.0"}
Loading

0 comments on commit 3af5739

Please sign in to comment.