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 client methods to support Actions artifact APIs. #1480

Merged
merged 5 commits into from
Sep 14, 2022
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
2 changes: 2 additions & 0 deletions lib/octokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'octokit/repository'
require 'octokit/user'
require 'octokit/organization'
require 'octokit/client/actions_artifacts'
require 'octokit/client/actions_secrets'
require 'octokit/client/actions_workflows'
require 'octokit/client/actions_workflow_jobs'
Expand Down Expand Up @@ -74,6 +75,7 @@ class Client
include Octokit::Configurable
include Octokit::Connection
include Octokit::Warnable
include Octokit::Client::ActionsArtifacts
include Octokit::Client::ActionsSecrets
include Octokit::Client::Authorizations
include Octokit::Client::Checks
Expand Down
67 changes: 67 additions & 0 deletions lib/octokit/client/actions_artifacts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

module Octokit
class Client
# Methods for the Actions Artifacts API
#
# @see https://developer.github.com/v3/actions/artifacts
module ActionsArtifacts
# List all artifacts for a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
#
# @return [Sawyer::Resource] the total count and an array of artifacts
# @see https://developer.github.com/v3/actions/artifacts#list-artifacts-for-a-repository
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @see https://developer.github.com/v3/actions/artifacts#list-artifacts-for-a-repository
# @see https://docs.github.com/en/rest/actions/artifacts#list-artifacts-for-a-repository

def repository_artifacts(repo, options = {})
paginate "#{Repository.path repo}/actions/artifacts", options
end

# List all artifacts for a workflow run
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param workflow_run_id [Integer] Id of a workflow run
#
# @return [Sawyer::Resource] the total count and an array of artifacts
# @see https://docs.github.com/en/rest/actions/artifacts#list-workflow-run-artifacts
def workflow_run_artifacts(repo, workflow_run_id, options = {})
paginate "#{Repository.path repo}/actions/runs/#{workflow_run_id}/artifacts", options
end

# Get an artifact
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of an artifact
#
# @return [Sawyer::Resource] Artifact information
# @see https://docs.github.com/en/rest/actions/artifacts#get-an-artifact
def artifact(repo, id, options = {})
get "#{Repository.path repo}/actions/artifacts/#{id}", options
end

# Get a download URL for an artifact
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of an artifact
#
# @return [String] URL to the .zip archive of the artifact
# @see https://docs.github.com/en/rest/actions/workflow-runs#download-workflow-run-logs
def artifact_download_url(repo, id, options = {})
url = "#{Repository.path repo}/actions/artifacts/#{id}/zip"

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

