Skip to content

Commit

Permalink
Merge branch '4-stable' into clear-last-response-on-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tarebyte authored May 22, 2020
2 parents b0e85f2 + 3af5739 commit d79667d
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 12 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
20 changes: 10 additions & 10 deletions lib/octokit/client/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def organization_membership(org, options = {})

# Edit an organization membership
#
# @param org [String] Organization GitHub login.
# @param org [String, Integer] Organization GitHub login or id.
# @option options [String] :role The role of the user in the organization.
# @option options [String] :state The state that the membership should be in.
# @option options [String] :user The login of the user, otherwise authenticated user.
Expand All @@ -701,7 +701,7 @@ def update_organization_membership(org, options = {})
options = options.dup
if user = options.delete(:user)
options.delete(:state)
put "orgs/#{org}/memberships/#{user}", options
put "#{Organization.path(org)}/memberships/#{user}", options
else
options.delete(:role)
patch "user/memberships/orgs/#{org}", options
Expand All @@ -711,13 +711,13 @@ def update_organization_membership(org, options = {})

# Remove an organization membership
#
# @param org [String] Organization GitHub login.
# @param org [String, Integer] Organization GitHub login or id.
# @return [Boolean] Success
# @see https://developer.github.com/v3/orgs/members/#remove-organization-membership
def remove_organization_membership(org, options = {})
options = options.dup
user = options.delete(:user)
user && boolean_from_response(:delete, "orgs/#{org}/memberships/#{user}", options)
user && boolean_from_response(:delete, "#{Organization.path(org)}/memberships/#{user}", options)
end
alias :remove_org_membership :remove_organization_membership

Expand All @@ -735,7 +735,7 @@ def remove_organization_membership(org, options = {})
def start_migration(org, repositories, options = {})
options = ensure_api_media_type(:migrations, options)
options[:repositories] = repositories
post "orgs/#{org}/migrations", options
post "#{Organization.path(org)}/migrations", options
end

# Lists the most recent migrations.
Expand All @@ -747,7 +747,7 @@ def start_migration(org, repositories, options = {})
# @see https://developer.github.com/v3/orgs/migrations/#get-a-list-of-migrations
def migrations(org, options = {})
options = ensure_api_media_type(:migrations, options)
paginate "orgs/#{org}/migrations", options
paginate "#{Organization.path(org)}/migrations", options
end

# Fetches the status of a migration.
Expand All @@ -759,7 +759,7 @@ def migrations(org, options = {})
# @see https://developer.github.com/v3/orgs/migrations/#get-the-status-of-a-migration
def migration_status(org, id, options = {})
options = ensure_api_media_type(:migrations, options)
get "orgs/#{org}/migrations/#{id}", options
get "#{Organization.path(org)}/migrations/#{id}", options
end

# Fetches the URL to a migration archive.
Expand All @@ -771,7 +771,7 @@ def migration_status(org, id, options = {})
# @see https://developer.github.com/v3/orgs/migrations/#download-a-migration-archive
def migration_archive_url(org, id, options = {})
options = ensure_api_media_type(:migrations, options)
url = "orgs/#{org}/migrations/#{id}/archive"
url = "#{Organization.path(org)}/migrations/#{id}/archive"

response = client_without_redirects(options).get(url)
response.headers['location']
Expand All @@ -786,7 +786,7 @@ def migration_archive_url(org, id, options = {})
# @see https://developer.github.com/v3/orgs/migrations/#delete-a-migration-archive
def delete_migration_archive(org, id, options = {})
options = ensure_api_media_type(:migrations, options)
delete "orgs/#{org}/migrations/#{id}/archive", options
delete "#{Organization.path(org)}/migrations/#{id}/archive", options
end

# Unlock a previous migration archive.
Expand All @@ -799,7 +799,7 @@ def delete_migration_archive(org, id, options = {})
# @see https://developer.github.com/v3/orgs/migrations/#unlock-a-repository
def unlock_repository(org, id, repo, options = {})
options = ensure_api_media_type(:migrations, options)
delete "orgs/#{org}/migrations/#{id}/repos/#{repo}/lock", options
delete "#{Organization.path(org)}/migrations/#{id}/repos/#{repo}/lock", options
end
end
end
Expand Down
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 @@ -165,7 +165,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 d79667d

Please sign in to comment.