github_api 0.4.11 → 0.5.0.rc1

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 (109) hide show
  1. data/README.md +76 -72
  2. data/features/cassettes/gists/starred.yml +48 -0
  3. data/features/cassettes/pagination/repos/commits/list.yml +193 -0
  4. data/features/cassettes/pagination/repos/commits/next.yml +183 -0
  5. data/features/cassettes/pagination/repos/diff/next.yml +45 -0
  6. data/features/cassettes/pagination/repos/list.yml +176 -0
  7. data/features/cassettes/pagination/repos/list/next.yml +222 -0
  8. data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
  9. data/features/cassettes/repos/list.yml +92 -0
  10. data/features/error_codes.feature +1 -1
  11. data/features/gists.feature +12 -3
  12. data/features/gists/comments.feature +3 -3
  13. data/features/github_api.feature +13 -2
  14. data/features/pagination.feature +40 -39
  15. data/features/repos.feature +2 -2
  16. data/features/step_definitions/common_steps.rb +12 -0
  17. data/features/step_definitions/github_api_steps.rb +12 -1
  18. data/lib/github_api.rb +1 -1
  19. data/lib/github_api/api.rb +4 -2
  20. data/lib/github_api/api_factory.rb +11 -5
  21. data/lib/github_api/authorizations.rb +23 -32
  22. data/lib/github_api/client.rb +1 -0
  23. data/lib/github_api/events.rb +38 -38
  24. data/lib/github_api/filter.rb +1 -1
  25. data/lib/github_api/gists.rb +47 -42
  26. data/lib/github_api/gists/comments.rb +77 -84
  27. data/lib/github_api/git_data.rb +25 -6
  28. data/lib/github_api/git_data/blobs.rb +48 -45
  29. data/lib/github_api/git_data/commits.rb +76 -73
  30. data/lib/github_api/git_data/references.rb +137 -118
  31. data/lib/github_api/git_data/tags.rb +74 -70
  32. data/lib/github_api/git_data/trees.rb +88 -85
  33. data/lib/github_api/issues.rb +43 -31
  34. data/lib/github_api/issues/comments.rb +116 -119
  35. data/lib/github_api/issues/events.rb +20 -19
  36. data/lib/github_api/issues/labels.rb +200 -197
  37. data/lib/github_api/issues/milestones.rb +137 -134
  38. data/lib/github_api/orgs.rb +27 -23
  39. data/lib/github_api/orgs/members.rb +105 -108
  40. data/lib/github_api/orgs/teams.rb +236 -237
  41. data/lib/github_api/paged_request.rb +1 -1
  42. data/lib/github_api/pull_requests.rb +40 -42
  43. data/lib/github_api/pull_requests/comments.rb +140 -143
  44. data/lib/github_api/repos.rb +101 -67
  45. data/lib/github_api/repos/collaborators.rb +64 -68
  46. data/lib/github_api/repos/commits.rb +50 -39
  47. data/lib/github_api/repos/downloads.rb +107 -110
  48. data/lib/github_api/repos/forks.rb +38 -39
  49. data/lib/github_api/repos/hooks.rb +161 -167
  50. data/lib/github_api/repos/keys.rb +86 -86
  51. data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
  52. data/lib/github_api/repos/watching.rb +80 -82
  53. data/lib/github_api/request.rb +5 -9
  54. data/lib/github_api/users.rb +26 -16
  55. data/lib/github_api/users/emails.rb +47 -47
  56. data/lib/github_api/users/followers.rb +85 -86
  57. data/lib/github_api/users/keys.rb +73 -75
  58. data/lib/github_api/validations.rb +25 -0
  59. data/lib/github_api/validations/format.rb +23 -0
  60. data/lib/github_api/validations/presence.rb +25 -0
  61. data/lib/github_api/validations/required.rb +21 -0
  62. data/lib/github_api/validations/token.rb +41 -0
  63. data/lib/github_api/version.rb +3 -3
  64. data/spec/fixtures/repos/commit_comparison.json +112 -0
  65. data/spec/github/api_factory_spec.rb +17 -1
  66. data/spec/github/authorizations_spec.rb +36 -34
  67. data/spec/github/gists/comments_spec.rb +39 -45
  68. data/spec/github/gists_spec.rb +50 -53
  69. data/spec/github/git_data/blobs_spec.rb +27 -20
  70. data/spec/github/git_data/commits_spec.rb +20 -19
  71. data/spec/github/git_data/references_spec.rb +83 -46
  72. data/spec/github/git_data/tags_spec.rb +16 -15
  73. data/spec/github/git_data/trees_spec.rb +20 -19
  74. data/spec/github/git_data_spec.rb +10 -1
  75. data/spec/github/issues/comments_spec.rb +78 -68
  76. data/spec/github/issues/events_spec.rb +42 -34
  77. data/spec/github/issues/labels_spec.rb +89 -101
  78. data/spec/github/issues/milestones_spec.rb +76 -54
  79. data/spec/github/issues_spec.rb +53 -57
  80. data/spec/github/orgs/members_spec.rb +64 -49
  81. data/spec/github/orgs/teams_spec.rb +112 -101
  82. data/spec/github/orgs_spec.rb +41 -31
  83. data/spec/github/paged_request_spec.rb +6 -5
  84. data/spec/github/pull_requests/comments_spec.rb +39 -44
  85. data/spec/github/pull_requests_spec.rb +32 -48
  86. data/spec/github/repos/collaborators_spec.rb +40 -29
  87. data/spec/github/repos/commits_spec.rb +108 -64
  88. data/spec/github/repos/downloads_spec.rb +46 -45
  89. data/spec/github/repos/forks_spec.rb +23 -24
  90. data/spec/github/repos/hooks_spec.rb +69 -71
  91. data/spec/github/repos/keys_spec.rb +39 -34
  92. data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
  93. data/spec/github/repos/watching_spec.rb +31 -33
  94. data/spec/github/repos_spec.rb +74 -83
  95. data/spec/github/request_spec.rb +31 -2
  96. data/spec/github/users/emails_spec.rb +19 -17
  97. data/spec/github/users/followers_spec.rb +30 -28
  98. data/spec/github/users/keys_spec.rb +37 -33
  99. data/spec/github/users_spec.rb +124 -125
  100. data/spec/github/validations/format_spec.rb +42 -0
  101. data/spec/github/validations/presence_spec.rb +18 -0
  102. data/spec/github/validations/required_spec.rb +28 -0
  103. data/spec/github/validations/token_spec.rb +19 -0
  104. data/spec/github/validations_spec.rb +23 -0
  105. metadata +33 -10
  106. data/features/cassettes/pagination/repos.yml +0 -177
  107. data/features/cassettes/pagination/repos/next.yml +0 -177
  108. data/lib/github_api/validation.rb +0 -53
  109. data/spec/github/validation_spec.rb +0 -62
