File: actions_artifacts.rb

package info (click to toggle)
ruby-octokit 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,092 kB
  • sloc: ruby: 13,339; sh: 99; makefile: 7; javascript: 3
file content (71 lines) | stat: -rw-r--r-- 2,869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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 do |data, last_response|
          data.artifacts.concat last_response.data.artifacts
        end
      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 do |data, last_response|
          data.artifacts.concat last_response.data.artifacts
        end
      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/artifacts#download-an-artifact
      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