File: apps.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 (211 lines) | stat: -rw-r--r-- 8,898 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# frozen_string_literal: true

module Octokit
  class Client
    # Methods for the Apps API
    module Apps
      # Get the authenticated App
      #
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/apps#get-the-authenticated-app
      #
      # @return [Sawyer::Resource] App information
      def app(options = {})
        get 'app', options
      end

      # List all installations that belong to an App
      #
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app
      #
      # @return [Array<Sawyer::Resource>] the total_count and an array of installations
      def list_app_installations(options = {})
        paginate 'app/installations', options
      end
      alias find_installations list_app_installations
      alias find_app_installations list_app_installations

      # List all installations that are accessible to the authenticated user
      #
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/installations#list-app-installations-accessible-to-the-user-access-token
      #
      # @return [Sawyer::Resource] the total_count and an array of installations
      def list_user_installations(options = {})
        paginate('user/installations', options) do |data, last_response|
          data.installations.concat last_response.data.installations
        end
      end
      alias find_user_installations list_user_installations

      # Get a single installation
      #
      # @param id [Integer] Installation id
      #
      # @see https://docs.github.com/en/rest/apps/apps#get-an-installation-for-the-authenticated-app
      #
      # @return [Sawyer::Resource] Installation information
      def installation(id, options = {})
        get "app/installations/#{id}", options
      end

      # Create a new installation token
      #
      # @param installation [Integer] The id of a GitHub App Installation
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app
      #
      # @return [<Sawyer::Resource>] An installation token
      def create_app_installation_access_token(installation, options = {})
        post "app/installations/#{installation}/access_tokens", options
      end
      alias create_installation_access_token create_app_installation_access_token

      # Enables an app to find the organization's installation information.
      #
      # @param organization [String] Organization GitHub login
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/apps#get-an-organization-installation-for-the-authenticated-app
      #
      # @return [Sawyer::Resource] Installation information
      def find_organization_installation(organization, options = {})
        get "#{Organization.path(organization)}/installation", options
      end

      # Enables an app to find the repository's installation information.
      #
      # @param repo [String] A GitHub repository
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/apps#get-a-repository-installation-for-the-authenticated-app
      #
      # @return [Sawyer::Resource] Installation information
      def find_repository_installation(repo, options = {})
        get "#{Repository.path(repo)}/installation", options
      end

      # Enables an app to find the user's installation information.
      #
      # @param user [String] GitHub user login
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/apps#get-a-user-installation-for-the-authenticated-app
      #
      # @return [Sawyer::Resource] Installation information
      def find_user_installation(user, options = {})
        get "#{User.path(user)}/installation", options
      end

      # List repositories that are accessible to the authenticated installation
      #
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/installations#list-repositories-accessible-to-the-app-installation
      #
      # @return [Sawyer::Resource] the total_count and an array of repositories
      def list_app_installation_repositories(options = {})
        paginate('installation/repositories', options) do |data, last_response|
          data.repositories.concat last_response.data.repositories
        end
      end
      alias list_installation_repos list_app_installation_repositories

      # Add a single repository to an installation
      #
      # @param installation [Integer] The id of a GitHub App Installation
      # @param repo [Integer] The id of the GitHub repository
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/installations#add-a-repository-to-an-app-installation
      #
      # @return [Boolean] Success
      def add_repository_to_app_installation(installation, repo, options = {})
        boolean_from_response :put, "user/installations/#{installation}/repositories/#{repo}", options
      end
      alias add_repo_to_installation add_repository_to_app_installation

      # Remove a single repository to an installation
      #
      # @param installation [Integer] The id of a GitHub App Installation
      # @param repo [Integer] The id of the GitHub repository
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/installations#remove-a-repository-from-an-app-installation
      #
      # @return [Boolean] Success
      def remove_repository_from_app_installation(installation, repo, options = {})
        boolean_from_response :delete, "user/installations/#{installation}/repositories/#{repo}", options
      end
      alias remove_repo_from_installation remove_repository_from_app_installation

      # List repositories accessible to the user for an installation
      #
      # @param installation [Integer] The id of a GitHub App Installation
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/installations#list-repositories-accessible-to-the-user-access-token
      #
      # @return [Sawyer::Resource] the total_count and an array of repositories
      def find_installation_repositories_for_user(installation, options = {})
        paginate("user/installations/#{installation}/repositories", options) do |data, last_response|
          data.repositories.concat last_response.data.repositories
        end
      end

      # Delete an installation and uninstall a GitHub App
      #
      # @param installation [Integer] The id of a GitHub App Installation
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/apps#delete-an-installation-for-the-authenticated-app
      #
      # @return [Boolean] Success
      def delete_installation(installation, options = {})
        boolean_from_response :delete, "app/installations/#{installation}", options
      end

      # Returns a list of webhook deliveries for the webhook configured for a GitHub App.
      #
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/webhooks#list-deliveries-for-an-app-webhook
      #
      # @return [Array<Hash>] an array of hook deliveries
      def list_app_hook_deliveries(options = {})
        paginate('app/hook/deliveries', options) do |data, last_response|
          data.concat last_response.data
        end
      end

      # Returns a delivery for the webhook configured for a GitHub App.
      #
      # @param delivery_id [String] The id of a GitHub App Hook Delivery
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/webhooks#get-a-delivery-for-an-app-webhook
      #
      # @return [<Sawyer::Resource>] The webhook delivery
      def app_hook_delivery(delivery_id, options = {})
        get "/app/hook/deliveries/#{delivery_id}", options
      end

      # Redeliver a delivery for the webhook configured for a GitHub App.
      #
      # @param delivery_id [Integer] The id of a GitHub App Hook Delivery
      # @param options [Hash] A customizable set of options
      #
      # @see https://docs.github.com/en/rest/apps/webhooks#redeliver-a-delivery-for-an-app-webhook
      #
      # @return [Boolean] Success
      def deliver_app_hook(delivery_id, options = {})
        boolean_from_response :post, "app/hook/deliveries/#{delivery_id}/attempts", options
      end
    end
  end
end