github_api2 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +770 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +741 -0
  5. data/lib/github_api2/api/actions.rb +60 -0
  6. data/lib/github_api2/api/arguments.rb +253 -0
  7. data/lib/github_api2/api/config/property.rb +30 -0
  8. data/lib/github_api2/api/config/property_set.rb +120 -0
  9. data/lib/github_api2/api/config.rb +105 -0
  10. data/lib/github_api2/api/factory.rb +33 -0
  11. data/lib/github_api2/api.rb +398 -0
  12. data/lib/github_api2/authorization.rb +75 -0
  13. data/lib/github_api2/client/activity/events.rb +233 -0
  14. data/lib/github_api2/client/activity/feeds.rb +50 -0
  15. data/lib/github_api2/client/activity/notifications.rb +181 -0
  16. data/lib/github_api2/client/activity/starring.rb +130 -0
  17. data/lib/github_api2/client/activity/watching.rb +176 -0
  18. data/lib/github_api2/client/activity.rb +31 -0
  19. data/lib/github_api2/client/authorizations/app.rb +98 -0
  20. data/lib/github_api2/client/authorizations.rb +142 -0
  21. data/lib/github_api2/client/emojis.rb +19 -0
  22. data/lib/github_api2/client/gists/comments.rb +100 -0
  23. data/lib/github_api2/client/gists.rb +289 -0
  24. data/lib/github_api2/client/git_data/blobs.rb +51 -0
  25. data/lib/github_api2/client/git_data/commits.rb +101 -0
  26. data/lib/github_api2/client/git_data/references.rb +150 -0
  27. data/lib/github_api2/client/git_data/tags.rb +95 -0
  28. data/lib/github_api2/client/git_data/trees.rb +113 -0
  29. data/lib/github_api2/client/git_data.rb +31 -0
  30. data/lib/github_api2/client/gitignore.rb +57 -0
  31. data/lib/github_api2/client/issues/assignees.rb +77 -0
  32. data/lib/github_api2/client/issues/comments.rb +146 -0
  33. data/lib/github_api2/client/issues/events.rb +50 -0
  34. data/lib/github_api2/client/issues/labels.rb +189 -0
  35. data/lib/github_api2/client/issues/milestones.rb +146 -0
  36. data/lib/github_api2/client/issues.rb +248 -0
  37. data/lib/github_api2/client/markdown.rb +62 -0
  38. data/lib/github_api2/client/meta.rb +19 -0
  39. data/lib/github_api2/client/orgs/hooks.rb +182 -0
  40. data/lib/github_api2/client/orgs/members.rb +142 -0
  41. data/lib/github_api2/client/orgs/memberships.rb +131 -0
  42. data/lib/github_api2/client/orgs/projects.rb +57 -0
  43. data/lib/github_api2/client/orgs/teams.rb +407 -0
  44. data/lib/github_api2/client/orgs.rb +127 -0
  45. data/lib/github_api2/client/projects/cards.rb +158 -0
  46. data/lib/github_api2/client/projects/columns.rb +146 -0
  47. data/lib/github_api2/client/projects.rb +83 -0
  48. data/lib/github_api2/client/pull_requests/comments.rb +140 -0
  49. data/lib/github_api2/client/pull_requests/reviews.rb +158 -0
  50. data/lib/github_api2/client/pull_requests.rb +195 -0
  51. data/lib/github_api2/client/repos/branches/protections.rb +75 -0
  52. data/lib/github_api2/client/repos/branches.rb +48 -0
  53. data/lib/github_api2/client/repos/collaborators.rb +84 -0
  54. data/lib/github_api2/client/repos/comments.rb +125 -0
  55. data/lib/github_api2/client/repos/commits.rb +80 -0
  56. data/lib/github_api2/client/repos/contents.rb +263 -0
  57. data/lib/github_api2/client/repos/deployments.rb +138 -0
  58. data/lib/github_api2/client/repos/downloads.rb +62 -0
  59. data/lib/github_api2/client/repos/forks.rb +50 -0
  60. data/lib/github_api2/client/repos/hooks.rb +214 -0
  61. data/lib/github_api2/client/repos/invitations.rb +41 -0
  62. data/lib/github_api2/client/repos/keys.rb +104 -0
  63. data/lib/github_api2/client/repos/merging.rb +47 -0
  64. data/lib/github_api2/client/repos/pages.rb +48 -0
  65. data/lib/github_api2/client/repos/projects.rb +62 -0
  66. data/lib/github_api2/client/repos/pub_sub_hubbub.rb +133 -0
  67. data/lib/github_api2/client/repos/releases/assets.rb +136 -0
  68. data/lib/github_api2/client/repos/releases/tags.rb +24 -0
  69. data/lib/github_api2/client/repos/releases.rb +189 -0
  70. data/lib/github_api2/client/repos/statistics.rb +89 -0
  71. data/lib/github_api2/client/repos/statuses.rb +91 -0
  72. data/lib/github_api2/client/repos.rb +473 -0
  73. data/lib/github_api2/client/say.rb +25 -0
  74. data/lib/github_api2/client/scopes.rb +46 -0
  75. data/lib/github_api2/client/search/legacy.rb +111 -0
  76. data/lib/github_api2/client/search.rb +133 -0
  77. data/lib/github_api2/client/users/emails.rb +65 -0
  78. data/lib/github_api2/client/users/followers.rb +115 -0
  79. data/lib/github_api2/client/users/keys.rb +104 -0
  80. data/lib/github_api2/client/users.rb +117 -0
  81. data/lib/github_api2/client.rb +77 -0
  82. data/lib/github_api2/configuration.rb +70 -0
  83. data/lib/github_api2/connection.rb +82 -0
  84. data/lib/github_api2/constants.rb +61 -0
  85. data/lib/github_api2/core_ext/array.rb +25 -0
  86. data/lib/github_api2/core_ext/hash.rb +91 -0
  87. data/lib/github_api2/deprecation.rb +39 -0
  88. data/lib/github_api2/error/client_error.rb +89 -0
  89. data/lib/github_api2/error/service_error.rb +223 -0
  90. data/lib/github_api2/error.rb +32 -0
  91. data/lib/github_api2/ext/faraday.rb +40 -0
  92. data/lib/github_api2/mash.rb +7 -0
  93. data/lib/github_api2/middleware.rb +37 -0
  94. data/lib/github_api2/mime_type.rb +33 -0
  95. data/lib/github_api2/normalizer.rb +23 -0
  96. data/lib/github_api2/null_encoder.rb +25 -0
  97. data/lib/github_api2/page_iterator.rb +138 -0
  98. data/lib/github_api2/page_links.rb +63 -0
  99. data/lib/github_api2/paged_request.rb +42 -0
  100. data/lib/github_api2/pagination.rb +115 -0
  101. data/lib/github_api2/parameter_filter.rb +35 -0
  102. data/lib/github_api2/params_hash.rb +115 -0
  103. data/lib/github_api2/rate_limit.rb +25 -0
  104. data/lib/github_api2/request/basic_auth.rb +36 -0
  105. data/lib/github_api2/request/jsonize.rb +54 -0
  106. data/lib/github_api2/request/oauth2.rb +45 -0
  107. data/lib/github_api2/request/verbs.rb +63 -0
  108. data/lib/github_api2/request.rb +84 -0
  109. data/lib/github_api2/response/atom_parser.rb +22 -0
  110. data/lib/github_api2/response/follow_redirects.rb +140 -0
  111. data/lib/github_api2/response/header.rb +87 -0
  112. data/lib/github_api2/response/jsonize.rb +28 -0
  113. data/lib/github_api2/response/mashify.rb +24 -0
  114. data/lib/github_api2/response/raise_error.rb +22 -0
  115. data/lib/github_api2/response/xmlize.rb +28 -0
  116. data/lib/github_api2/response.rb +48 -0
  117. data/lib/github_api2/response_wrapper.rb +161 -0
  118. data/lib/github_api2/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api2/utils/url.rb +63 -0
  120. data/lib/github_api2/validations/format.rb +26 -0
  121. data/lib/github_api2/validations/presence.rb +32 -0
  122. data/lib/github_api2/validations/required.rb +21 -0
  123. data/lib/github_api2/validations/token.rb +41 -0
  124. data/lib/github_api2/validations.rb +22 -0
  125. data/lib/github_api2/version.rb +5 -0
  126. data/lib/github_api2.rb +92 -0
  127. metadata +363 -0
