-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathissues.rb
230 lines (204 loc) · 8.13 KB
/
issues.rb
1
2
3
4
5
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# encoding: utf-8
module BitBucket
class Issues < API
extend AutoloadHelper
autoload_all 'bitbucket_rest_api/issues',
:Comments => 'comments',
:Components => 'components',
:Milestones => 'milestones'
VALID_ISSUE_PARAM_NAMES = %w[
title
content
component
milestone
version
responsible
priority
status
kind
limit
start
search
sort
reported_by
].freeze
VALID_ISSUE_PARAM_VALUES = {
'priority' => %w[ trivial minor major critical blocker ],
'status' => ['new', 'open', 'resolved', 'on hold', 'invalid', 'duplicate', 'wontfix'],
'kind' => %w[ bug enhancement proposal task ]
}
# Creates new Issues API
def initialize(options = { })
super(options)
end
# Access to Issues::Comments API
def comments
@comments ||= ApiFactory.new 'Issues::Comments'
end
# Access to Issues::Components API
def components
@components ||= ApiFactory.new 'Issues::Components'
end
# Access to Issues::Milestones API
def milestones
@milestones ||= ApiFactory.new 'Issues::Milestones'
end
# List issues for a repository
#
# = Inputs
# <tt>:limit</tt> - Optional - Number of issues to retrieve, default 15
# <tt>:start</tt> - Optional - Issue offset, default 0
# <tt>:search</tt> - Optional - A string to search for
# <tt>:sort</tt> - Optional - Sorts the output by any of the metadata fields
# <tt>:title</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue title
# <tt>:content</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue content
# <tt>:version</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the version
# <tt>:milestone</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the milestone
# <tt>:component</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the component
# <tt>:kind</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue kind
# <tt>:status</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue status
# <tt>:responsible</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the user responsible
# <tt>:reported_by</tt> - Optional - Contains a filter operation to restrict the list of issues by the user that reported the issue
#
# = Examples
# bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
# bitbucket.issues.list_repo :filter => 'kind=bug&kind=enhancement'
#
def list_repo(user_name, repo_name, params = {})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
filter! VALID_ISSUE_PARAM_NAMES, params
# _merge_mime_type(:issue, params)
assert_valid_values(VALID_ISSUE_PARAM_VALUES, params)
response = get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues", params)
return response unless block_given?
response["values"].each { |el| yield el }
end
alias :list_repository :list_repo
# Get a single issue
#
# = Examples
# bitbucket = BitBucket.new
# bitbucket.issues.get 'user-name', 'repo-name', 'issue-id'
#
def get(user_name, repo_name, issue_id, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of issue_id
normalize! params
# _merge_mime_type(:issue, params)
get_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}", params)
end
alias :find :get
# Delete a single issue
#
# = Examples
# bitbucket = BitBucket.new
# bitbucket.issues.delete 'user-name', 'repo-name', 'issue-id'
#
def delete(user_name, repo_name, issue_id, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of issue_id
normalize! params
# _merge_mime_type(:issue, params)
delete_request("/2.0/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
end
# Create an issue
#
# = Inputs
# <tt>:title</tt> - Required string
# <tt>:content</tt> - Optional string
# <tt>:responsible</tt> - Optional string - Login for the user that this issue should be assigned to.
# <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
# <tt>:version</tt> - Optional number - Version to associate this issue with
# <tt>:component</tt> - Optional number - Component to associate this issue with
# <tt>:priority</tt> - Optional string - The priority of this issue
# * <tt>trivial</tt>
# * <tt>minor</tt>
# * <tt>major</tt>
# * <tt>critical</tt>
# * <tt>blocker</tt>
# <tt>:status</tt> - Optional string - The status of this issue
# * <tt>new</tt>
# * <tt>open</tt>
# * <tt>resolved</tt>
# * <tt>on hold</tt>
# * <tt>invalid</tt>
# * <tt>duplicate</tt>
# * <tt>wontfix</tt>
# <tt>:kind</tt> - Optional string - The kind of issue
# * <tt>bug</tt>
# * <tt>enhancement</tt>
# * <tt>proposal</tt>
# * <tt>task</tt>
#
# = Examples
# bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
# bitbucket.issues.create
# "title" => "Found a bug",
# "content" => "I'm having a problem with this.",
# "responsible" => "octocat",
# "milestone" => 1,
# "priority" => "blocker"
#
def create(user_name, repo_name, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
normalize! params
_merge_user_into_params!(params) unless params.has_key?('user')
# _merge_mime_type(:issue, params)
filter! VALID_ISSUE_PARAM_NAMES, params
assert_required_keys(%w[ title ], params)
post_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/", params)
end
# Edit an issue
#
# = Inputs
# <tt>:title</tt> - Required string
# <tt>:content</tt> - Optional string
# <tt>:responsible</tt> - Optional string - Login for the user that this issue should be assigned to.
# <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
# <tt>:version</tt> - Optional number - Version to associate this issue with
# <tt>:component</tt> - Optional number - Component to associate this issue with
# <tt>:priority</tt> - Optional string - The priority of this issue
# * <tt>trivial</tt>
# * <tt>minor</tt>
# * <tt>major</tt>
# * <tt>critical</tt>
# * <tt>blocker</tt>
# <tt>:status</tt> - Optional string - The status of this issue
# * <tt>new</tt>
# * <tt>open</tt>
# * <tt>resolved</tt>
# * <tt>on hold</tt>
# * <tt>invalid</tt>
# * <tt>duplicate</tt>
# * <tt>wontfix</tt>
# <tt>:kind</tt> - Optional string - The kind of issue
# * <tt>bug</tt>
# * <tt>enhancement</tt>
# * <tt>proposal</tt>
# * <tt>task</tt>
#
# = Examples
# bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
# bitbucket.issues.create
# "title" => "Found a bug",
# "content" => "I'm having a problem with this.",
# "responsible" => "octocat",
# "milestone" => 1,
# "priority" => "blocker"
#
def edit(user_name, repo_name, issue_id, params={ })
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?
_validate_presence_of issue_id
normalize! params
# _merge_mime_type(:issue, params)
filter! VALID_ISSUE_PARAM_NAMES, params
put_request("/2.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/", params)
end
end # Issues
end # BitBucket