github_api 0.3.5 → 0.3.6

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 (147) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.rdoc +228 -0
  3. data/Rakefile +52 -0
  4. data/features/github_api.feature +50 -0
  5. data/features/options.feature +4 -0
  6. data/features/pagination.feature +4 -0
  7. data/features/step_definitions/github_api_steps.rb +11 -0
  8. data/features/support/env.rb +13 -0
  9. data/lib/github_api.rb +73 -0
  10. data/lib/github_api/api.rb +175 -0
  11. data/lib/github_api/api/utils.rb +9 -0
  12. data/lib/github_api/authorization.rb +73 -0
  13. data/lib/github_api/authorizations.rb +119 -0
  14. data/lib/github_api/cache_control.rb +19 -0
  15. data/lib/github_api/client.rb +55 -0
  16. data/lib/github_api/compatibility.rb +23 -0
  17. data/lib/github_api/configuration.rb +96 -0
  18. data/lib/github_api/connection.rb +75 -0
  19. data/lib/github_api/core_ext/array.rb +14 -0
  20. data/lib/github_api/core_ext/hash.rb +42 -0
  21. data/lib/github_api/error.rb +35 -0
  22. data/lib/github_api/events.rb +202 -0
  23. data/lib/github_api/gists.rb +200 -0
  24. data/lib/github_api/gists/comments.rb +86 -0
  25. data/lib/github_api/git_data.rb +26 -0
  26. data/lib/github_api/git_data/blobs.rb +51 -0
  27. data/lib/github_api/git_data/commits.rb +78 -0
  28. data/lib/github_api/git_data/references.rb +113 -0
  29. data/lib/github_api/git_data/tags.rb +78 -0
  30. data/lib/github_api/git_data/trees.rb +89 -0
  31. data/lib/github_api/issues.rb +215 -0
  32. data/lib/github_api/issues/comments.rb +123 -0
  33. data/lib/github_api/issues/events.rb +54 -0
  34. data/lib/github_api/issues/labels.rb +191 -0
  35. data/lib/github_api/issues/milestones.rb +140 -0
  36. data/lib/github_api/mime_type.rb +55 -0
  37. data/lib/github_api/orgs.rb +95 -0
  38. data/lib/github_api/orgs/members.rb +120 -0
  39. data/lib/github_api/orgs/teams.rb +245 -0
  40. data/lib/github_api/pull_requests.rb +224 -0
  41. data/lib/github_api/pull_requests/comments.rb +144 -0
  42. data/lib/github_api/repos.rb +286 -0
  43. data/lib/github_api/repos/collaborators.rb +81 -0
  44. data/lib/github_api/repos/commits.rb +180 -0
  45. data/lib/github_api/repos/downloads.rb +155 -0
  46. data/lib/github_api/repos/forks.rb +48 -0
  47. data/lib/github_api/repos/hooks.rb +174 -0
  48. data/lib/github_api/repos/keys.rb +104 -0
  49. data/lib/github_api/repos/pub_sub_hubbub.rb +102 -0
  50. data/lib/github_api/repos/watching.rb +94 -0
  51. data/lib/github_api/request.rb +84 -0
  52. data/lib/github_api/request/basic_auth.rb +31 -0
  53. data/lib/github_api/request/caching.rb +33 -0
  54. data/lib/github_api/request/oauth2.rb +33 -0
  55. data/lib/github_api/response.rb +28 -0
  56. data/lib/github_api/response/helpers.rb +14 -0
  57. data/lib/github_api/response/jsonize.rb +26 -0
  58. data/lib/github_api/response/mashify.rb +24 -0
  59. data/lib/github_api/response/raise_error.rb +33 -0
  60. data/lib/github_api/result.rb +42 -0
  61. data/lib/github_api/users.rb +84 -0
  62. data/lib/github_api/users/emails.rb +49 -0
  63. data/lib/github_api/users/followers.rb +98 -0
  64. data/lib/github_api/users/keys.rb +84 -0
  65. data/lib/github_api/version.rb +12 -0
  66. data/spec/README.rdoc +22 -0
  67. data/spec/coverage_adapter.rb +15 -0
  68. data/spec/fixtures/auths/authorization.json +14 -0
  69. data/spec/fixtures/auths/authorizations.json +16 -0
  70. data/spec/fixtures/events/events.json +29 -0
  71. data/spec/fixtures/issues/comment.json +13 -0
  72. data/spec/fixtures/issues/comments.json +15 -0
  73. data/spec/fixtures/issues/event.json +13 -0
  74. data/spec/fixtures/issues/events.json +15 -0
  75. data/spec/fixtures/issues/issue.json +56 -0
  76. data/spec/fixtures/issues/issues.json +58 -0
  77. data/spec/fixtures/issues/milestone.json +18 -0
  78. data/spec/fixtures/issues/milestones.json +20 -0
  79. data/spec/fixtures/orgs/members.json +9 -0
  80. data/spec/fixtures/orgs/org.json +18 -0
  81. data/spec/fixtures/orgs/orgs.json +8 -0
  82. data/spec/fixtures/orgs/team.json +8 -0
  83. data/spec/fixtures/orgs/team_repos.json +29 -0
  84. data/spec/fixtures/orgs/teams.json +7 -0
  85. data/spec/fixtures/repos/branches.json +9 -0
  86. data/spec/fixtures/repos/collaborators.json +8 -0
  87. data/spec/fixtures/repos/commit.json +53 -0
  88. data/spec/fixtures/repos/commit_comment.json +16 -0
  89. data/spec/fixtures/repos/commit_comments.json +18 -0
  90. data/spec/fixtures/repos/commits.json +27 -0
  91. data/spec/fixtures/repos/contributors.json +8 -0
  92. data/spec/fixtures/repos/download.json +10 -0
  93. data/spec/fixtures/repos/download_s3.json +21 -0
  94. data/spec/fixtures/repos/downloads.json +12 -0
  95. data/spec/fixtures/repos/fork.json +27 -0
  96. data/spec/fixtures/repos/forks.json +29 -0
  97. data/spec/fixtures/repos/hook.json +15 -0
  98. data/spec/fixtures/repos/hooks.json +10 -0
  99. data/spec/fixtures/repos/key.json +6 -0
  100. data/spec/fixtures/repos/keys.json +8 -0
  101. data/spec/fixtures/repos/languages.json +4 -0
  102. data/spec/fixtures/repos/repo.json +90 -0
  103. data/spec/fixtures/repos/repo_comments.json +18 -0
  104. data/spec/fixtures/repos/repos.json +29 -0
  105. data/spec/fixtures/repos/tags.json +11 -0
  106. data/spec/fixtures/repos/teams.json +7 -0
  107. data/spec/fixtures/repos/watched.json +29 -0
  108. data/spec/fixtures/repos/watchers.json +8 -0
  109. data/spec/fixtures/users/user.json +32 -0
  110. data/spec/github/api_spec.rb +25 -0
  111. data/spec/github/authorization_spec.rb +176 -0
  112. data/spec/github/authorizations_spec.rb +242 -0
  113. data/spec/github/client_spec.rb +50 -0
  114. data/spec/github/core_ext/hash_spec.rb +44 -0
  115. data/spec/github/events_spec.rb +491 -0
  116. data/spec/github/gists/comments_spec.rb +5 -0
  117. data/spec/github/gists_spec.rb +5 -0
  118. data/spec/github/git_data/blobs_spec.rb +5 -0
  119. data/spec/github/git_data/commits_spec.rb +5 -0
  120. data/spec/github/git_data/references_spec.rb +5 -0
  121. data/spec/github/git_data/tags_spec.rb +5 -0
  122. data/spec/github/git_data/trees_spec.rb +5 -0
  123. data/spec/github/git_data_spec.rb +5 -0
  124. data/spec/github/issues/comments_spec.rb +254 -0
  125. data/spec/github/issues/events_spec.rb +153 -0
  126. data/spec/github/issues/labels_spec.rb +5 -0
  127. data/spec/github/issues/milestones_spec.rb +260 -0
  128. data/spec/github/issues_spec.rb +287 -0
  129. data/spec/github/mime_type_spec.rb +70 -0
  130. data/spec/github/orgs/members_spec.rb +275 -0
  131. data/spec/github/orgs/teams_spec.rb +563 -0
  132. data/spec/github/orgs_spec.rb +160 -0
  133. data/spec/github/repos/collaborators_spec.rb +169 -0
  134. data/spec/github/repos/commits_spec.rb +424 -0
  135. data/spec/github/repos/downloads_spec.rb +247 -0
  136. data/spec/github/repos/forks_spec.rb +108 -0
  137. data/spec/github/repos/hooks_spec.rb +333 -0
  138. data/spec/github/repos/keys_spec.rb +217 -0
  139. data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
  140. data/spec/github/repos/watching_spec.rb +222 -0
  141. data/spec/github/repos_spec.rb +571 -0
  142. data/spec/github/result_spec.rb +43 -0
  143. data/spec/github/users_spec.rb +140 -0
  144. data/spec/github_spec.rb +109 -0
  145. data/spec/spec_helper.rb +86 -0
  146. data/spec/support/base.rb +13 -0
  147. metadata +149 -4
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData
5
+ # This tags api only deals with tag objects - so only annotated tags, not lightweight tags.
6
+ module Tags
7
+
8
+ VALID_TAG_PARAM_NAMES = %w[
9
+ tag
10
+ message
11
+ object
12
+ type
13
+ name
14
+ email
15
+ date
16
+ ]
17
+
18
+ VALID_TAG_PARAM_VALUES = {
19
+ 'type' => %w[ blob tree commit ]
20
+ }
21
+
22
+ # Get a tag
23
+ #
24
+ # = Examples
25
+ # @github = Github.new
26
+ # @github.git_data.tag 'user-name', 'repo-name', 'sha'
27
+ #
28
+ def tag(user_name, repo_name, sha, params={})
29
+ _update_user_repo_params(user_name, repo_name)
30
+ _validate_user_repo_params(user, repo) unless user? && repo?
31
+ _validate_presence_of sha
32
+ _normalize_params_keys(params)
33
+
34
+ get("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
35
+ end
36
+
37
+ # Create a tag object
38
+ # Note that creating a tag object does not create the reference that
39
+ # makes a tag in Git. If you want to create an annotated tag in Git,
40
+ # you have to do this call to create the tag object, and then create
41
+ # the <tt>refs/tags/[tag]</tt> reference. If you want to create a lightweight tag, you simply have to create the reference - this call would be unnecessary.
42
+ #
43
+ # = Parameters
44
+ # * <tt>:tag</tt> - String of the tag
45
+ # * <tt>:message</tt> - String of the tag message
46
+ # * <tt>:object</tt> - String of the SHA of the git object this is tagging
47
+ # * <tt>:type</tt> - String of the type of the object we're tagging. Normally this is a <tt>commit</tt> but it can also be a <tt>tree</tt> or a <tt>blob</tt>
48
+ # * tagger.name:: String of the name of the author of the tag
49
+ # * tagger.email:: String of the email of the author of the tag
50
+ # * tagger.date:: Timestamp of when this object was tagged
51
+ #
52
+ # = Examples
53
+ # @github = Github.new
54
+ # @github.git_data.create_tag 'user-name', 'repo-name',
55
+ # "tag" => "v0.0.1",
56
+ # "message" => "initial version\n",
57
+ # "type": "commit",
58
+ # "object": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
59
+ # "tagger" => {
60
+ # "name" => "Scott Chacon",
61
+ # "email" => "schacon@gmail.com",
62
+ # "date" => "2011-06-17T14:53:3"
63
+ # }
64
+ #
65
+ def create_tag(user_name, repo_name, 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
+
70
+ _filter_params_keys(VALID_TAG_PARAM_NAMES, params)
71
+ _validate_params_values(VALID_TAG_PARAM_VALUES, params)
72
+
73
+ post("/repos/#{user}/#{repo}/git/tags", params)
74
+ end
75
+
76
+ end # Tags
77
+ end # GitData
78
+ end # Github
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class GitData
5
+ module Trees
6
+
7
+ VALID_TREE_PARAM_NAMES = %w[
8
+ base_tree
9
+ tree
10
+ path
11
+ mode
12
+ type
13
+ sha
14
+ content
15
+ ].freeze
16
+
17
+ VALID_TREE_PARAM_VALUES = {
18
+ 'mode' => %w[ 100644 100755 040000 160000 120000 ],
19
+ 'type' => %w[ blob tree commit ]
20
+ }
21
+
22
+ # Get a tree
23
+ #
24
+ # = Examples
25
+ # @github = Github.new
26
+ # @github.git_data.tree 'user-name', 'repo-name', 'sha'
27
+ # @github.git_data.tree 'user-name', 'repo-name', 'sha' do |file|
28
+ # file.path
29
+ # end
30
+ #
31
+ def tree(user_name, repo_name, sha, params={})
32
+ _update_user_repo_params(user_name, repo_name)
33
+ _validate_user_repo_params(user, repo) unless user? && repo?
34
+ _validate_presence_of sha
35
+ _normalize_params_keys(params)
36
+
37
+ response = if params['recursive']
38
+ params['recursive'] = 1
39
+ get("/repos/#{user}/#{repo}/git/trees/#{sha}", params)
40
+ else
41
+ get("/repos/#{user}/#{repo}/git/trees/#{sha.to_s}", params)
42
+ end
43
+ return response unless block_given?
44
+ response.tree.each { |el| yield el }
45
+ end
46
+
47
+ # Create a tree
48
+ #
49
+ # The tree creation API will take nested entries as well.
50
+ # If both a tree and a nested path modifying that tree are specified,
51
+ # it will overwrite the contents of that tree with the new path contents
52
+ # and write a new tree out.
53
+ #
54
+ # = Parameters
55
+ # * <tt>:base_tree</tt> - optional string of the SHA1 of the tree you want to update with new data
56
+ # * <tt>:tree</tt> - array of hash objects(of <tt>:path</tt>, <tt>:mode</tt>, <tt>:type</tt> and <tt>sha</tt>)
57
+ # * tree.path:: String of the file referenced in the tree
58
+ # * tree.mode:: String of the file mode - one of <tt>100644</tt> for file(blob), <tt>100755</tt> for executable (blob), <tt>040000</tt> for subdirectory (tree), <tt>160000</tt> for submodule (commit) or <tt>120000</tt> for a blob that specifies the path of a symlink
59
+ # * tree.type:: String of <tt>blob</tt>, <tt>tree</tt>, <tt>commit</tt>
60
+ # * tree.sha:: String of SHA1 checksum ID of the object in the tree
61
+ # * tree.content:: String of content you want this file to have - GitHub will write this blob out and use the SHA for this entry. Use either this or <tt>tree.sha</tt>
62
+ #
63
+ # = Examples
64
+ # @github = Github.new
65
+ # @github.git_data.create_tree 'user-name', 'repo-name',
66
+ # "tree" => [
67
+ # {
68
+ # "path" => "file.rb",
69
+ # "mode" => "100644",
70
+ # "type" => "blob",
71
+ # "sha" => "44b4fc6d56897b048c772eb4087f854f46256132"
72
+ # },
73
+ # ...
74
+ # ]
75
+ #
76
+ def create_tree(user_name=nil, repo_name=nil, params={})
77
+ _update_user_repo_params(user_name, repo_name)
78
+ _validate_user_repo_params(user, repo) unless user? && repo?
79
+ _normalize_params_keys(params)
80
+
81
+ _filter_params_keys(VALID_TREE_PARAM_NAMES, params['tree'])
82
+ _validate_params_values(VALID_TREE_PARAM_VALUES, params['tree'])
83
+
84
+ post("/repos/#{user}/#{repo}/git/trees", params)
85
+ end
86
+
87
+ end # Trees
88
+ end # GitData
89
+ end # Github
@@ -0,0 +1,215 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Issues < API
5
+ extend AutoloadHelper
6
+
7
+ autoload_all 'github_api/issues',
8
+ :Comments => 'comments',
9
+ :Events => 'events',
10
+ :Labels => 'labels',
11
+ :Milestones => 'milestones'
12
+
13
+ include Github::Issues::Comments
14
+ include Github::Issues::Events
15
+ include Github::Issues::Labels
16
+ include Github::Issues::Milestones
17
+
18
+ VALID_ISSUE_PARAM_NAMES = %w[
19
+ filter
20
+ state
21
+ labels
22
+ sort
23
+ direction
24
+ since
25
+ milestone
26
+ assignee
27
+ mentioned
28
+ title
29
+ body
30
+ resource
31
+ mime_type
32
+ ].freeze
33
+
34
+ VALID_ISSUE_PARAM_VALUES = {
35
+ 'filter' => %w[ assigned created mentioned subscribed ],
36
+ 'state' => %w[ open closed ],
37
+ 'sort' => %w[ created updated comments ],
38
+ 'direction' => %w[ desc asc ],
39
+ 'since' => %r{\d{4}-\d{2}-\d{5}:\d{2}:\d{3}}
40
+ }
41
+
42
+ # Creates new Issues API
43
+ def initialize(options = {})
44
+ super(options)
45
+ end
46
+
47
+ # List your issues
48
+ #
49
+ # = Parameters
50
+ # <tt>:filter</tt>
51
+ # * <tt>assigned</tt>: Issues assigned to you (default)
52
+ # * <tt>created</tt>: Issues assigned to you (default)
53
+ # * <tt>mentioned</tt>: Issues assigned to you (default)
54
+ # * <tt>subscribed</tt>: Issues assigned to you (default)
55
+ # <tt>:state</tt> - <tt>open</tt>, <tt>closed</tt>, default: <tt>open</tt>
56
+ # <tt>:labels</tt> - String list of comma separated Label names. Example: bug,ui,@high
57
+ # <tt>:sort</tt> - <tt>created</tt>, <tt>updated</tt>, <tt>comments</tt>, default: <tt>created</tt>
58
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
59
+ # <tt>:since</tt> - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
60
+ #
61
+ # = Examples
62
+ # @github = Github.new :oauth_token => '...'
63
+ # @github.issues.issues :since => '2011-04-12312:12:121',
64
+ # :filter => 'created',
65
+ # :state => 'open',
66
+ # :labels => "bug,ui,bla",
67
+ # :sort => 'comments',
68
+ # :direction => 'asc'
69
+ #
70
+ def issues(params={})
71
+ _normalize_params_keys(params)
72
+ _filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
73
+ _merge_mime_type(:issue, params)
74
+ _validate_params_values(VALID_ISSUE_PARAM_VALUES, params)
75
+
76
+ response = get("/issues", params)
77
+ return response unless block_given?
78
+ response.each { |el| yield el }
79
+ end
80
+ alias :list_issues :issues
81
+
82
+ # List issues for a repository
83
+ #
84
+ # = Parameters
85
+ # <tt>:milestone</tt>
86
+ # * Integer Milestone number
87
+ # * <tt>none</tt> for Issues with no Milestone.
88
+ # * <tt>*</tt> for Issues with any Milestone
89
+ # <tt>:state</tt> - <tt>open</tt>, <tt>closed</tt>, default: <tt>open</tt>
90
+ # <tt>:assignee</tt>
91
+ # * String User login
92
+ # * <tt>none</tt> for Issues with no assigned User.
93
+ # * <tt>*</tt> for Issues with any assigned User.
94
+ # <tt>:mentioned</tt> String User login
95
+ # <tt>:labels</tt> - String list of comma separated Label names. Example: bug,ui,@high
96
+ # <tt>:sort</tt> - <tt>created</tt>, <tt>updated</tt>, <tt>comments</tt>, default: <tt>created</tt>
97
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
98
+ # <tt>:since</tt> - Optional string of a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
99
+ # <tt></tt>, default: <tt>due_date</tt>
100
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
101
+ #
102
+ # = Examples
103
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
104
+ # @github.issues.repo_issues :milestone => 1,
105
+ # :state => 'open',
106
+ # :assignee => '*',
107
+ # :mentioned => 'octocat',
108
+ # :labels => "bug,ui,bla",
109
+ # :sort => 'comments',
110
+ # :direction => 'asc'
111
+ #
112
+ def repo_issues(user_name=nil, repo_name=nil, params={})
113
+ _update_user_repo_params(user_name, repo_name)
114
+ _validate_user_repo_params(user, repo) unless user? && repo?
115
+
116
+ _normalize_params_keys(params)
117
+ _filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
118
+ _merge_mime_type(:issue, params)
119
+ _validate_params_values(VALID_ISSUE_PARAM_VALUES, params)
120
+
121
+ response = get("/repos/#{user}/#{repo}/issues", params)
122
+ return response unless block_given?
123
+ response.each { |el| yield el }
124
+ end
125
+ alias :repository_issues :repo_issues
126
+ alias :list_repo_issues :repo_issues
127
+ alias :list_repository_issues :repo_issues
128
+
129
+ # Get a single issue
130
+ #
131
+ # = Examples
132
+ # @github = Github.new
133
+ # @github.issues.get_issue 'user-name', 'repo-name', 'issue-id'
134
+ #
135
+ def issue(user_name, repo_name, issue_id, params={})
136
+ _update_user_repo_params(user_name, repo_name)
137
+ _validate_user_repo_params(user, repo) unless user? && repo?
138
+ _validate_presence_of issue_id
139
+
140
+ _normalize_params_keys(params)
141
+ _merge_mime_type(:issue, params)
142
+
143
+ get("/repos/#{user}/#{repo}/issues/#{issue_id}", params)
144
+ end
145
+ alias :get_issue :issue
146
+
147
+ # Create an issue
148
+ #
149
+ # = Inputs
150
+ # <tt>:title</tt> - Required string
151
+ # <tt>:body</tt> - Optional string
152
+ # <tt>:assignee</tt> - Optional string - Login for the user that this issue should be assigned to.
153
+ # <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
154
+ # <tt>:labels</tt> - Optional array of strings - Labels to associate with this issue
155
+ # = Examples
156
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
157
+ # @github.issues.create_issue
158
+ # "title" => "Found a bug",
159
+ # "body" => "I'm having a problem with this.",
160
+ # "assignee" => "octocat",
161
+ # "milestone" => 1,
162
+ # "labels" => [
163
+ # "Label1",
164
+ # "Label2"
165
+ # ]
166
+ #
167
+ def create_issue(user_name=nil, repo_name=nil, params={})
168
+ _update_user_repo_params(user_name, repo_name)
169
+ _validate_user_repo_params(user, repo) unless user? && repo?
170
+
171
+ _normalize_params_keys(params)
172
+ _merge_mime_type(:issue, params)
173
+ _filter_params_keys(VALID_ISSUE_PARAM_NAMES, params)
174
+
175
+ raise ArgumentError, "Required params are: :title" unless _validate_inputs(%w[ title ], params)
176
+
177
+ post("/repos/#{user}/#{repo}/issues", params)
178
+ end
179
+
180
+ # Edit an issue
181
+ #
182
+ # = Inputs
183
+ # <tt>:title</tt> - Optional string
184
+ # <tt>:body</tt> - Optional string
185
+ # <tt>:assignee</tt> - Optional string - Login for the user that this issue should be assigned to.
186
+ # <tt>:state</tt> - Optional string - State of the issue:<tt>open</tt> or <tt>closed</tt>
187
+ # <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
188
+ # <tt>:labels</tt> - Optional array of strings - Labels to associate with this issue. Pass one or more Labels to replace the set of Labels on this Issue. Send an empty array ([]) to clear all Labels from the Issue.
189
+ #
190
+ # = Examples
191
+ # @github = Github.new
192
+ # @github.issues.create_issue 'user-name', 'repo-name', 'issue-id'
193
+ # "title" => "Found a bug",
194
+ # "body" => "I'm having a problem with this.",
195
+ # "assignee" => "octocat",
196
+ # "milestone" => 1,
197
+ # "labels" => [
198
+ # "Label1",
199
+ # "Label2"
200
+ # ]
201
+ #
202
+ def edit_issue(user_name, repo_name, issue_id, params={})
203
+ _update_user_repo_params(user_name, repo_name)
204
+ _validate_user_repo_params(user, repo) unless user? && repo?
205
+ _validate_presence_of issue_id
206
+
207
+ _normalize_params_keys(params)
208
+ _merge_mime_type(:issue, params)
209
+ _filter_params_keys(VALID_MILESTONE_INPUTS, params)
210
+
211
+ patch("/repos/#{user}/#{repo}/issues/#{issue_id}", params)
212
+ end
213
+
214
+ end # Issues
215
+ end # Github
@@ -0,0 +1,123 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Issues
5
+ module Comments
6
+
7
+ VALID_ISSUE_COMMENT_PARAM_NAME = %w[
8
+ body
9
+ resource
10
+ mime_type
11
+ ].freeze
12
+
13
+ # List comments on an issue
14
+ #
15
+ # = Examples
16
+ # @github = Github.new
17
+ # @github.issues.comments 'user-name', 'repo-name', 'issue-id'
18
+ # @github.issues.comments 'user-name', 'repo-name', 'issue-id' { |com| ... }
19
+ #
20
+ def comments(user_name, repo_name, issue_id, params={})
21
+ _update_user_repo_params(user_name, repo_name)
22
+ _validate_user_repo_params(user, repo) unless user? && repo?
23
+ _validate_presence_of issue_id
24
+
25
+ _normalize_params_keys(params)
26
+ _merge_mime_type(:issue_comment, params)
27
+
28
+ response = get("/repos/#{user}/#{repo}/issues/#{issue_id}/comments", params)
29
+ return response unless block_given?
30
+ response.each { |el| yield el }
31
+ end
32
+ alias :issue_comments :comments
33
+ alias :list_comments :comments
34
+ alias :list_issue_comments :comments
35
+
36
+ # Get a single comment
37
+ #
38
+ # = Examples
39
+ # @github = Github.new
40
+ # @github.issues.comment 'user-name', 'repo-name', 'comment-id'
41
+ #
42
+ def comment(user_name, repo_name, comment_id, params={})
43
+ _update_user_repo_params(user_name, repo_name)
44
+ _validate_user_repo_params(user, repo) unless user? && repo?
45
+ _validate_presence_of comment_id
46
+
47
+ _normalize_params_keys(params)
48
+ _merge_mime_type(:issue_comment, params)
49
+
50
+ get("/repos/#{user}/#{repo}/issues/comments/#{comment_id}", params)
51
+ end
52
+ alias :issue_comment :comment
53
+ alias :get_comment :comment
54
+
55
+ # Create a comment
56
+ #
57
+ # = Inputs
58
+ # <tt>:body</tt> Required string
59
+ #
60
+ # = Examples
61
+ # @github = Github.new
62
+ # @github.issues.create_comment 'user-name', 'repo-name', 'issue-id',
63
+ # "body" => 'a new comment'
64
+ #
65
+ def create_comment(user_name, repo_name, issue_id, params={})
66
+ _update_user_repo_params(user_name, repo_name)
67
+ _validate_user_repo_params(user, repo) unless user? && repo?
68
+ _validate_presence_of issue_id
69
+
70
+ _normalize_params_keys(params)
71
+ _merge_mime_type(:issue_comment, params)
72
+ _filter_params_keys(VALID_ISSUE_COMMENT_PARAM_NAME, params)
73
+ raise ArgumentError, "Required params are: :body" unless _validate_inputs(%w[ body ], params)
74
+
75
+ post("/repos/#{user}/#{repo}/issues/#{issue_id}/comments", params)
76
+ end
77
+ alias :create_issue_comment :create_comment
78
+
79
+ # Edit a comment
80
+ #
81
+ # = Inputs
82
+ # <tt>:body</tt> Required string
83
+ #
84
+ # = Examples
85
+ # @github = Github.new
86
+ # @github.issues.edit_comment 'user-name', 'repo-name', 'comment-id',
87
+ # "body" => 'a new comment'
88
+ #
89
+ def edit_comment(user_name, repo_name, comment_id, params={})
90
+ _update_user_repo_params(user_name, repo_name)
91
+ _validate_user_repo_params(user, repo) unless user? && repo?
92
+ _validate_presence_of comment_id
93
+
94
+ _normalize_params_keys(params)
95
+ _merge_mime_type(:issue_comment, params)
96
+ _filter_params_keys(VALID_ISSUE_COMMENT_PARAM_NAME, params)
97
+ raise ArgumentError, "Required params are: :body" unless _validate_inputs(%w[ body ], params)
98
+
99
+ patch("/repos/#{user}/#{repo}/issues/comments/#{comment_id}")
100
+ end
101
+ alias :edit_issue_comment :edit_comment
102
+
103
+ # Delete a comment
104
+ #
105
+ # = Examples
106
+ # @github = Github.new
107
+ # @github.issues.delete_comment 'user-name', 'repo-name', 'comment-id'
108
+ #
109
+ def delete_comment(user_name, repo_name, comment_id, params={})
110
+ _update_user_repo_params(user_name, repo_name)
111
+ _validate_user_repo_params(user, repo) unless user? && repo?
112
+ _validate_presence_of comment_id
113
+
114
+ _normalize_params_keys(params)
115
+ _merge_mime_type(:issue_comment, params)
116
+
117
+ delete("/repos/#{user}/#{repo}/issues/comments/#{comment_id}", params)
118
+ end
119
+ alias :delete_issue_comment :delete_comment
120
+
121
+ end # Comments
122
+ end # Issues
123
+ end # Github