@@ -1,202 +1,205 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Issues
5
- module Labels
6
-
7
- VALID_LABEL_INPUTS = %w[ name color ].freeze
8
-
9
- # List all labels for a repository
10
- #
11
- # = Examples
12
- # @github = Github.new :user => 'user-name', :repo => 'repo-name'
13
- # @github.issues.labels
14
- # @github.issues.labels { |label| ... }
15
- #
16
- def labels(user_name=nil, repo_name=nil, params={})
17
- _update_user_repo_params(user_name, repo_name)
18
- _validate_user_repo_params(user, repo) unless user? && repo?
19
- _normalize_params_keys(params)
20
-
21
- response = get("/repos/#{user}/#{repo}/labels", params)
22
- return response unless block_given?
23
- response.each { |el| yield el }
4
+ class Issues::Labels < API
5
+
6
+ VALID_LABEL_INPUTS = %w[ name color ].freeze
7
+
8
+ # Creates new Issues::Labels API
9
+ def initialize(options = {})
10
+ super(options)
11
+ end
12
+
13
+ # TODO Merge repository, issues and milesonte labels insdie one query
14
+
15
+ # List all labels for a repository
16
+ #
17
+ # = Examples
18
+ # github = Github.new :user => 'user-name', :repo => 'repo-name'
19
+ # github.issues.labels.list
20
+ # github.issues.labels.list { |label| ... }
21
+ #
22
+ def list(user_name, repo_name, params={})
23
+ _update_user_repo_params(user_name, repo_name)
24
+ _validate_user_repo_params(user, repo) unless user? && repo?
25
+ _normalize_params_keys(params)
26
+
27
+ response = get_request("/repos/#{user}/#{repo}/labels", params)
28
+ return response unless block_given?
29
+ response.each { |el| yield el }
30
+ end
31
+ alias :all :list
32
+
33
+ # Get a single label
34
+ #
35
+ # = Examples
36
+ # github = Github.new
37
+ # github.issues.labels.find 'user-name', 'repo-name', 'label-id'
38
+ #
39
+ def get(user_name, repo_name, label_id, params={})
40
+ _update_user_repo_params(user_name, repo_name)
41
+ _validate_user_repo_params(user, repo) unless user? && repo?
42
+ _validate_presence_of label_id
43
+ _normalize_params_keys(params)
44
+
45
+ get_request("/repos/#{user}/#{repo}/labels/#{label_id}", params)
46
+ end
47
+ alias :find :get
48
+
49
+ # Create a label
50
+ #
51
+ # = Inputs
52
+ # <tt>:name</tt> - Required string
53
+ # <tt>:color</tt> - Required string - 6 character hex code, without leading #
54
+ #
55
+ # = Examples
56
+ # github = Github.new :user => 'user-name', :repo => 'repo-name'
57
+ # github.issues.labels.create :name => 'API', :color => 'FFFFFF'
58
+ #
59
+ def create(user_name, repo_name, params={})
60
+ _update_user_repo_params(user_name, repo_name)
61
+ _validate_user_repo_params(user, repo) unless user? && repo?
62
+
63
+ _normalize_params_keys(params)
64
+ _filter_params_keys(VALID_LABEL_INPUTS, params)
65
+ _validate_inputs(VALID_LABEL_INPUTS, params)
66
+
67
+ post_request("/repos/#{user}/#{repo}/labels", params)
68
+ end
69
+
70
+ # Update a label
71
+ #
72
+ # = Inputs
73
+ # <tt>:name</tt> - Required string
74
+ # <tt>:color</tt> - Required string-6 character hex code, without leading #
75
+ #
76
+ # = Examples
77
+ # @github = Github.new
78
+ # @github.issues.labels.update 'user-name', 'repo-name', 'label-id',
79
+ # :name => 'API', :color => "FFFFFF"
80
+ #
81
+ def update(user_name, repo_name, label_id, params={})
82
+ _update_user_repo_params(user_name, repo_name)
83
+ _validate_user_repo_params(user, repo) unless user? && repo?
84
+ _validate_presence_of label_id
85
+
86
+ _normalize_params_keys(params)
87
+ _filter_params_keys(VALID_LABEL_INPUTS, params)
88
+ _validate_inputs(VALID_LABEL_INPUTS, params)
89
+
90
+ patch_request("/repos/#{user}/#{repo}/labels/#{label_id}", params)
91
+ end
92
+ alias :edit :update
93
+
94
+ # Delete a label
95
+ #
96
+ # = Examples
97
+ # github = Github.new
98
+ # github.issues.labels.delete 'user-name', 'repo-name', 'label-id'
99
+ #
100
+ def delete(user_name, repo_name, label_id, params={})
101
+ _update_user_repo_params(user_name, repo_name)
102
+ _validate_user_repo_params(user, repo) unless user? && repo?
103
+
104
+ _validate_presence_of label_id
105
+ _normalize_params_keys params
106
+
107
+ delete_request("/repos/#{user}/#{repo}/labels/#{label_id}", params)
108
+ end
109
+
110
+ # List labels on an issue
111
+ #
112
+ # = Examples
113
+ # @github = Github.new
114
+ # @github.issues.labels.issue 'user-name', 'repo-name', 'issue-id'
115
+ #
116
+ def issue(user_name, repo_name, issue_id, params={})
117
+ _update_user_repo_params(user_name, repo_name)
118
+ _validate_user_repo_params(user, repo) unless user? && repo?
119
+ _validate_presence_of(issue_id)
120
+ _normalize_params_keys(params)
121
+
122
+ get_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
123
+ end
124
+
125
+ # Add labels to an issue
126
+ #
127
+ # = Examples
128
+ # github = Github.new
129
+ # github.issues.labels.add 'user-name', 'repo-name', 'issue-id', 'label1', 'label2', ...
130
+ #
131
+ def add(user_name, repo_name, issue_id, *args)
132
+ params = args.last.is_a?(Hash) ? args.pop : {}
133
+ params['data'] = args unless args.empty?
134
+
135
+ _update_user_repo_params(user_name, repo_name)
136
+ _validate_user_repo_params(user, repo) unless user? && repo?
137
+ _validate_presence_of(issue_id)
138
+ _normalize_params_keys(params)
139
+
140
+ post_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
141
+ end
142
+ alias :<< :add
143
+
144
+ # Remove a label from an issue
145
+ #
146
+ # = Examples
147
+ # github = Github.new
148
+ # github.issues.labels.remove 'user-name', 'repo-name', 'issue-id', 'label-id'
149
+ #
150
+ # Remove all labels from an issue
151
+ # = Examples
152
+ # github = Github.new
153
+ # github.issues.labels.remove 'user-name', 'repo-name', 'issue-id'
154
+ #
155
+ def remove(user_name, repo_name, issue_id, label_id=nil, params={})
156
+ _update_user_repo_params(user_name, repo_name)
157
+ _validate_user_repo_params(user, repo) unless user? && repo?
158
+ _validate_presence_of issue_id
159
+ _normalize_params_keys params
160
+
161
+ if label_id
162
+ delete_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}", params)
163
+ else
164
+ delete_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
24
165
  end
