github_api 0.4.11 → 0.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +76 -72
- data/features/cassettes/gists/starred.yml +48 -0
- data/features/cassettes/pagination/repos/commits/list.yml +193 -0
- data/features/cassettes/pagination/repos/commits/next.yml +183 -0
- data/features/cassettes/pagination/repos/diff/next.yml +45 -0
- data/features/cassettes/pagination/repos/list.yml +176 -0
- data/features/cassettes/pagination/repos/list/next.yml +222 -0
- data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
- data/features/cassettes/repos/list.yml +92 -0
- data/features/error_codes.feature +1 -1
- data/features/gists.feature +12 -3
- data/features/gists/comments.feature +3 -3
- data/features/github_api.feature +13 -2
- data/features/pagination.feature +40 -39
- data/features/repos.feature +2 -2
- data/features/step_definitions/common_steps.rb +12 -0
- data/features/step_definitions/github_api_steps.rb +12 -1
- data/lib/github_api.rb +1 -1
- data/lib/github_api/api.rb +4 -2
- data/lib/github_api/api_factory.rb +11 -5
- data/lib/github_api/authorizations.rb +23 -32
- data/lib/github_api/client.rb +1 -0
- data/lib/github_api/events.rb +38 -38
- data/lib/github_api/filter.rb +1 -1
- data/lib/github_api/gists.rb +47 -42
- data/lib/github_api/gists/comments.rb +77 -84
- data/lib/github_api/git_data.rb +25 -6
- data/lib/github_api/git_data/blobs.rb +48 -45
- data/lib/github_api/git_data/commits.rb +76 -73
- data/lib/github_api/git_data/references.rb +137 -118
- data/lib/github_api/git_data/tags.rb +74 -70
- data/lib/github_api/git_data/trees.rb +88 -85
- data/lib/github_api/issues.rb +43 -31
- data/lib/github_api/issues/comments.rb +116 -119
- data/lib/github_api/issues/events.rb +20 -19
- data/lib/github_api/issues/labels.rb +200 -197
- data/lib/github_api/issues/milestones.rb +137 -134
- data/lib/github_api/orgs.rb +27 -23
- data/lib/github_api/orgs/members.rb +105 -108
- data/lib/github_api/orgs/teams.rb +236 -237
- data/lib/github_api/paged_request.rb +1 -1
- data/lib/github_api/pull_requests.rb +40 -42
- data/lib/github_api/pull_requests/comments.rb +140 -143
- data/lib/github_api/repos.rb +101 -67
- data/lib/github_api/repos/collaborators.rb +64 -68
- data/lib/github_api/repos/commits.rb +50 -39
- data/lib/github_api/repos/downloads.rb +107 -110
- data/lib/github_api/repos/forks.rb +38 -39
- data/lib/github_api/repos/hooks.rb +161 -167
- data/lib/github_api/repos/keys.rb +86 -86
- data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
- data/lib/github_api/repos/watching.rb +80 -82
- data/lib/github_api/request.rb +5 -9
- data/lib/github_api/users.rb +26 -16
- data/lib/github_api/users/emails.rb +47 -47
- data/lib/github_api/users/followers.rb +85 -86
- data/lib/github_api/users/keys.rb +73 -75
- data/lib/github_api/validations.rb +25 -0
- data/lib/github_api/validations/format.rb +23 -0
- data/lib/github_api/validations/presence.rb +25 -0
- data/lib/github_api/validations/required.rb +21 -0
- data/lib/github_api/validations/token.rb +41 -0
- data/lib/github_api/version.rb +3 -3
- data/spec/fixtures/repos/commit_comparison.json +112 -0
- data/spec/github/api_factory_spec.rb +17 -1
- data/spec/github/authorizations_spec.rb +36 -34
- data/spec/github/gists/comments_spec.rb +39 -45
- data/spec/github/gists_spec.rb +50 -53
- data/spec/github/git_data/blobs_spec.rb +27 -20
- data/spec/github/git_data/commits_spec.rb +20 -19
- data/spec/github/git_data/references_spec.rb +83 -46
- data/spec/github/git_data/tags_spec.rb +16 -15
- data/spec/github/git_data/trees_spec.rb +20 -19
- data/spec/github/git_data_spec.rb +10 -1
- data/spec/github/issues/comments_spec.rb +78 -68
- data/spec/github/issues/events_spec.rb +42 -34
- data/spec/github/issues/labels_spec.rb +89 -101
- data/spec/github/issues/milestones_spec.rb +76 -54
- data/spec/github/issues_spec.rb +53 -57
- data/spec/github/orgs/members_spec.rb +64 -49
- data/spec/github/orgs/teams_spec.rb +112 -101
- data/spec/github/orgs_spec.rb +41 -31
- data/spec/github/paged_request_spec.rb +6 -5
- data/spec/github/pull_requests/comments_spec.rb +39 -44
- data/spec/github/pull_requests_spec.rb +32 -48
- data/spec/github/repos/collaborators_spec.rb +40 -29
- data/spec/github/repos/commits_spec.rb +108 -64
- data/spec/github/repos/downloads_spec.rb +46 -45
- data/spec/github/repos/forks_spec.rb +23 -24
- data/spec/github/repos/hooks_spec.rb +69 -71
- data/spec/github/repos/keys_spec.rb +39 -34
- data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
- data/spec/github/repos/watching_spec.rb +31 -33
- data/spec/github/repos_spec.rb +74 -83
- data/spec/github/request_spec.rb +31 -2
- data/spec/github/users/emails_spec.rb +19 -17
- data/spec/github/users/followers_spec.rb +30 -28
- data/spec/github/users/keys_spec.rb +37 -33
- data/spec/github/users_spec.rb +124 -125
- data/spec/github/validations/format_spec.rb +42 -0
- data/spec/github/validations/presence_spec.rb +18 -0
- data/spec/github/validations/required_spec.rb +28 -0
- data/spec/github/validations/token_spec.rb +19 -0
- data/spec/github/validations_spec.rb +23 -0
- metadata +33 -10
- data/features/cassettes/pagination/repos.yml +0 -177
- data/features/cassettes/pagination/repos/next.yml +0 -177
- data/lib/github_api/validation.rb +0 -53
- data/spec/github/validation_spec.rb +0 -62
@@ -1,172 +1,166 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Github
|
4
|
-
class Repos
|
4
|
+
class Repos::Hooks < API
|
5
5
|
# The Repository Hooks API manages the post-receive web and service hooks for a repository.
|
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
|
-
delete("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
168
|
-
end
|
169
|
-
|
170
|
-
end # Hooks
|
171
|
-
end # Repos
|
6
|
+
|
7
|
+
VALID_HOOK_PARAM_NAMES = %w[
|
8
|
+
name
|
9
|
+
config
|
10
|
+
active
|
11
|
+
events
|
12
|
+
add_events
|
13
|
+
remove_events
|
14
|
+
].freeze # :nodoc:
|
15
|
+
|
16
|
+
# Active hooks can be configured to trigger for one or more events. The default event is push.
|
17
|
+
# The available events are:
|
18
|
+
VALID_HOOK_PARAM_VALUES = {
|
19
|
+
'events' => %w[
|
20
|
+
push
|
21
|
+
issues
|
22
|
+
issue_comment
|
23
|
+
commit_comment
|
24
|
+
pull_request
|
25
|
+
gollum
|
26
|
+
watch
|
27
|
+
download
|
28
|
+
fork
|
29
|
+
fork_apply
|
30
|
+
member
|
31
|
+
public
|
32
|
+
]
|
33
|
+
}.freeze # :nodoc:
|
34
|
+
|
35
|
+
REQUIRED_PARAMS = %w[ name config ].freeze # :nodoc:
|
36
|
+
|
37
|
+
# List repository hooks
|
38
|
+
#
|
39
|
+
# = Examples
|
40
|
+
# github = Github.new
|
41
|
+
# github.repos.hooks.list 'user-name', 'repo-name'
|
42
|
+
# github.repos.hooks.list 'user-name', 'repo-name' { |hook| ... }
|
43
|
+
#
|
44
|
+
def list(user_name, repo_name, params={})
|
45
|
+
_update_user_repo_params(user_name, repo_name)
|
46
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
47
|
+
_normalize_params_keys(params)
|
48
|
+
|
49
|
+
response = get_request("/repos/#{user}/#{repo}/hooks", params)
|
50
|
+
return response unless block_given?
|
51
|
+
response.each { |el| yield el }
|
52
|
+
end
|
53
|
+
alias :all :list
|
54
|
+
|
55
|
+
# Get a single hook
|
56
|
+
#
|
57
|
+
# = Examples
|
58
|
+
# github = Github.new
|
59
|
+
# github.repos.hooks.get 'user-name', 'repo-name'
|
60
|
+
#
|
61
|
+
def get(user_name, repo_name, hook_id, params={})
|
62
|
+
_update_user_repo_params(user_name, repo_name)
|
63
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
64
|
+
_validate_presence_of hook_id
|
65
|
+
_normalize_params_keys(params)
|
66
|
+
|
67
|
+
get_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
68
|
+
end
|
69
|
+
alias :find :get
|
70
|
+
|
71
|
+
# Create a hook
|
72
|
+
#
|
73
|
+
# = Inputs
|
74
|
+
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
75
|
+
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
76
|
+
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. Default: ["push"]
|
77
|
+
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
78
|
+
#
|
79
|
+
# = Examples
|
80
|
+
# github = Github.new
|
81
|
+
# github.repos.hooks.create 'user-name', 'repo-name',
|
82
|
+
# "name" => "web",
|
83
|
+
# "active" => true,
|
84
|
+
# "config" => {
|
85
|
+
# "url" => "http://something.com/webhook"
|
86
|
+
# }
|
87
|
+
# }
|
88
|
+
#
|
89
|
+
def create(user_name, repo_name, params={})
|
90
|
+
_update_user_repo_params(user_name, repo_name)
|
91
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
92
|
+
|
93
|
+
_normalize_params_keys(params)
|
94
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params, :recursive => false)
|
95
|
+
_validate_inputs(REQUIRED_PARAMS, params)
|
96
|
+
|
97
|
+
post_request("/repos/#{user}/#{repo}/hooks", params)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Edit a hook
|
101
|
+
#
|
102
|
+
# = Inputs
|
103
|
+
# * <tt>:name</tt> - Required string - the name of the service that is being called.
|
104
|
+
# * <tt>:config</tt> - Required hash - A Hash containing key/value pairs to provide settings for this hook.
|
105
|
+
# * <tt>:events</tt> - Optional array - Determines what events the hook is triggered for. This replaces the entire array of events. Default: ["push"].
|
106
|
+
# * <tt>:add_events</tt> - Optional array - Determines a list of events to be added to the list of events that the Hook triggers for.
|
107
|
+
# * <tt>:remove_events</tt> - Optional array - Determines a list of events to be removed from the list of events that the Hook triggers for.
|
108
|
+
# * <tt>:active</tt> - Optional boolean - Determines whether the hook is actually triggered on pushes.
|
109
|
+
#
|
110
|
+
# = Examples
|
111
|
+
# github = Github.new
|
112
|
+
# github.repos.hooks.edit 'user-name', 'repo-name',
|
113
|
+
# "name" => "campfire",
|
114
|
+
# "active" => true,
|
115
|
+
# "config" => {
|
116
|
+
# "subdomain" => "github",
|
117
|
+
# "room" => "Commits",
|
118
|
+
# "token" => "abc123"
|
119
|
+
# }
|
120
|
+
#
|
121
|
+
def edit(user_name, repo_name, hook_id, params={})
|
122
|
+
_update_user_repo_params(user_name, repo_name)
|
123
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
124
|
+
_validate_presence_of hook_id
|
125
|
+
|
126
|
+
_normalize_params_keys(params)
|
127
|
+
_filter_params_keys(VALID_HOOK_PARAM_NAMES, params, :recursive => false)
|
128
|
+
_validate_inputs(REQUIRED_PARAMS, params)
|
129
|
+
|
130
|
+
patch_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Test a hook
|
134
|
+
#
|
135
|
+
# This will trigger the hook with the latest push to the current repository.
|
136
|
+
#
|
137
|
+
# = Examples
|
138
|
+
# github = Github.new
|
139
|
+
# github.repos.hooks.test 'user-name', 'repo-name', 'hook-id'
|
140
|
+
#
|
141
|
+
def test(user_name, repo_name, hook_id, params={})
|
142
|
+
_update_user_repo_params(user_name, repo_name)
|
143
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
144
|
+
_validate_presence_of hook_id
|
145
|
+
_normalize_params_keys(params)
|
146
|
+
|
147
|
+
post_request("/repos/#{user}/#{repo}/hooks/#{hook_id}/test", params)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Delete a hook
|
151
|
+
#
|
152
|
+
# = Examples
|
153
|
+
# github = Github.new
|
154
|
+
# github.repos.hooks.delete 'user-name', 'repo-name', 'hook-id'
|
155
|
+
#
|
156
|
+
def delete(user_name, repo_name, hook_id, params={})
|
157
|
+
_update_user_repo_params(user_name, repo_name)
|
158
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
159
|
+
_validate_presence_of hook_id
|
160
|
+
_normalize_params_keys(params)
|
161
|
+
|
162
|
+
delete_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
163
|
+
end
|
164
|
+
|
165
|
+
end # Repos::Hooks
|
172
166
|
end # Github
|
@@ -1,103 +1,103 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Github
|
4
|
-
class Repos
|
5
|
-
module Keys
|
4
|
+
class Repos::Keys < API
|
6
5
|
|
7
|
-
|
6
|
+
VALID_KEY_PARAM_NAMES = %w[ title key ].freeze
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
# List deploy keys
|
9
|
+
#
|
10
|
+
# = Examples
|
11
|
+
# github = Github.new
|
12
|
+
# github.repos.keys.list 'user-name', 'repo-name'
|
13
|
+
# github.repos.keys.list 'user-name', 'repo-name' { |key| ... }
|
14
|
+
#
|
15
|
+
def list(user_name, repo_name, params={})
|
16
|
+
_update_user_repo_params(user_name, repo_name)
|
17
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
18
|
+
_normalize_params_keys(params)
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
response = get_request("/repos/#{user}/#{repo}/keys", params)
|
21
|
+
return response unless block_given?
|
22
|
+
response.each { |el| yield el }
|
23
|
+
end
|
24
|
+
alias :all :list
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
# Get a key
|
27
|
+
#
|
28
|
+
# = Examples
|
29
|
+
# github = Github.new
|
30
|
+
# github.repos.keys.get 'user-name', 'repo-name', 'key-id'
|
31
|
+
#
|
32
|
+
def get(user_name, repo_name, key_id, params={})
|
33
|
+
_update_user_repo_params(user_name, repo_name)
|
34
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
35
|
+
_validate_presence_of key_id
|
36
|
+
_normalize_params_keys(params)
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
get_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
39
|
+
end
|
40
|
+
alias :find :get
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
42
|
+
# Create a key
|
43
|
+
#
|
44
|
+
# = Inputs
|
45
|
+
# * <tt>:title</tt> - Required string.
|
46
|
+
# * <tt>:key</tt> - Required string.
|
47
|
+
#
|
48
|
+
# = Examples
|
49
|
+
# github = Github.new
|
50
|
+
# github.repos.keys.create 'user-name', 'repo-name',
|
51
|
+
# "title" => "octocat@octomac",
|
52
|
+
# "key" => "ssh-rsa AAA..."
|
53
|
+
#
|
54
|
+
def create(user_name, repo_name, params={})
|
55
|
+
_update_user_repo_params(user_name, repo_name)
|
56
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
57
|
+
_normalize_params_keys(params)
|
58
|
+
_filter_params_keys(VALID_KEY_PARAM_NAMES, params)
|
59
|
+
_validate_inputs(VALID_KEY_PARAM_NAMES, params)
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
post_request("/repos/#{user}/#{repo}/keys", params)
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
64
|
+
# Edit a key
|
65
|
+
#
|
66
|
+
# = Inputs
|
67
|
+
# * <tt>:title</tt> - Required string.
|
68
|
+
# * <tt>:key</tt> - Required string.
|
69
|
+
#
|
70
|
+
# = Examples
|
71
|
+
# github = Github.new
|
72
|
+
# github.repos.keys.edit 'user-name', 'repo-name',
|
73
|
+
# "title" => "octocat@octomac",
|
74
|
+
# "key" => "ssh-rsa AAA..."
|
75
|
+
#
|
76
|
+
def edit(user_name, repo_name, key_id, params={})
|
77
|
+
_update_user_repo_params(user_name, repo_name)
|
78
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
79
|
+
_validate_presence_of key_id
|
79
80
|
|
80
|
-
|
81
|
-
|
81
|
+
_normalize_params_keys(params)
|
82
|
+
_filter_params_keys(VALID_KEY_PARAM_NAMES, params)
|
82
83
|
|
83
|
-
|
84
|
-
|
84
|
+
patch_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
87
|
+
# Delete key
|
88
|
+
#
|
89
|
+
# = Examples
|
90
|
+
# @github = Github.new
|
91
|
+
# @github.repos.keys.delete 'user-name', 'repo-name', 'key-id'
|
92
|
+
#
|
93
|
+
def delete(user_name, repo_name, key_id, params={})
|
94
|
+
_update_user_repo_params(user_name, repo_name)
|
95
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
96
|
+
_validate_presence_of key_id
|
97
|
+
_normalize_params_keys(params)
|
97
98
|
|
98
|
-
|
99
|
-
|
99
|
+
delete_request("/repos/#{user}/#{repo}/keys/#{key_id}", params)
|
100
|
+
end
|
100
101
|
|
101
|
-
|
102
|
-
end # Repos
|
102
|
+
end # Repos::Keys
|
103
103
|
end # Github
|