github_api 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. metadata +4 -140
  2. data/LICENSE.txt +0 -20
  3. data/README.rdoc +0 -228
  4. data/Rakefile +0 -52
  5. data/features/github_api.feature +0 -50
  6. data/features/step_definitions/github_api_steps.rb +0 -11
  7. data/features/support/env.rb +0 -13
  8. data/lib/github_api.rb +0 -73
  9. data/lib/github_api/api.rb +0 -175
  10. data/lib/github_api/api/utils.rb +0 -9
  11. data/lib/github_api/authorization.rb +0 -73
  12. data/lib/github_api/authorizations.rb +0 -119
  13. data/lib/github_api/cache_control.rb +0 -19
  14. data/lib/github_api/client.rb +0 -55
  15. data/lib/github_api/compatibility.rb +0 -23
  16. data/lib/github_api/configuration.rb +0 -96
  17. data/lib/github_api/connection.rb +0 -81
  18. data/lib/github_api/core_ext/array.rb +0 -14
  19. data/lib/github_api/core_ext/hash.rb +0 -42
  20. data/lib/github_api/error.rb +0 -35
  21. data/lib/github_api/events.rb +0 -202
  22. data/lib/github_api/gists.rb +0 -200
  23. data/lib/github_api/gists/comments.rb +0 -86
  24. data/lib/github_api/git_data.rb +0 -26
  25. data/lib/github_api/git_data/blobs.rb +0 -51
  26. data/lib/github_api/git_data/commits.rb +0 -78
  27. data/lib/github_api/git_data/references.rb +0 -113
  28. data/lib/github_api/git_data/tags.rb +0 -78
  29. data/lib/github_api/git_data/trees.rb +0 -89
  30. data/lib/github_api/issues.rb +0 -215
  31. data/lib/github_api/issues/comments.rb +0 -110
  32. data/lib/github_api/issues/events.rb +0 -50
  33. data/lib/github_api/issues/labels.rb +0 -191
  34. data/lib/github_api/issues/milestones.rb +0 -119
  35. data/lib/github_api/mime_type.rb +0 -55
  36. data/lib/github_api/orgs.rb +0 -95
  37. data/lib/github_api/orgs/members.rb +0 -120
  38. data/lib/github_api/orgs/teams.rb +0 -245
  39. data/lib/github_api/pull_requests.rb +0 -224
  40. data/lib/github_api/pull_requests/comments.rb +0 -144
  41. data/lib/github_api/repos.rb +0 -286
  42. data/lib/github_api/repos/collaborators.rb +0 -81
  43. data/lib/github_api/repos/commits.rb +0 -180
  44. data/lib/github_api/repos/downloads.rb +0 -155
  45. data/lib/github_api/repos/forks.rb +0 -48
  46. data/lib/github_api/repos/hooks.rb +0 -173
  47. data/lib/github_api/repos/keys.rb +0 -104
  48. data/lib/github_api/repos/pub_sub_hubbub.rb +0 -102
  49. data/lib/github_api/repos/watching.rb +0 -94
  50. data/lib/github_api/request.rb +0 -84
  51. data/lib/github_api/request/basic_auth.rb +0 -31
  52. data/lib/github_api/request/caching.rb +0 -33
  53. data/lib/github_api/request/oauth2.rb +0 -33
  54. data/lib/github_api/response.rb +0 -28
  55. data/lib/github_api/response/helpers.rb +0 -14
  56. data/lib/github_api/response/jsonize.rb +0 -26
  57. data/lib/github_api/response/mashify.rb +0 -24
  58. data/lib/github_api/response/raise_error.rb +0 -33
  59. data/lib/github_api/result.rb +0 -42
  60. data/lib/github_api/users.rb +0 -84
  61. data/lib/github_api/users/emails.rb +0 -49
  62. data/lib/github_api/users/followers.rb +0 -98
  63. data/lib/github_api/users/keys.rb +0 -84
  64. data/lib/github_api/version.rb +0 -12
  65. data/spec/README.rdoc +0 -22
  66. data/spec/coverage_adapter.rb +0 -14
  67. data/spec/fixtures/auths/authorization.json +0 -14
  68. data/spec/fixtures/auths/authorizations.json +0 -16
  69. data/spec/fixtures/events/events.json +0 -29
  70. data/spec/fixtures/issues/issue.json +0 -56
  71. data/spec/fixtures/issues/issues.json +0 -58
  72. data/spec/fixtures/orgs/members.json +0 -9
  73. data/spec/fixtures/orgs/org.json +0 -18
  74. data/spec/fixtures/orgs/orgs.json +0 -8
  75. data/spec/fixtures/orgs/team.json +0 -8
  76. data/spec/fixtures/orgs/team_repos.json +0 -29
  77. data/spec/fixtures/orgs/teams.json +0 -7
  78. data/spec/fixtures/repos/branches.json +0 -9
  79. data/spec/fixtures/repos/collaborators.json +0 -8
  80. data/spec/fixtures/repos/commit.json +0 -53
  81. data/spec/fixtures/repos/commit_comment.json +0 -16
  82. data/spec/fixtures/repos/commit_comments.json +0 -18
  83. data/spec/fixtures/repos/commits.json +0 -27
  84. data/spec/fixtures/repos/contributors.json +0 -8
  85. data/spec/fixtures/repos/download.json +0 -10
  86. data/spec/fixtures/repos/download_s3.json +0 -21
  87. data/spec/fixtures/repos/downloads.json +0 -12
  88. data/spec/fixtures/repos/fork.json +0 -27
  89. data/spec/fixtures/repos/forks.json +0 -29
  90. data/spec/fixtures/repos/hook.json +0 -15
  91. data/spec/fixtures/repos/hooks.json +0 -10
  92. data/spec/fixtures/repos/key.json +0 -6
  93. data/spec/fixtures/repos/keys.json +0 -8
  94. data/spec/fixtures/repos/languages.json +0 -4
  95. data/spec/fixtures/repos/repo.json +0 -90
  96. data/spec/fixtures/repos/repo_comments.json +0 -18
  97. data/spec/fixtures/repos/repos.json +0 -29
  98. data/spec/fixtures/repos/tags.json +0 -11
  99. data/spec/fixtures/repos/teams.json +0 -7
  100. data/spec/fixtures/repos/watched.json +0 -29
  101. data/spec/fixtures/repos/watchers.json +0 -8
  102. data/spec/fixtures/users/user.json +0 -32
  103. data/spec/github/api_spec.rb +0 -25
  104. data/spec/github/authorization_spec.rb +0 -176
  105. data/spec/github/authorizations_spec.rb +0 -242
  106. data/spec/github/client_spec.rb +0 -50
  107. data/spec/github/core_ext/hash_spec.rb +0 -44
  108. data/spec/github/events_spec.rb +0 -491
  109. data/spec/github/gists/comments_spec.rb +0 -5
  110. data/spec/github/gists_spec.rb +0 -5
  111. data/spec/github/git_data/blobs_spec.rb +0 -5
  112. data/spec/github/git_data/commits_spec.rb +0 -5
  113. data/spec/github/git_data/references_spec.rb +0 -5
  114. data/spec/github/git_data/tags_spec.rb +0 -5
  115. data/spec/github/git_data/trees_spec.rb +0 -5
  116. data/spec/github/git_data_spec.rb +0 -5
  117. data/spec/github/issues/comments_spec.rb +0 -5
  118. data/spec/github/issues/events_spec.rb +0 -5
  119. data/spec/github/issues/labels_spec.rb +0 -5
  120. data/spec/github/issues/milestones_spec.rb +0 -5
  121. data/spec/github/issues_spec.rb +0 -287
  122. data/spec/github/mime_type_spec.rb +0 -70
  123. data/spec/github/orgs/members_spec.rb +0 -275
  124. data/spec/github/orgs/teams_spec.rb +0 -563
  125. data/spec/github/orgs_spec.rb +0 -160
  126. data/spec/github/repos/collaborators_spec.rb +0 -169
  127. data/spec/github/repos/commits_spec.rb +0 -424
  128. data/spec/github/repos/downloads_spec.rb +0 -236
  129. data/spec/github/repos/forks_spec.rb +0 -103
  130. data/spec/github/repos/hooks_spec.rb +0 -307
  131. data/spec/github/repos/keys_spec.rb +0 -216
  132. data/spec/github/repos/pub_sub_hubbub_spec.rb +0 -83
  133. data/spec/github/repos/watching_spec.rb +0 -222
  134. data/spec/github/repos_spec.rb +0 -571
  135. data/spec/github/result_spec.rb +0 -43
  136. data/spec/github/users_spec.rb +0 -140
  137. data/spec/github_spec.rb +0 -109
  138. data/spec/spec_helper.rb +0 -86