# Delete an artifact
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param id [Integer] Id of an artifact
#
# @return [Boolean] Return true if the artifact was successfully deleted
# @see https://docs.github.com/en/rest/actions/artifacts#delete-an-artifact
def delete_artifact(repo, id, options = {})
boolean_from_response :delete, "#{Repository.path repo}/actions/artifacts/#{id}", options
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"http_interactions": [
{
"request": {
"method": "get",
"uri": "https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/actions/artifacts/362518594",
"body": {
"encoding": "US-ASCII",
"base64_string": ""
},
"headers": {
"Accept": [
"application/vnd.github.v3+json"
],
"User-Agent": [
"Octokit Ruby Gem 5.5.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": {
"Server": [
"GitHub.com"
],
"Date": [
"Wed, 14 Sep 2022 00:30:09 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Transfer-Encoding": [
"chunked"
],
"Cache-Control": [
"private, max-age=60, s-maxage=60"
],
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"Etag": [
"W/\"b3e29c2607b804ddc4762de34fc90791462b0a94836b2e3073841e6b305f0e6e\""
],
"X-Oauth-Scopes": [
"repo, workflow"
],
"X-Accepted-Oauth-Scopes": [
""
],
"Github-Authentication-Token-Expiration": [
"2022-09-20 23:45:13 UTC"
],
"X-Github-Media-Type": [
"github.v3; format=json"
],
"X-Github-Api-Version-Selected": [
"2022-08-09"
],
"X-Ratelimit-Limit": [
"5000"
],
"X-Ratelimit-Remaining": [
"4994"
],
"X-Ratelimit-Reset": [
"1663119007"
],
"X-Ratelimit-Used": [
"6"
],
"X-Ratelimit-Resource": [
"core"
],
"Access-Control-Expose-Headers": [
"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, 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": [
"0"
],
"Referrer-Policy": [
"origin-when-cross-origin, strict-origin-when-cross-origin"
],
"Content-Security-Policy": [
"default-src 'none'"
],
"X-Github-Request-Id": [
"0405:0770:2B5BB:2CF24:63212091"
]
},
"body": {
"encoding": "ASCII-8BIT",
"base64_string": "eyJpZCI6MzYyNTE4NTk0LCJub2RlX2lkIjoiTURnNlFYSjBhV1poWTNRek5q\nSTFNVGcxT1RRPSIsIm5hbWUiOiJoZWxsby50eHQiLCJzaXplX2luX2J5dGVz\nIjoxNCwidXJsIjoiaHR0cHM6Ly9hcGkuZ2l0aHViLmNvbS9yZXBvcy88R0lU\nSFVCX0xPR0lOPi88R0lUSFVCX1RFU1RfUkVQT1NJVE9SWT4vYWN0aW9ucy9h\ncnRpZmFjdHMvMzYyNTE4NTk0IiwiYXJjaGl2ZV9kb3dubG9hZF91cmwiOiJo\ndHRwczovL2FwaS5naXRodWIuY29tL3JlcG9zLzxHSVRIVUJfTE9HSU4+LzxH\nSVRIVUJfVEVTVF9SRVBPU0lUT1JZPi9hY3Rpb25zL2FydGlmYWN0cy8zNjI1\nMTg1OTQvemlwIiwiZXhwaXJlZCI6ZmFsc2UsImNyZWF0ZWRfYXQiOiIyMDIy\nLTA5LTE0VDAwOjI0OjQ1WiIsInVwZGF0ZWRfYXQiOiIyMDIyLTA5LTE0VDAw\nOjI0OjQ2WiIsImV4cGlyZXNfYXQiOiIyMDIyLTA5LTE1VDAwOjI0OjQyWiIs\nIndvcmtmbG93X3J1biI6eyJpZCI6MzA0OTI5ODAyMywicmVwb3NpdG9yeV9p\nZCI6MTk5MDI2MzE1LCJoZWFkX3JlcG9zaXRvcnlfaWQiOjE5OTAyNjMxNSwi\naGVhZF9icmFuY2giOiJtYXN0ZXIiLCJoZWFkX3NoYSI6Ijk5OWJlODY3MzNk\nNWJmNGE2NzIyZDc4ZjMzYjJkZGMyNDI0Yzc5OGQifX0=\n"
}
},
"recorded_at": "Wed, 14 Sep 2022 00:30:09 GMT"
}
],
"recorded_with": "VCR 6.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"http_interactions": [
{
"request": {
"method": "head",
"uri": "https://api.github.com/repos/<GITHUB_LOGIN>/<GITHUB_TEST_REPOSITORY>/actions/artifacts/362518594/zip",
"body": {
"encoding": "US-ASCII",
"base64_string": ""
},
"headers": {
"Accept": [
"application/vnd.github.v3+json"
],
"User-Agent": [
"Octokit Ruby Gem 5.5.0"
],
"Authorization": [
"token <<ACCESS_TOKEN>>"
]
}
},
"response": {
"status": {
"code": 302,
"message": "Found"
},
"headers": {
"Server": [
"GitHub.com"
],
"Date": [
"Wed, 14 Sep 2022 00:30:10 GMT"
],
"Content-Type": [
"text/html;charset=utf-8"
],
"Content-Length": [
"0"
],
"Location": [
"https://pipelines.actions.githubusercontent.com/serviceHosts/833a0c19-e430-43c5-ad4b-ffd8a794e906/_apis/pipelines/1/runs/3/signedartifactscontent?artifactName=hello.txt&urlExpires=2022-09-14T00%3A31%3A10.3987297Z&urlSigningMethod=HMACV2&urlSignature=bcxwAz34CgmtYfPXvslRZNWm2pVI9vH61nZqA996X0A%3D"
],
"X-Github-Api-Version-Selected": [
"2022-08-09"
],
"X-Ratelimit-Limit": [
"5000"
],
"X-Ratelimit-Remaining": [
"4992"
],
"X-Ratelimit-Reset": [
"1663119007"
],
"X-Ratelimit-Used": [
"8"
],
"X-Ratelimit-Resource": [
"core"
],
"Access-Control-Expose-Headers": [
"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, 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": [
"0"
],
"Referrer-Policy": [
"origin-when-cross-origin, strict-origin-when-cross-origin"
],
"Content-Security-Policy": [
"default-src 'none'"
],
"Vary": [
"Accept-Encoding, Accept, X-Requested-With"
],
"X-Github-Request-Id": [
"0407:949B:2F9974F:30C78CD:63212092"
]
},
"body": {
"encoding": "UTF-8",
"base64_string": ""
}
},
"recorded_at": "Wed, 14 Sep 2022 00:30:10 GMT"
}
],
"recorded_with": "VCR 6.1.0"
}
Loading