25
- alias :list_labels :labels
26
-
27
- # Get a single label
28
- #
29
- # = Examples
30
- # @github = Github.new
31
- # @github.issues.label 'user-name', 'repo-name', 'label-id'
32
- #
33
- def label(user_name, repo_name, label_id, params={})
34
- _update_user_repo_params(user_name, repo_name)
35
- _validate_user_repo_params(user, repo) unless user? && repo?
36
- _validate_presence_of label_id
37
- _normalize_params_keys(params)
38
-
39
- get("/repos/#{user}/#{repo}/labels/#{label_id}", params)
40
- end
41
- alias :get_label :label
42
-
43
- # Create a label
44
- #
45
- # = Inputs
46
- # <tt>:name</tt> - Required string
47
- # <tt>:color</tt> - Required string - 6 character hex code, without leading #
48
- #
49
- # = Examples
50
- # @github = Github.new :user => 'user-name', :repo => 'repo-name'
51
- # @github.issues.create_label :name => 'API', :color => 'FFFFFF'
52
- #
53
- def create_label(user_name=nil, repo_name=nil, params={})
54
- _update_user_repo_params(user_name, repo_name)
55
- _validate_user_repo_params(user, repo) unless user? && repo?
56
-
57
- _normalize_params_keys(params)
58
- _filter_params_keys(VALID_LABEL_INPUTS, params)
59
- _validate_inputs(VALID_LABEL_INPUTS, params)
60
-
61
- post("/repos/#{user}/#{repo}/labels", params)
62
- end
63
-
64
- # Update a label
65
- #
66
- # = Inputs
67
- # <tt>:name</tt> - Required string
68
- # <tt>:color</tt> - Required string - 6 character hex code, without leading #
69
- #
70
- # = Examples
71
- # @github = Github.new
72
- # @github.issues.update_label 'user-name', 'repo-name', 'label-id', :name => 'API', :color => "FFFFFF"
73
- #
74
- def update_label(user_name, repo_name, label_id, params={})
75
- _update_user_repo_params(user_name, repo_name)
76
- _validate_user_repo_params(user, repo) unless user? && repo?
77
- _validate_presence_of label_id
78
-
79
- _normalize_params_keys(params)
80
- _filter_params_keys(VALID_LABEL_INPUTS, params)
81
- _validate_inputs(VALID_LABEL_INPUTS, params)
82
-
83
- patch("/repos/#{user}/#{repo}/labels/#{label_id}", params)
84
- end
85
-
86
- # Delete a label
87
- #
88
- # = Examples
89
- # @github = Github.new
90
- # @github.issues.delete_label 'user-name', 'repo-name', 'label-id'
91
- #
92
- def delete_label(user_name, repo_name, label_id, params={})
93
- _update_user_repo_params(user_name, repo_name)
94
- _validate_user_repo_params(user, repo) unless user? && repo?
95
-
96
- _validate_presence_of label_id
97
- _normalize_params_keys params
98
-
99
- delete("/repos/#{user}/#{repo}/labels/#{label_id}", params)
100
- end
101
-
102
- # List labels on an issue
103
- #
104
- # = Examples
105
- # @github = Github.new
106
- # @github.issues.labels_for 'user-name', 'repo-name', 'issue-id'
107
- #
108
- def labels_for(user_name, repo_name, issue_id, params={})
109
- _update_user_repo_params(user_name, repo_name)
110
- _validate_user_repo_params(user, repo) unless user? && repo?
111
- _validate_presence_of(issue_id)
112
- _normalize_params_keys(params)
113
-
114
- get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
115
- end
116
- alias :issue_labels :labels_for
117
-
118
- # Add labels to an issue
119
- #
120
- # = Examples
121
- # @github = Github.new
122
- # @github.issues.add_labels 'user-name', 'repo-name', 'issue-id', 'label1', 'label2', ...
123
- #
124
- def add_labels(user_name, repo_name, issue_id, *args)
125
- params = args.last.is_a?(Hash) ? args.pop : {}
126
- params['data'] = args unless args.empty?
127
-
128
- _update_user_repo_params(user_name, repo_name)
129
- _validate_user_repo_params(user, repo) unless user? && repo?
130
- _validate_presence_of(issue_id)
131
- _normalize_params_keys(params)
132
-
133
- post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
134
- end
135
- alias :add_issue_labels :add_labels
136
-
137
- # Remove a label from an issue
138
- #
139
- # = Examples
140
- # @github = Github.new
141
- # @github.issues.remove_label 'user-name', 'repo-name', 'issue-id', 'label-id'
142
- #
143
- # Remove all labels from an issue
144
- # = Examples
145
- # @github = Github.new
146
- # @github.issues.remove_label 'user-name', 'repo-name', 'issue-id'
147
- #
148
- def remove_label(user_name, repo_name, issue_id, label_id=nil, params={})
149
- _update_user_repo_params(user_name, repo_name)
150
- _validate_user_repo_params(user, repo) unless user? && repo?
151
- _validate_presence_of issue_id
152
- _normalize_params_keys params
153
-
154
- if label_id
155
- delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels/#{label_id}", params)
156
- else
157
- delete("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
158
- end
159
- end
160
- alias :remove_label_from_issue :remove_label
161
-
162
- # Replace all labels for an issue
163
- #
164
- # Sending an empty array ([]) will remove all Labels from the Issue.
165
- #
166
- # = Examples
167
- # @github = Github.new
168
- # @github.issues.replace_labels 'user-name', 'repo-name', 'issue-id', 'label1', 'label2', ...
169
- #
170
- def replace_labels(user_name, repo_name, issue_id, *args)
171
- params = args.last.is_a?(Hash) ? args.pop : {}
172
- params['data'] = args unless args.empty?
173
-
174
- _update_user_repo_params(user_name, repo_name)
175
- _validate_user_repo_params(user, repo) unless user? && repo?
176
- _validate_presence_of issue_id
177
- _normalize_params_keys(params)
178
-
179
- put("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
180
- end
181
-
182
- # Get labels for every issue in a milestone
183
- #
184
- # = Examples
185
- # @github = Github.new
186
- # @github.issues.get_label 'user-name', 'repo-name', 'milestone-id'
187
- #
188
- def milestone_labels(user_name, repo_name, milestone_id, params={})
189
- _update_user_repo_params(user_name, repo_name)
190
- _validate_user_repo_params(user, repo) unless user? && repo?
191
- _validate_presence_of milestone_id
192
-
193
- response = get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
194
- return response unless block_given?
195
- response.each { |el| yield el }
196
- end
197
- alias :milestone_issues_labels :milestone_labels
198
- alias :list_milestone_labels :milestone_labels
199
-
200
- end # Labels
201
- end # Issues
166
+ end
167
+
168
+ # Replace all labels for an issue
169
+ #
170
+ # Sending an empty array ([]) will remove all Labels from the Issue.
171
+ #
172
+ # = Examples
173
+ # github = Github.new
174
+ # github.issues.labels.replace 'user-name', 'repo-name', 'issue-id', 'label1', 'label2', ...
175
+ #
176
+ def replace(user_name, repo_name, issue_id, *args)
177
+ params = args.last.is_a?(Hash) ? args.pop : {}
178
+ params['data'] = args unless args.empty?
179
+
180
+ _update_user_repo_params(user_name, repo_name)
181
+ _validate_user_repo_params(user, repo) unless user? && repo?
182
+ _validate_presence_of issue_id
183
+ _normalize_params_keys(params)
184
+
185
+ put_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
186
+ end
187
+
188
+ # Get labels for every issue in a milestone
189
+ #
190
+ # = Examples
191
+ # github = Github.new
192
+ # github.issues.labels. 'user-name', 'repo-name', 'milestone-id'
193
+ #
194
+ def milestone(user_name, repo_name, milestone_id, params={})
195
+ _update_user_repo_params(user_name, repo_name)
196
+ _validate_user_repo_params(user, repo) unless user? && repo?
197
+ _validate_presence_of milestone_id
198
+
199
+ response = get_request("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
200
+ return response unless block_given?
201
+ response.each { |el| yield el }
202
+ end
203
+
204
+ end # Issues::Labels
202
205
  end # Github
@@ -1,138 +1,141 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Issues
5
- module Milestones
6
-
7
- VALID_MILESTONE_OPTIONS = {
8
- 'state' => %w[ open closed ],
9
- 'sort' => %w[ due_date completeness ],
10
- 'direction' => %w[ desc asc ]
11
- }.freeze # :nodoc:
12
-
13
- VALID_MILESTONE_INPUTS = %w[
14
- title
15
- state
16
- description
17
- due_on
18
- ].freeze # :nodoc:
19
-
20
- # List milestones for a repository
21
- #
22
- # = Parameters
23
- # <tt>:state</tt> - <tt>open</tt>, <tt>closed</tt>, default: <tt>open</tt>
24
- # <tt>:sort</tt> - <tt>due_date</tt>, <tt>completeness</tt>, default: <tt>due_date</tt>
25
- # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
26
- #
27
- # = Examples
28
- # @github = Github.new :user => 'user-name', :repo => 'repo-name'
29
- # @github.issues.milestones
30
- #
31
- # or
32
- #
33
- # @github.issues.milestones :state => 'open',
34
- # :sort => 'due_date',
35
- # :direction => 'asc'
36
- #
37
- def milestones(user_name=nil, repo_name=nil, params={})
38
- _update_user_repo_params(user_name, repo_name)
39
- _validate_user_repo_params(user, repo) unless user? && repo?
40
-
41
- _normalize_params_keys(params)
42
- _filter_params_keys(VALID_MILESTONE_OPTIONS.keys, params)
43
- _validate_params_values(VALID_MILESTONE_OPTIONS, params)
44
-
45
- response = get("/repos/#{user}/#{repo}/milestones", params)
46
- return response unless block_given?
47
- response.each { |el| yield el }
48
- end
49
- alias :list_milestones :milestones
50
-
51
- # Get a single milestone
52
- #
53
- # = Examples
54
- # @github = Github.new
55
- # @github.issues.milestone 'user-name', 'repo-name', 'milestone-id'
56
- #
57
- def milestone(user_name, repo_name, milestone_id, params={})
58
- _update_user_repo_params(user_name, repo_name)
59
- _validate_user_repo_params(user, repo) unless user? && repo?
60
- _validate_presence_of milestone_id
61
- _normalize_params_keys(params)
62
-
63
- get("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
64
- end
65
- alias :get_milestone :milestone
66
-
67
- # Create a milestone
68
- #
69
- # = Inputs
70
- # <tt>:title</tt> - Required string
71
- # <tt>:state</tt> - Optional string - <tt>open</tt> or <tt>closed</tt>
72
- # <tt>:description</tt> - Optional string
73
- # <tt>:due_on</tt> - Optional string - ISO 8601 time
74
- #
75
- # = Examples
76
- # @github = Github.new :user => 'user-name', :repo => 'repo-name'
77
- # @github.issues.create_milestone :title => 'hello-world',
78
- # :state => "open or closed",
79
- # :description => "String",
80
- # :due_on => "Time"
81
- #
82
- def create_milestone(user_name=nil, repo_name=nil, params={})
83
- _update_user_repo_params(user_name, repo_name)
84
- _validate_user_repo_params(user, repo) unless user? && repo?
85
-
86
- _normalize_params_keys(params)
87
- _filter_params_keys(VALID_MILESTONE_INPUTS, params)
88
- _validate_inputs(%w[ title ], params)
89
-
90
- post("/repos/#{user}/#{repo}/milestones", params)
91
- end
92
-
93
- # Update a milestone
94
- #
95
- # = Inputs
96
- # <tt>:title</tt> - Required string
97
- # <tt>:state</tt> - Optional string - <tt>open</tt> or <tt>closed</tt>
98
- # <tt>:description</tt> - Optional string
99
- # <tt>:due_on</tt> - Optional string - ISO 8601 time
100
- #
101
- # = Examples
102
- # @github = Github.new
103
- # @github.issues.update_milestone 'user-name', 'repo-name', 'milestone-id',
104
- # :title => 'hello-world',
105
- # :state => "open or closed",
106
- # :description => "String",
107
- # :due_on => "Time"
108
- #
109
- def update_milestone(user_name, repo_name, milestone_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 milestone_id
113
-
114
- _normalize_params_keys(params)
115
- _filter_params_keys(VALID_MILESTONE_INPUTS, params)
116
- _validate_inputs(%w[ title ], params)
117
-
118
- patch("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
119
- end
120
-
121
- # Delete a milestone
122
- #
123
- # = Examples
124
- # @github = Github.new
125
- # @github.issues.delete_milestone 'user-name', 'repo-name', 'milestone-id'
126
- #
127
- def delete_milestone(user_name, repo_name, milestone_id, params={})
128
- _update_user_repo_params(user_name, repo_name)
129
- _validate_user_repo_params(user, repo) unless user? && repo?
130
- _validate_presence_of milestone_id
131
- _normalize_params_keys(params)
132
-
133
- delete("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
134
- end
135
-
136
- end # Milestones
137
- end # Issues
4
+ class Issues::Milestones < API
5
+
6
+ VALID_MILESTONE_OPTIONS = {
7
+ 'state' => %w[ open closed ],
8
+ 'sort' => %w[ due_date completeness ],
9
+ 'direction' => %w[ desc asc ]
10
+ }.freeze # :nodoc:
11
+
12
+ VALID_MILESTONE_INPUTS = %w[
13
+ title
14
+ state
15
+ description
16
+ due_on
17
+ ].freeze # :nodoc:
18
+
19
+ # Creates new Issues::Milestones API
20
+ def initialize(options = {})
21
+ super(options)
22
+ end
23
+
24
+ # List milestones for a repository
25
+ #
26
+ # = Parameters
27
+ # <tt>:state</tt> - <tt>open</tt>, <tt>closed</tt>, default: <tt>open</tt>
28
+ # <tt>:sort</tt> - <tt>due_date</tt>, <tt>completeness</tt>, default: <tt>due_date</tt>
29
+ # <tt>:direction</tt> - <tt>asc</tt>, <tt>desc</tt>, default: <tt>desc</tt>
30
+ #
31
+ # = Examples
32
+ # github = Github.new :user => 'user-name', :repo => 'repo-name'
33
+ # github.issues.milestones.list
34
+ #
35
+ # or
36
+ #
37
+ # github.issues.milestones.list :state => 'open',
38
+ # :sort => 'due_date',
39
+ # :direction => 'asc'
40
+ #
41
+ def list(user_name, repo_name, params={})
42
+ _update_user_repo_params(user_name, repo_name)
43
+ _validate_user_repo_params(user, repo) unless user? && repo?
44
+
45
+ _normalize_params_keys(params)
46
+ _filter_params_keys(VALID_MILESTONE_OPTIONS.keys, params)
47
+ _validate_params_values(VALID_MILESTONE_OPTIONS, params)
48
+
49
+ response = get_request("/repos/#{user}/#{repo}/milestones", params)
50
+ return response unless block_given?
51
+ response.each { |el| yield el }
52
+ end
53
+ alias :all :list
54
+
55
+ # Get a single milestone
56
+ #
57
+ # = Examples
58
+ # github = Github.new
59
+ # github.issues.milestones.get 'user-name', 'repo-name', 'milestone-id'
60
+ #
61
+ def get(user_name, repo_name, milestone_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 milestone_id
65
+ _normalize_params_keys(params)
66
+
67
+ get_request("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
68
+ end
69
+ alias :find :get
70
+
71
+ # Create a milestone
72
+ #
73
+ # = Inputs
74
+ # <tt>:title</tt> - Required string
75
+ # <tt>:state</tt> - Optional string - <tt>open</tt> or <tt>closed</tt>
76
+ # <tt>:description</tt> - Optional string
77
+ # <tt>:due_on</tt> - Optional string - ISO 8601 time
78
+ #
79
+ # = Examples
80
+ # github = Github.new :user => 'user-name', :repo => 'repo-name'
81
+ # github.issues.milestones.create :title => 'hello-world',
82
+ # :state => "open or closed",
83
+ # :description => "String",
84
+ # :due_on => "Time"
85
+ #
86
+ def create(user_name, repo_name, params={})
87
+ _update_user_repo_params(user_name, repo_name)
88
+ _validate_user_repo_params(user, repo) unless user? && repo?
89
+
90
+ _normalize_params_keys(params)
91
+ _filter_params_keys(VALID_MILESTONE_INPUTS, params)
92
+ _validate_inputs(%w[ title ], params)
93
+
94
+ post_request("/repos/#{user}/#{repo}/milestones", params)
95
+ end
96
+
97
+ # Update a milestone
98
+ #
99
+ # = Inputs
100
+ # <tt>:title</tt> - Required string
101
+ # <tt>:state</tt> - Optional string - <tt>open</tt> or <tt>closed</tt>
102
+ # <tt>:description</tt> - Optional string
103
+ # <tt>:due_on</tt> - Optional string - ISO 8601 time
104
+ #
105
+ # = Examples
106
+ # github = Github.new
107
+ # github.issues.milestones.update 'user-name', 'repo-name', 'milestone-id',
108
+ # :title => 'hello-world',
109
+ # :state => "open or closed",
110
+ # :description => "String",
111
+ # :due_on => "Time"
112
+ #
113
+ def update(user_name, repo_name, milestone_id, params={})
114
+ _update_user_repo_params(user_name, repo_name)
115
+ _validate_user_repo_params(user, repo) unless user? && repo?
116
+ _validate_presence_of milestone_id
117
+
118
+ _normalize_params_keys(params)
119
+ _filter_params_keys(VALID_MILESTONE_INPUTS, params)
120
+ _validate_inputs(%w[ title ], params)
121
+
122
+ patch_request("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
123
+ end
124
+
125
+ # Delete a milestone
126
+ #
127
+ # = Examples
128
+ # github = Github.new
129
+ # github.issues.milestones.delete 'user-name', 'repo-name', 'milestone-id'
130
+ #
131
+ def delete(user_name, repo_name, milestone_id, params={})
132
+ _update_user_repo_params(user_name, repo_name)
133
+ _validate_user_repo_params(user, repo) unless user? && repo?
134
+ _validate_presence_of milestone_id
135
+ _normalize_params_keys(params)
136
+
137
+ delete_request("/repos/#{user}/#{repo}/milestones/#{milestone_id}", params)
138
+ end
139
+
140
+ end # Issues::Milestones
138
141
  end # Github