@@ -1,200 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Github
4
- class Gists < API
5
- extend AutoloadHelper
6
-
7
- autoload_all 'github_api/gists',
8
- :Comments => 'comments'
9
-
10
- include Github::Gists::Comments
11
-
12
- REQUIRED_GIST_INPUTS = %w[ description public files content ]
13
-
14
- # Creates new Gists API
15
- def initialize(options = {})
16
- super(options)
17
- end
18
-
19
- # List a user's gists.
20
- #
21
- # = Examples
22
- # @github = Github.new :user => 'user-name'
23
- # @github.gists.gists
24
- #
25
- # List the authenticated user’s gists or if called anonymously,
26
- # this will returns all public gists
27
- #
28
- # = Examples
29
- # @github = Github.new :oauth_token => '...'
30
- # @github.gists.gists
31
- #
32
- def gists(user_name=nil, params={})
33
- _update_user_repo_params(user_name)
34
- _normalize_params_keys(params)
35
-
36
- response = if user
37
- get("/users/#{user}/gists", params)
38
- elsif oauth_token
39
- get("/gists", params)
40
- else
41
- get("/gists/public", params)
42
- end
43
- return response unless block_given?
44
- response.each { |el| yield el }
45
- end
46
- alias :list_gists :gists
47
-
48
- # List the authenticated user's starred gists
49
- #
50
- # = Examples
51
- # @github = Github.new :oauth_token => '...'
52
- # @github.gists.starred
53
- #
54
- def starred(params={})
55
- _normalize_params_keys(params)
56
- get("/gists/starred", params)
57
- end
58
-
59
- # Get a single gist
60
- #
61
- # = Examples
62
- # @github = Github.new :oauth_token => '...'
63
- # @github.gists.get_gist 'gist-id'
64
- #
65
- def get_gist(gist_id, params={})
66
- _normalize_params_keys(params)
67
- get("/gists/#{gist_id}", params)
68
- end
69
-
70
- # Create a gist
71
- #
72
- # = Inputs
73
- # <tt>:description</tt> - Optional string
74
- # <tt>:public</tt> - Required boolean
75
- # <tt>:files</tt> - Required hash - Files that make up this gist.
76
- # The key of which should be a required string filename and
77
- # the value another required hash with parameters:
78
- # <tt>:content</tt> - Required string - File contents.
79
- #
80
- # = Examples
81
- # @github = Github.new :oauth_token => '...'
82
- # @github.gists.create_gist
83
- # 'description' => 'the description for this gist',
84
- # 'public' => true,
85
- # 'files' => {
86
- # 'file1.txt' => {
87
- # 'content' => 'String file contents'
88
- # }
89
- # }
90
- #
91
- def create_gist(params={})
92
- _normalize_params_keys(params)
93
- _filter_params_keys(REQUIRED_GIST_INPUTS, params)
94
-
95
- post("/gists", params)
96
- end
97
-
98
- # Edit a gist
99
- #
100
- # = Inputs
101
- # <tt>:description</tt> - Optional string
102
- # <tt>:files</tt> - Optional hash - Files that make up this gist.
103
- # The key of which should be a optional string filename and
104
- # the value another optional hash with parameters:
105
- # <tt>:content</tt> - Updated string - Update file contents.
106
- # <tt>:filename</tt> - Optional string - New name for this file.
107
- #
108
- # = Examples
109
- # @github = Github.new :oauth_token => '...'
110
- # @github.gists.edit_gist 'gist-id',
111
- # 'description' => 'the description for this gist',
112
- # 'files' => {
113
- # 'file1.txt' => {
114
- # 'content' => 'Updated file contents'
115
- # },
116
- # 'old_name.txt' => {
117
- # 'filename' => 'new_name.txt',
118
- # 'content' => 'modified contents'
119
- # },
120
- # 'new_file.txt' => {
121
- # 'content' => 'a new file contents'
122
- # },
123
- # 'delete_the_file.txt' => nil
124
- # }
125
- #
126
- def edit_gist(gist_id, params={})
127
- _validate_presence_of(gist_id)
128
- _normalize_params_keys(params)
129
- _filter_params_keys(REQUIRED_GIST_INPUTS, params)
130
-
131
- patch("/gists/#{gist_id}", params)
132
- end
133
-
134
- # Star a gist
135
- #
136
- # = Examples
137
- # @github = Github.new
138
- # @github.gists.star 'gist-id'
139
- #
140
- def star(gist_id, params={})
141
- _validate_presence_of(gist_id)
142
- _normalize_params_keys(params)
143
-
144
- put("/gists/#{gist_id}/star", params)
145
- end
146
-
147
- # Unstar a gist
148
- #
149
- # = Examples
150
- # @github = Github.new
151
- # @github.gists.unstar 'gist-id'
152
- #
153
- def unstar_gist(gist_id, params={})
154
- _validate_presence_of(gist_id)
155
- _normalize_params_keys(params)
156
-
157
- delete("/gists/#{gist_id}/star", params)
158
- end
159
-
160
- # Check if a gist is starred
161
- #
162
- # = Examples
163
- # @github = Github.new
164
- # @github.gists.unstar 'gist-id'
165
- #
166
- def starred?(gist_id, params={})
167
- _validate_presence_of(gist_id)
168
- _normalize_params_keys(params)
169
-
170
- get("/gists/#{gist_id}/star", params)
171
- end
172
-
173
- # Fork a gist
174
- #
175
- # = Examples
176
- # @github = Github.new
177
- # @github.gists.fork 'gist-id'
178
- #
179
- def fork(gist_id, params={})
180
- _validate_presence_of(gist_id)
181
- _normalize_params_keys(params)
182
-
183
- post("/gists/#{gist_id}/fork", params)
184
- end
185
-
186
- # Delete a gist
187
- #
188
- # = Examples
189
- # @github = Github.new
190
- # @github.gists.delete_gist 'gist-id'
191
- #
192
- def delete_gist(gist_id, params={})
193
- _validate_presence_of(gist_id)
194
- _normalize_params_keys(params)
195
-
196
- delete("/gists/#{gist_id}", params)
197
- end
198
-
199
- end # Gists
200
- end # Github
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Github
4
- class Gists
5
- module Comments
6
-
7
- REQUIRED_GIST_COMMENT_INPUTS = %w[
8
- body
9
- mime_type
10
- resource
11
- ].freeze
12
-
13
- # List comments on a gist
14
- #
15
- # = Examples
16
- # @github = Github.new
17
- # @github.gists.gist_comments 'gist-id'
18
- #
19
- def gist_comments(gist_id, params={})
20
- _normalize_params_keys(params)
21
- _merge_mime_type(:gist_comment, params)
22
-
23
- get("/gists/#{gist_id}/comments", params)
24
- end
25
-
26
- # Get a single comment
27
- #
28
- # = Examples
29
- # @github = Github.new
30
- # @github.gists.gist_comment 'comment-id'
31
- #
32
- def gist_comment(comment_id, params={})
33
- _normalize_params_keys(params)
34
- _merge_mime_type(:gist_comment, params)
35
-
36
- get("/gists/comments/#{comment_id}", params)
37
- end
38
-
39
- # Create a comment
40
- #
41
- # = Examples
42
- # @github = Github.new
43
- # @github.gists.create_gist_comment 'gist-id'
44
- #
45
- def create_gist_comment(gist_id, params={})
46
- _normalize_params_keys(params)
47
- _merge_mime_type(:gist_comment, params)
48
- _filter_params_keys(REQUIRED_GIST_COMMENT_INPUTS, params)
49
-
50
- raise ArgumentError, "Required inputs are: :body" unless _validate_inputs(REQUIRED_GIST_COMMENT_INPUTS, params)
51
-
52
- post("/gists/#{gist_id}/comments", params)
53
- end
54
-
55
- # Edit a comment
56
- #
57
- # = Examples
58
- # @github = Github.new
59
- # @github.gists.edit_gist_comment 'comment-id'
60
- #
61
- def edit_gist_comment(comment_id, params={})
62
- _normalize_params_keys(params)
63
- _merge_mime_type(:gist_comment, params)
64
- _filter_params_keys(REQUIRED_GIST_COMMENT_INPUTS, params)
65
-
66
- raise ArgumentError, "Required inputs are: :body" unless _validate_inputs(REQUIRED_GIST_COMMENT_INPUTS, params)
67
-
68
- patch("/gists/comments/#{comment_id}", params)
69
- end
70
-
71
- # Delete a comment
72
- #
73
- # = Examples
74
- # @github = Github.new
75
- # @github.gists.delete_gist_comment 'comment-id'
76
- #
77
- def delete_gist_comment(comment_id, params={})
78
- _normalize_params_keys(params)
79
- _merge_mime_type(:gist_comment, params)
80
-
81
- delete("/gists/comments/#{comment_id}", params)
82
- end
83
-
84
- end # Comments
85
- end # Gists
86
- end # Github
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Github
4
- class GitData < API
5
- extend AutoloadHelper
6
-
7
- autoload_all 'github_api/git_data',
8
- :Blobs => 'blobs',
9
- :Commits => 'commits',
10
- :References => 'references',
11
- :Tags => 'tags',
12
- :Trees => 'trees'
13
-
14
- include Github::GitData::Blobs
15
- include Github::GitData::Commits
16
- include Github::GitData::References
17
- include Github::GitData::Tags
18
- include Github::GitData::Trees
19
-
20
- # Creates new GitData API
21
- def initialize(options = {})
22
- super(options)
23
- end
24
-
25
- end # GitData
26
- end # Github
@@ -1,51 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Github
4
- class GitData
5
- # Since blobs can be any arbitrary binary data, the input and responses for
6
- # the blob api takes an encoding parameter that can be either utf-8 or base64.
7
- # If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it.
8
- module Blobs
9
-
10
- VALID_BLOB_PARAM_NAMES = %w[ content encoding ].freeze
11
-
12
- # Get a blob
13
- #
14
- # = Examples
15
- # @github = Github.new
16
- # @github.git_data.blob 'user-name', 'repo-name', 'sha'
17
- #
18
- def blob(user_name, repo_name, sha, params={})
19
- _update_user_repo_params(user_name, repo_name)
20
- _validate_user_repo_params(user, repo) unless user? && repo?
21
- _validate_presence_of sha
22
- _normalize_params_keys(params)
23
-
24
- get("/repos/#{user}/#{repo}/git/blobs/#{sha}", params)
25
- end
26
-
27
- # Create a blob
28
- #
29
- # = Inputs
30
- # * <tt>:content</tt> - String of content
31
- # * <tt>:encoding</tt> - String containing encoding<tt>utf-8</tt> or <tt>base64</tt>
32
- # = Examples
33
- # @github = Github.new
34
- # @github.git_data.create_blob 'user-name', 'repo-name',
35
- # "content" => "Content of the blob",
36
- # "encoding" => "utf-8"
37
- #
38
- def create_blob(user_name, repo_name=nil, params={})
39
- _update_user_repo_params(user_name, repo_name)
40
- _validate_user_repo_params(user, repo) unless user? && repo?
41
- _normalize_params_keys(params)
42
- _filter_params_keys(VALID_BLOB_PARAM_NAMES, params)
43
-
44
- raise ArgumentError, "Required params are: #{VALID_BLOB_PARAM_NAMES.join(', ')}" unless _validate_inputs(VALID_BLOB_PARAM_NAMES, params)
45
-
46
- post("/repos/#{user}/#{repo}/git/blobs", params)
47
- end
48
-
49
- end # Blobs
50
- end # GitData
51
- end # Github
@@ -1,78 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Github
4
- class GitData
5
- module Commits
6
-
7
- VALID_COMMIT_PARAM_NAMES = %w[
8
- message
9
- tree
10
- parents
11
- author
12
- committer
13
- name
14
- email
15
- date
16
- ].freeze
17
-
18
- # Get a commit
19
- #
20
- # = Examples
21
- # @github = Github.new
22
- # @github.git_data.commit 'user-name', 'repo-name', 'sha'
23
- #
24
- def commit(user_name, repo_name, sha, params={})
25
- _update_user_repo_params(user_name, repo_name)
26
- _validate_user_repo_params(user, repo) unless user? && repo?
27
- _validate_presence_of sha
28
- _normalize_params_keys(params)
29
-
30
- get("/repos/#{user}/#{repo}/git/commits/#{sha}", params)
31
- end
32
-
33
- # Create a commit
34
- #
35
- # = Parameters
36
- # * <tt>message</tt> - String of the commit message
37
- # * <tt>tree</tt> - String of the SHA of the tree object this commit points to
38
- # * <tt>parents</tt> - Array of the SHAs of the commits that were the parents of this commit. If omitted or empty, the commit will be written as a root commit. For a single parent, an array of one SHA should be provided, for a merge commit, an array of more than one should be provided.
39
- #
40
- # = Optional Parameters
41
- #
42
- # The committer section is optional and will be filled with the author data if omitted. If the author section is omitted, it will be filled in with the authenticated users information and the current date.
43
- #
44
- # * author.name:: String of the name of the author of the commit
45
- # * author.email:: String of the email of the author of the commit
46
- # * author.date:: Timestamp of when this commit was authored
47
- # * committer.name:: String of the name of the committer of the commit
48
- # * committer.email:: String of the email of the committer of the commit
49
- # * committer.date:: Timestamp of when this commit was committed
50
- #
51
- # = Examples
52
- # @github = Github.new
53
- # @github.git_data.create_commit 'user-name', 'repo-name',
54
- # "message": "my commit message",
55
- # "author": {
56
- # "name": "Scott Chacon",
57
- # "email": "schacon@gmail.com",
58
- # "date": "2008-07-09T16:13:30+12:00"
59
- # },
60
- # "parents": [
61
- # "7d1b31e74ee336d15cbd21741bc88a537ed063a0"
62
- # ],
63
- # "tree": "827efc6d56897b048c772eb4087f854f46256132"]
64
- #
65
- def create_commit(user_name=nil, repo_name=nil, params={})
66
- _update_user_repo_params(user_name, repo_name)
67
- _validate_user_repo_params(user, repo) unless user? && repo?
68
- _normalize_params_keys(params)
69
- _filter_params_keys(VALID_COMMIT_PARAM_NAMES, params)
70
-
71
- raise ArgumentError, "Required params are: message, tree, parents" unless _validate_inputs(%w[ message tree parents ], params)
72
-
73
- post("/repos/#{user}/#{repo}/git/commits", params)
74
- end
75
-
76
- end # Commits
77
- end # GitData
78
- end # Github
@@ -1,113 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Github
4
- class GitData
5
- module References
6
-
7
- VALID_REF_PARAM_NAMES = %w[ ref sha force ].freeze
8
-
9
- VALID_REF_PARAM_VALUES = {
10
- 'ref' => %r{^refs\/\w+\/\w+(\/\w+)*} # test fully qualified reference
11
- }
12
-
13
- # Get a reference
14
- #
15
- # The ref in the URL must be formatted as <tt>heads/branch</tt>,
16
- # not just branch. For example, the call to get the data for a
17
- # branch named <tt>sc/featureA</tt> would be formatted as
18
- # <tt>heads/sc/featureA</tt>
19
- #
20
- # = Examples
21
- # @github = Github.new
22
- # @github.git_data.reference 'user-name', 'repo-name', 'reference'
23
- #
24
- def reference(user_name, repo_name, ref, params={})
25
- _update_user_repo_params(user_name, repo_name)
26
- _validate_user_repo_params(user, repo) unless user? && repo?
27
- _validate_presence_of ref
28
- _normalize_params_keys(params)
29
-
30
- get("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
31
- end
32
-
33
- # Get all references
34
- #
35
- # This will return an array of all the references on the system,
36
- # including things like notes and stashes if they exist on the server.
37
- # Anything in the namespace, not just <tt>heads</tt> and <tt>tags</tt>,
38
- # though that would be the most common.
39
- #
40
- # = Examples
41
- # @github = Github.new
42
- # @github.git_data.references 'user-name', 'repo-name'
43
- #
44
- # @github.git_data.references 'user-name', 'repo-name', 'tags'
45
- #
46
- def references(user_name, repo_name, ref=nil, params={})
47
- _update_user_repo_params(user_name, repo_name)
48
- _validate_user_repo_params(user, repo) unless user? && repo?
49
- _normalize_params_keys(params)
50
-
51
- response = if ref
52
- get("/repos/#{user}/#{repo}/git/refs/#{ref}")
53
- else
54
- get("/repos/#{user}/#{repo}/git/refs")
55
- end
56
- return response unless block_given?
57
- response.each { |el| yield el }
58
- end
59
-
60
- # Create a reference
61
- #
62
- # = Inputs
63
- # * <tt>:ref</tt> - String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.
64
- # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
65
- #
66
- # = Examples
67
- # @github = Github.new
68
- # @github.git_data.create_reference 'user-name', 'repo-name',
69
- # "ref" => "refs/heads/master",
70
- # "sha" => "827efc6d56897b048c772eb4087f854f46256132"
71
- #
72
- def create_reference(user_name, repo_name, params={})
73
- _update_user_repo_params(user_name, repo_name)
74
- _validate_user_repo_params(user, repo) unless user? && repo?
75
- _normalize_params_keys(params)
76
-
77
- raise ArgumentError, "Required params are: ref, sha" unless _validate_inputs(%w[ ref sha ], params)
78
-
79
- _filter_params_keys(VALID_REF_PARAM_NAMES, params)
80
- _validate_params_values(VALID_REF_PARAM_VALUES, params)
81
-
82
- post("/repos/#{user}/#{repo}/git/refs", params)
83
- end
84
-
85
- # Update a reference
86
- #
87
- # = Inputs
88
- # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
89
- # * <tt>:force</tt> - Boolean indicating whether to force the update or to make sure the update is a fast-forward update. The default is <tt>false</tt>, so leaving this out or setting it to false will make sure you’re not overwriting work.
90
- #
91
- # = Examples
92
- # @github = Github.new
93
- # @github.git_data.create_reference 'user-name', 'repo-name',
94
- # "sha" => "827efc6d56897b048c772eb4087f854f46256132",
95
- # "force" => true
96
- #
97
- def update_reference(user_name, repo_name, ref, params={})
98
- _update_user_repo_params(user_name, repo_name)
99
- _validate_user_repo_params(user, repo) unless user? && repo?
100
- _validate_presence_of ref
101
- _normalize_params_keys(params)
102
-
103
- raise ArgumentError, "Required params are: sha" unless _validate_inputs(%w[ sha ], params)
104
-
105
- _filter_params_keys(VALID_REF_PARAM_NAMES, params)
106
- _validate_params_values(VALID_REF_PARAM_VALUES, params)
107
-
108
- patch("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
109
- end
110
-
111
- end # References
112
- end # GitData
113
- end # Github