@@ -0,0 +1,214 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # The Repository Hooks API manages the post-receive web and
7
+ # service hooks for a repository.
8
+ class Client::Repos::Hooks < API
9
+
10
+ VALID_HOOK_PARAM_NAMES = %w[
11
+ name
12
+ config
13
+ active
14
+ events
15
+ add_events
16
+ remove_events
17
+ ].freeze # :nodoc:
18
+
19
+ # Active hooks can be configured to trigger for one or more events.
20
+ # The default event is push. The available events are:
21
+ VALID_HOOK_PARAM_VALUES = {
22
+ 'events' => %w[
23
+ push
24
+ issues
25
+ issue_comment
26
+ commit_comment
27
+ pull_request
28
+ gollum
29
+ watch
30
+ download
31
+ fork
32
+ fork_apply
33
+ member
34
+ public
35
+ ]
36
+ }.freeze # :nodoc:
37
+
38
+ REQUIRED_PARAMS = %w[ name config ].freeze # :nodoc:
39
+
40
+ # List repository hooks
41
+ #
42
+ # @example
43
+ # github = Github.new
44
+ # github.repos.hooks.list 'user-name', 'repo-name'
45
+ # github.repos.hooks.list 'user-name', 'repo-name' { |hook| ... }
46
+ #
47
+ # @api public
48
+ def list(*args)
49
+ arguments(args, required: [:user, :repo])
50
+
51
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/hooks", arguments.params)
52
+ return response unless block_given?
53
+ response.each { |el| yield el }
54
+ end
55
+ alias :all :list
56
+
57
+ # Get a single hook
58
+ #
59
+ # @example
60
+ # github = Github.new
61
+ # github.repos.hooks.get 'user-name', 'repo-name', 'hook-id'
62
+ #
63
+ # @api public
64
+ def get(*args)
65
+ arguments(args, required: [:user, :repo, :id])
66
+
67
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}", arguments.params)
68
+ end
69
+ alias :find :get
70
+
71
+ # Create a hook
72
+ #
73
+ # @param [Hash] params
74
+ # @input params [String] :name
75
+ # Required. The name of the service that is being called.
76
+ # @input params [Hash] :config
77
+ # Required. Key/value pairs to provide settings for this hook.
78
+ # These settings vary between the services and are defined in
79
+ # the github-services repository. Booleans are stored internally
80
+ # as “1” for true, and “0” for false. Any JSON true/false values
81
+ # will be converted automatically.
82
+ # @input params [Array] :events
83
+ # Determines what events the hook is triggered for. Default: ["push"]
84
+ # @input params [Boolean] :active
85
+ # Determines whether the hook is actually triggered on pushes.
86
+ #
87
+ # To create a webhook, the following fields are required by the config:
88
+ #
89
+ # @input config [String] :url
90
+ # A required string defining the URL to which the payloads
91
+ # will be delivered.
92
+ # @input config [String] :content_type
93
+ # An optional string defining the media type used to serialize
94
+ # the payloads. Supported values include json and form.
95
+ # The default is form.
96
+ # @input config [String] :secret
97
+ # An optional string that’s passed with the HTTP requests as
98
+ # an X-Hub-Signature header. The value of this header is
99
+ # computed as the HMAC hex digest of the body,
100
+ # using the secret as the key.
101
+ # @input config [String] :insecure_ssl
102
+ # An optional string that determines whether the SSL certificate
103
+ # of the host for url will be verified when delivering payloads.
104
+ # Supported values include "0" (verification is performed) and
105
+ # "1" (verification is not performed). The default is "0".
106
+ #
107
+ # @example
108
+ # github = Github.new
109
+ # github.repos.hooks.create 'user-name', 'repo-name',
110
+ # name: "web",
111
+ # active: true,
112
+ # config: {
113
+ # url: "http://something.com/webhook"
114
+ # }
115
+ # }
116
+ #
117
+ # @api public
118
+ def create(*args)
119
+ arguments(args, required: [:user, :repo]) do
120
+ permit VALID_HOOK_PARAM_NAMES, recursive: false
121
+ assert_required REQUIRED_PARAMS
122
+ end
123
+
124
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/hooks", arguments.params)
125
+ end
126
+
127
+ # Edit a hook
128
+ #
129
+ # @param [Hash] params
130
+ # @input params [Hash] :config
131
+ # Required. Key/value pairs to provide settings for this hook.
132
+ # These settings vary between the services and are defined in
133
+ # the github-services repository. Booleans are stored internally
134
+ # as “1” for true, and “0” for false. Any JSON true/false values
135
+ # will be converted automatically.
136
+ # @input params [Array] :events
137
+ # Determines what events the hook is triggered for. Default: ["push"]
138
+ # @input params [Array] :add_events
139
+ # Determines a list of events to be added to the list of events
140
+ # that the Hook triggers for.
141
+ # @input params [Array] :remove_events
142
+ # Determines a list of events to be removed from the list of
143
+ # events that the Hook triggers for.
144
+ # @input params [Boolean] :active
145
+ # Determines whether the hook is actually triggered on pushes.
146
+ #
147
+ # @example
148
+ # github = Github.new
149
+ # github.repos.hooks.edit 'user-name', 'repo-name', 'hook-id',
150
+ # "name" => "campfire",
151
+ # "active" => true,
152
+ # "config" => {
153
+ # "subdomain" => "github",
154
+ # "room" => "Commits",
155
+ # "token" => "abc123"
156
+ # }
157
+ #
158
+ # @api public
159
+ def edit(*args)
160
+ arguments(args, required: [:user, :repo, :id]) do
161
+ permit VALID_HOOK_PARAM_NAMES, recursive: false
162
+ assert_required REQUIRED_PARAMS
163
+ end
164
+
165
+ patch_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}", arguments.params)
166
+ end
167
+
168
+ # Test a hook
169
+ #
170
+ # This will trigger the hook with the latest push to the current
171
+ # repository if the hook is subscribed to push events. If the hook
172
+ # is not subscribed to push events, the server will respond with 204
173
+ # but no test POST will be generated.
174
+ #
175
+ # @example
176
+ # github = Github.new
177
+ # github.repos.hooks.test 'user-name', 'repo-name', 'hook-id'
178
+ #
179
+ # @api public
180
+ def test(*args)
181
+ arguments(args, required: [:user, :repo, :id])
182
+
183
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}/tests", arguments.params)
184
+ end
185
+
186
+ # Ping a hook
187
+ #
188
+ # This will trigger a ping event to be sent to the hook.
189
+ #
190
+ # @example
191
+ # github = Github.new
192
+ # github.repos.hooks.ping 'user-name', 'repo-name', 'hook-id'
193
+ #
194
+ # @api public
195
+ def ping(*args)
196
+ arguments(args, required: [:user, :repo, :id])
197
+
198
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}/pings", arguments.params)
199
+ end
200
+
201
+ # Delete a hook
202
+ #
203
+ # @example
204
+ # github = Github.new
205
+ # github.repos.hooks.delete 'user-name', 'repo-name', 'hook-id'
206
+ #
207
+ # @api public
208
+ def delete(*args)
209
+ arguments(args, required: [:user, :repo, :id])
210
+
211
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}/hooks/#{arguments.id}", arguments.params)
212
+ end
213
+ end # Client::Repos::Hooks
214
+ end # Github
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::Invitations < API
7
+ # List repo invitations
8
+ #
9
+ # @example
10
+ # github = Github.new
11
+ # github.repos.invitations.list 'user-name', 'repo-name'
12
+ #
13
+ # @example
14
+ # github.repos.invitations.list 'user-name', 'repo-name' { |cbr| .. }
15
+ #
16
+ # @return [Array]
17
+ #
18
+ # @api public
19
+ def list(*args)
20
+ arguments(args, required: [:user, :repo])
21
+
22
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/invitations", arguments.params)
23
+ return response unless block_given?
24
+ response.each { |el| yield el }
25
+ end
26
+ alias :all :list
27
+
28
+ # Deletes a repo invitation
29
+ #
30
+ # @example
31
+ # github = Github.new
32
+ # github.repos.invitations.delete 'user-name', 'repo-name', 'invitation-id'
33
+ #
34
+ # @api public
35
+ def delete(*args)
36
+ arguments(args, required: [:user, :repo, :id])
37
+
38
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}/invitations/#{arguments.id}", arguments.params)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::Keys < API
7
+ # List deploy keys
8
+ #
9
+ # @see https://developer.github.com/v3/repos/keys/#list
10
+ #
11
+ # @param [String] :user
12
+ # @param [String :repo
13
+ #
14
+ # @example
15
+ # github = Github.new
16
+ # github.repos.keys.list 'user-name', 'repo-name'
17
+ # github.repos.keys.list 'user-name', 'repo-name' { |key| ... }
18
+ #
19
+ # @example
20
+ # keys = Github::Repos::Keys.new user: 'user-name', repo: 'repo-name'
21
+ # keys.list
22
+ #
23
+ # @api public
24
+ def list(*args)
25
+ arguments(args, required: [:user, :repo])
26
+
27
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/keys",
28
+ arguments.params)
29
+ return response unless block_given?
30
+ response.each { |el| yield el }
31
+ end
32
+ alias_method :all, :list
33
+
34
+ # Get a key
35
+ #
36
+ # @see https://developer.github.com/v3/repos/keys/#get
37
+ #
38
+ # @param [String] :user
39
+ # @param [String] :repo
40
+ # @param [Integer] :id
41
+ #
42
+ # @example
43
+ # github = Github.new
44
+ # github.repos.keys.get 'user-name', 'repo-name', 'key-id'
45
+ #
46
+ # @api public
47
+ def get(*args)
48
+ arguments(args, required: [:user, :repo, :id])
49
+
50
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/keys/#{arguments.id}", arguments.params)
51
+ end
52
+ alias_method :find, :get
53
+
54
+ # Create a key
55
+ #
56
+ # @see https://developer.github.com/v3/repos/keys/#create
57
+ #
58
+ # @param [String] :user
59
+ # @param [String] :repo
60
+ # @param [Hash] params
61
+ # @option params [String] :title
62
+ # Required string.
63
+ # @option params [String] :key
64
+ # Required string.
65
+ # @option params [String] :read_only
66
+ # If true, the key will only be able to read repository contents.
67
+ # Otherwise, the key will be able to read and write.
68
+ #
69
+ # @example
70
+ # github = Github.new
71
+ # github.repos.keys.create 'user-name', 'repo-name',
72
+ # title: "octocat@octomac",
73
+ # key: "ssh-rsa AAA..."
74
+ #
75
+ # @api public
76
+ def create(*args)
77
+ arguments(args, required: [:user, :repo])
78
+
79
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/keys",
80
+ arguments.params)
81
+ end
82
+ alias_method :add, :create
83
+
84
+ # Delete key
85
+ #
86
+ # @see https://developer.github.com/v3/repos/keys/#delete
87
+ #
88
+ # @param [String] :user
89
+ # @param [String] :repo
90
+ # @param [Integer] :id
91
+ #
92
+ # @example
93
+ # github = Github.new
94
+ # github.repos.keys.delete 'user-name', 'repo-name', 'key-id'
95
+ #
96
+ # @api public
97
+ def delete(*args)
98
+ arguments(args, required: [:user, :repo, :id])
99
+
100
+ delete_request("/repos/#{arguments.user}/#{arguments.repo}/keys/#{arguments.id}", arguments.params)
101
+ end
102
+ alias_method :remove, :delete
103
+ end # Client::Repos::Keys
104
+ end # Github
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # The Repo Merging API supports merging branches in a repository. This
7
+ # accomplishes essentially the same thing as merging one branch into another
8
+ # in a local repository and then pushing to GitHub.
9
+ class Client::Repos::Merging < API
10
+
11
+ VALID_MERGE_PARAM_NAMES = %w[
12
+ base
13
+ head
14
+ commit_message
15
+ ].freeze # :nodoc:
16
+
17
+ REQUIRED_MERGE_PARAMS = %w[ base head ].freeze # :nodoc:
18
+
19
+ # Perform a merge
20
+ #
21
+ # @param [Hash] params
22
+ # @input params [String] :base
23
+ # Required. The name of the base branch that the head will be merged into.
24
+ # @input params [String] :head
25
+ # Required. The head to merge. This can be a branch name or a commit SHA1.
26
+ # @input params [String] :commit_message
27
+ # Commit message to use for the merge commit.
28
+ # If omitted, a default message will be used.
29
+ #
30
+ # @example
31
+ # github = Github.new
32
+ # github.repos.merging.merge 'user', 'repo',
33
+ # base: "master",
34
+ # head: "cool_feature",
35
+ # commit_message: "Shipped cool_feature!"
36
+ #
37
+ # @api public
38
+ def merge(*args)
39
+ arguments(args, required: [:user, :repo]) do
40
+ permit VALID_MERGE_PARAM_NAMES
41
+ assert_required REQUIRED_MERGE_PARAMS
42
+ end
43
+
44
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/merges", arguments.params)
45
+ end
46
+ end # Client::Repos::Merging
47
+ end # Github
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # The Pages API retrieves information about your GitHub Pages configuration,
7
+ # and the statuses of your builds. Information about the site and the builds
8
+ # can only be accessed by authenticated owners, even though the websites
9
+ # are public.
10
+ class Client::Repos::Pages < API
11
+
12
+ # List Pages builds
13
+ #
14
+ # @example
15
+ # github = Github.new
16
+ # github.repos.pages.list owner: 'owner-name', repo: 'repo-name'
17
+ #
18
+ # github = Github.new
19
+ # github.repos.pages.list :latest, owner: 'owner-name', repo: 'repo-name'
20
+ # @api public
21
+ def list(*args)
22
+ arguments(args, required: [:owner, :repo])
23
+
24
+ response = if args.map(&:to_s).include?('latest')
25
+ get_request("/repos/#{arguments.owner}/#{arguments.repo}/pages/builds/latest", arguments.params)
26
+ else
27
+ get_request("/repos/#{arguments.owner}/#{arguments.repo}/pages/builds", arguments.params)
28
+ end
29
+ return response unless block_given?
30
+ response.each { |el| yield el }
31
+ end
32
+ alias :all :list
33
+
34
+ # Get information about a Pages site
35
+ #
36
+ # @example
37
+ # github = Github.new
38
+ # github.repos.pages.get owner: 'owner-name', repo: 'repo-name'
39
+ #
40
+ # @api public
41
+ def get(*args)
42
+ arguments(args, required: [:owner, :repo])
43
+
44
+ get_request("/repos/#{arguments.owner}/#{arguments.repo}/pages", arguments.params)
45
+ end
46
+ alias :find :get
47
+ end # Client::Repos::Pages
48
+ end # Github
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::Projects < API
7
+ PREVIEW_MEDIA = "application/vnd.github.inertia-preview+json".freeze # :nodoc:
8
+
9
+ # List a repo's projects
10
+ #
11
+ # @example
12
+ # github = Github.new
13
+ # github.repos.projects.list owner: 'owner-name', repo: 'repo-name'
14
+ #
15
+ # @example
16
+ # github = Github.new
17
+ # github.repos.projects.list state: 'open', owner: 'owner-name', repo: 'repo-name'
18
+ #
19
+ # @example
20
+ # github.repos.projects.list owner: 'owner-name', repo: 'repo-name' { |cbr| .. }
21
+ #
22
+ # @return [Array]
23
+ #
24
+ # @api public
25
+ def list(*args)
26
+ arguments(args, required: [:owner, :repo])
27
+ params = arguments.params
28
+
29
+ params["accept"] ||= PREVIEW_MEDIA
30
+
31
+ response = get_request("/repos/#{arguments.owner}/#{arguments.repo}/projects", params)
32
+ return response unless block_given?
33
+ response.each { |el| yield el }
34
+ end
35
+ alias :all :list
36
+
37
+ # Create a new project for the specified repo
38
+ #
39
+ # @param [Hash] params
40
+ # @option params [String] :name
41
+ # Required string - The name of the project.
42
+ # @option params [String] :body
43
+ # Optional string - The body of the project.
44
+ #
45
+ # @example
46
+ # github = Github.new
47
+ # github.repos.projects.create 'owner-name', 'repo-name', name: 'project-name'
48
+ # github.repos.projects.create name: 'project-name', body: 'project-body', owner: 'owner-name', repo: 'repo-name'
49
+ #
50
+ # @api public
51
+ def create(*args)
52
+ arguments(args, required: [:owner, :repo]) do
53
+ assert_required %w[ name ]
54
+ end
55
+ params = arguments.params
56
+
57
+ params["accept"] ||= PREVIEW_MEDIA
58
+
59
+ post_request("/repos/#{arguments.owner}/#{arguments.repo}/projects", params)
60
+ end
61
+ end # Projects
62
+ end # Github
@@ -0,0 +1,133 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::PubSubHubbub < API
7
+ HEADERS = {
8
+ CONTENT_TYPE => 'application/x-www-form-urlencoded'
9
+ }
10
+
11
+ # Subscribe to existing topic/event through pubsubhubbub
12
+ #
13
+ # @param [Hash] params
14
+ # @input params [String] :topic
15
+ # Required string. The URI of the GitHub repository to subscribe to.
16
+ # The path must be in the format of /:user/:repo/events/:event.
17
+ # @input params [String] :callback
18
+ # Required string - The URI to receive the updates to the topic.
19
+ #
20
+ # @example
21
+ # github = Github.new oauth_token: 'token'
22
+ # github.repos.pubsubhubbub.subscribe
23
+ # 'https://github.com/:user/:repo/events/push',
24
+ # 'github://Email?address=peter-murach@gmail.com',
25
+ # verify: 'sync',
26
+ # secret: '...'
27
+ #
28
+ # @api public
29
+ def subscribe(*args)
30
+ params = arguments(args, required: [:topic, :callback]).params
31
+ _merge_action!("subscribe", arguments.topic, arguments.callback, params)
32
+ params['headers'] = HEADERS
33
+
34
+ post_request("/hub", params)
35
+ end
36
+
37
+ # Unsubscribe from existing topic/event through pubsubhubbub
38
+ #
39
+ # @param [Hash] params
40
+ # @input params [String] :topic
41
+ # Required string. The URI of the GitHub repository to
42
+ # unsubscribe from. The path must be in the format of
43
+ # /:user/:repo/events/:event.
44
+ # @input params [String] :callback
45
+ # Required string. The URI to unsubscribe the topic from.
46
+ #
47
+ # @example
48
+ # github = Github.new oauth_token: 'token'
49
+ # github.repos.pubsubhubbub.unsubscribe
50
+ # 'https://github.com/:user/:repo/events/push',
51
+ # 'github://Email?address=peter-murach@gmail.com',
52
+ # verify: 'sync',
53
+ # secret: '...'
54
+ #
55
+ # @api public
56
+ def unsubscribe(*args)
57
+ params = arguments(args, required: [:topic, :callback]).params
58
+ _merge_action!("unsubscribe", arguments.topic, arguments.callback, params)
59
+ params['headers'] = HEADERS
60
+
61
+ post_request("/hub", params)
62
+ end
63
+
64
+ # Subscribe repository to service hook through pubsubhubbub
65
+ #
66
+ # @param [Hash] params
67
+ # @input params [String] :event
68
+ # Required hash key for the type of event. The default event is push.
69
+ #
70
+ # @example
71
+ # github = Github.new oauth_token: '...'
72
+ # github.repos.pubsubhubbub.subscribe_service 'user-name', 'repo-name',
73
+ # 'campfire',
74
+ # subdomain: 'github',
75
+ # room: 'Commits',
76
+ # token: 'abc123',
77
+ # event: 'watch'
78
+ #
79
+ # @api public
80
+ def subscribe_service(*args)
81
+ params = arguments(args, required: [:user, :repo, :service]).params
82
+ event = params.delete('event') || 'push'
83
+ topic = "#{site}/#{arguments.user}/#{arguments.repo}/events/#{event}"
84
+ callback = "github://#{arguments.service}?#{params.serialize}"
85
+
86
+ subscribe(topic, callback)
87
+ end
88
+ alias :subscribe_repository :subscribe_service
89
+ alias :subscribe_repo :subscribe_service
90
+
91
+ # Subscribe repository to service hook through pubsubhubbub
92
+ #
93
+ # @param [Hash] params
94
+ # @input params [String] :event
95
+ # Optional hash key for the type of event. The default event is push.
96
+ #
97
+ # @example
98
+ # github = Github.new oauth_token: '...'
99
+ # github.repos.pubsubhubbub.unsubscribe_service 'user-name', 'repo-name',
100
+ # 'campfire'
101
+ #
102
+ # @example
103
+ # github.repos.pubsubhubbub.unsubscribe_service
104
+ # user: 'user-name',
105
+ # repo: 'repo-name',
106
+ # service: 'service-name'
107
+ #
108
+ # @api public
109
+ def unsubscribe_service(*args)
110
+ params = arguments(args, required: [:user, :repo, :service]).params
111
+ event = params.delete('event') || 'push'
112
+ topic = "#{site}/#{arguments.user}/#{arguments.repo}/events/#{event}"
113
+ callback = "github://#{arguments.service}"
114
+
115
+ unsubscribe(topic, callback)
116
+ end
117
+ alias :unsubscribe_repository :unsubscribe_service
118
+ alias :unsubscribe_repo :unsubscribe_service
119
+
120
+ private
121
+
122
+ def _merge_action!(action, topic, callback, params) # :nodoc:
123
+ options = {
124
+ "hub.mode" => action.to_s,
125
+ "hub.topic" => topic.to_s,
126
+ "hub.callback" => callback,
127
+ "hub.verify" => params.delete('verify') || 'sync',
128
+ "hub.secret" => params.delete('secret') || ''
129
+ }
130
+ params.merge! options
131
+ end
132
+ end # Client::Repos::PubSubHubbub
133
+ end # Github