-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52e099a
Add support for the actions artifacts API
lerebear d41dcb5
Add missing frozen string literal comments
lerebear 6b40a83
Fix tests so they work correctly with VCR
lerebear f8859a7
Update docs URLs
timrogers 5b6cbd7
Make assertion for `delete_artifact` more explicit
timrogers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 |
124 changes: 124 additions & 0 deletions
124
spec/cassettes/Octokit_Client_ActionsArtifacts/_artifact/returns_the_requested_artifact.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
102 changes: 102 additions & 0 deletions
102
...ActionsArtifacts/_artifact_download_url/returns_the_location_of_artifact_zip_archive.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.