bitbuckets 0.2.0

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 (122) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +7 -0
  3. data/README.md +169 -0
  4. data/Rakefile +1 -0
  5. data/lib/bitbucket_rest_api.rb +86 -0
  6. data/lib/bitbucket_rest_api/api.rb +104 -0
  7. data/lib/bitbucket_rest_api/api/actions.rb +32 -0
  8. data/lib/bitbucket_rest_api/api_factory.rb +29 -0
  9. data/lib/bitbucket_rest_api/authorization.rb +31 -0
  10. data/lib/bitbucket_rest_api/client.rb +53 -0
  11. data/lib/bitbucket_rest_api/configuration.rb +103 -0
  12. data/lib/bitbucket_rest_api/connection.rb +97 -0
  13. data/lib/bitbucket_rest_api/constants.rb +57 -0
  14. data/lib/bitbucket_rest_api/core_ext/array.rb +6 -0
  15. data/lib/bitbucket_rest_api/core_ext/hash.rb +58 -0
  16. data/lib/bitbucket_rest_api/deprecation.rb +36 -0
  17. data/lib/bitbucket_rest_api/error.rb +37 -0
  18. data/lib/bitbucket_rest_api/error/bad_events.rb +10 -0
  19. data/lib/bitbucket_rest_api/error/bad_request.rb +11 -0
  20. data/lib/bitbucket_rest_api/error/blank_value.rb +10 -0
  21. data/lib/bitbucket_rest_api/error/client_error.rb +19 -0
  22. data/lib/bitbucket_rest_api/error/forbidden.rb +11 -0
  23. data/lib/bitbucket_rest_api/error/internal_server_error.rb +11 -0
  24. data/lib/bitbucket_rest_api/error/invalid_options.rb +17 -0
  25. data/lib/bitbucket_rest_api/error/no_events.rb +10 -0
  26. data/lib/bitbucket_rest_api/error/not_found.rb +11 -0
  27. data/lib/bitbucket_rest_api/error/required_params.rb +17 -0
  28. data/lib/bitbucket_rest_api/error/service_error.rb +18 -0
  29. data/lib/bitbucket_rest_api/error/service_unavailable.rb +11 -0
  30. data/lib/bitbucket_rest_api/error/unauthorized.rb +11 -0
  31. data/lib/bitbucket_rest_api/error/unknown_value.rb +17 -0
  32. data/lib/bitbucket_rest_api/error/unprocessable_entity.rb +11 -0
  33. data/lib/bitbucket_rest_api/error/validations.rb +17 -0
  34. data/lib/bitbucket_rest_api/invitations.rb +14 -0
  35. data/lib/bitbucket_rest_api/issues.rb +229 -0
  36. data/lib/bitbucket_rest_api/issues/comments.rb +116 -0
  37. data/lib/bitbucket_rest_api/issues/components.rb +105 -0
  38. data/lib/bitbucket_rest_api/issues/milestones.rb +105 -0
  39. data/lib/bitbucket_rest_api/normalizer.rb +24 -0
  40. data/lib/bitbucket_rest_api/parameter_filter.rb +29 -0
  41. data/lib/bitbucket_rest_api/repos.rb +276 -0
  42. data/lib/bitbucket_rest_api/repos/changesets.rb +52 -0
  43. data/lib/bitbucket_rest_api/repos/commits.rb +38 -0
  44. data/lib/bitbucket_rest_api/repos/components.rb +35 -0
  45. data/lib/bitbucket_rest_api/repos/default_reviewers.rb +60 -0
  46. data/lib/bitbucket_rest_api/repos/download.rb +15 -0
  47. data/lib/bitbucket_rest_api/repos/following.rb +38 -0
  48. data/lib/bitbucket_rest_api/repos/forks.rb +66 -0
  49. data/lib/bitbucket_rest_api/repos/keys.rb +86 -0
  50. data/lib/bitbucket_rest_api/repos/pull_request.rb +158 -0
  51. data/lib/bitbucket_rest_api/repos/services.rb +101 -0
  52. data/lib/bitbucket_rest_api/repos/sources.rb +36 -0
  53. data/lib/bitbucket_rest_api/repos/webhooks.rb +99 -0
  54. data/lib/bitbucket_rest_api/request.rb +71 -0
  55. data/lib/bitbucket_rest_api/request/basic_auth.rb +30 -0
  56. data/lib/bitbucket_rest_api/request/jsonize.rb +39 -0
  57. data/lib/bitbucket_rest_api/request/oauth.rb +50 -0
  58. data/lib/bitbucket_rest_api/response.rb +26 -0
  59. data/lib/bitbucket_rest_api/response/helpers.rb +18 -0
  60. data/lib/bitbucket_rest_api/response/jsonize.rb +25 -0
  61. data/lib/bitbucket_rest_api/response/mashify.rb +23 -0
  62. data/lib/bitbucket_rest_api/response/raise_error.rb +28 -0
  63. data/lib/bitbucket_rest_api/response/xmlize.rb +25 -0
  64. data/lib/bitbucket_rest_api/result.rb +136 -0
  65. data/lib/bitbucket_rest_api/teams.rb +91 -0
  66. data/lib/bitbucket_rest_api/user.rb +87 -0
  67. data/lib/bitbucket_rest_api/users.rb +20 -0
  68. data/lib/bitbucket_rest_api/users/account.rb +50 -0
  69. data/lib/bitbucket_rest_api/utils/url.rb +61 -0
  70. data/lib/bitbucket_rest_api/validations.rb +23 -0
  71. data/lib/bitbucket_rest_api/validations/format.rb +21 -0
  72. data/lib/bitbucket_rest_api/validations/presence.rb +21 -0
  73. data/lib/bitbucket_rest_api/validations/required.rb +37 -0
  74. data/lib/bitbucket_rest_api/validations/token.rb +38 -0
  75. data/lib/bitbucket_rest_api/version.rb +10 -0
  76. data/lib/bitbuckets.rb +2 -0
  77. data/spec/bitbucket_rest_api/api/actions_spec.rb +18 -0
  78. data/spec/bitbucket_rest_api/api_factory_spec.rb +28 -0
  79. data/spec/bitbucket_rest_api/api_spec.rb +87 -0
  80. data/spec/bitbucket_rest_api/authorization_spec.rb +74 -0
  81. data/spec/bitbucket_rest_api/client_spec.rb +17 -0
  82. data/spec/bitbucket_rest_api/core_ext/array_spec.rb +13 -0
  83. data/spec/bitbucket_rest_api/core_ext/hash_spec.rb +47 -0
  84. data/spec/bitbucket_rest_api/deprecation_spec.rb +31 -0
  85. data/spec/bitbucket_rest_api/error/bad_events_spec.rb +11 -0
  86. data/spec/bitbucket_rest_api/error/blank_value_spec.rb +14 -0
  87. data/spec/bitbucket_rest_api/error/no_events_spec.rb +11 -0
  88. data/spec/bitbucket_rest_api/invitations_spec.rb +21 -0
  89. data/spec/bitbucket_rest_api/issues/comments_spec.rb +89 -0
  90. data/spec/bitbucket_rest_api/issues/components_spec.rb +89 -0
  91. data/spec/bitbucket_rest_api/issues/milestones_spec.rb +89 -0
  92. data/spec/bitbucket_rest_api/issues_spec.rb +91 -0
  93. data/spec/bitbucket_rest_api/normalizer_spec.rb +29 -0
  94. data/spec/bitbucket_rest_api/parameter_filter_spec.rb +42 -0
  95. data/spec/bitbucket_rest_api/repos/changesets_spec.rb +44 -0
  96. data/spec/bitbucket_rest_api/repos/commits_spec.rb +21 -0
  97. data/spec/bitbucket_rest_api/repos/components_spec.rb +43 -0
  98. data/spec/bitbucket_rest_api/repos/default_reviewers_spec.rb +65 -0
  99. data/spec/bitbucket_rest_api/repos/download_spec.rb +10 -0
  100. data/spec/bitbucket_rest_api/repos/following_spec.rb +53 -0
  101. data/spec/bitbucket_rest_api/repos/forks_spec.rb +46 -0
  102. data/spec/bitbucket_rest_api/repos/keys_spec.rb +73 -0
  103. data/spec/bitbucket_rest_api/repos/pull_request_spec.rb +283 -0
  104. data/spec/bitbucket_rest_api/repos/sources_spec.rb +78 -0
  105. data/spec/bitbucket_rest_api/repos/webhooks_spec.rb +245 -0
  106. data/spec/bitbucket_rest_api/repos_spec.rb +158 -0
  107. data/spec/bitbucket_rest_api/request/jsonize_spec.rb +19 -0
  108. data/spec/bitbucket_rest_api/request/oauth_spec.rb +26 -0
  109. data/spec/bitbucket_rest_api/request_spec.rb +88 -0
  110. data/spec/bitbucket_rest_api/response/jsonize_spec.rb +13 -0
  111. data/spec/bitbucket_rest_api/response/mashify_spec.rb +33 -0
  112. data/spec/bitbucket_rest_api/response/raise_error_spec.rb +42 -0
  113. data/spec/bitbucket_rest_api/teams_spec.rb +136 -0
  114. data/spec/bitbucket_rest_api/user_spec.rb +78 -0
  115. data/spec/bitbucket_rest_api/utils/url_spec.rb +34 -0
  116. data/spec/bitbucket_rest_api/validations/format_spec.rb +30 -0
  117. data/spec/bitbucket_rest_api/validations/presence_spec.rb +13 -0
  118. data/spec/bitbucket_rest_api/validations/required_spec.rb +44 -0
  119. data/spec/bitbucket_rest_api/validations/token_spec.rb +17 -0
  120. data/spec/bitbucket_rest_api_spec.rb +17 -0
  121. data/spec/spec_helper.rb +24 -0
  122. metadata +358 -0
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Error
4
+ class BadEvents < ClientError
5
+ def initialize(event)
6
+ super "The event: '#{event}', does not exist :("
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Error
4
+ # Raised when BitBucket returns the HTTP status code 400
5
+ class BadRequest < ServiceError
6
+ def initialize(env)
7
+ super(env)
8
+ end
9
+ end
10
+ end
11
+ end # BitBucket
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Error
4
+ class BlankValue < ClientError
5
+ def initialize(required_key)
6
+ super "The value for: '#{required_key}', cannot be blank :("
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns the HTTP status code 404
4
+ module Error
5
+ class ClientError < BitBucketError
6
+ attr_reader :problem, :summary, :resolution
7
+
8
+ def initialize(message)
9
+ super(message)
10
+ end
11
+
12
+ def generate_message(attributes)
13
+ "\nProblem:\n #{attributes[:problem]}" \
14
+ "\nSummary:\n #{attributes[:summary]}" \
15
+ "\nResolution:\n #{attributes[:resolution]}"
16
+ end
17
+ end
18
+ end # Error
19
+ end # BitBucket
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns the HTTP status code 403
4
+ module Error
5
+ class Forbidden < BitBucketError
6
+ def initialize(env)
7
+ super(env)
8
+ end
9
+ end
10
+ end # Error
11
+ end # BitBucket
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns the HTTP status code 500
4
+ module Error
5
+ class InternalServerError < BitBucketError
6
+ def initialize(env)
7
+ super(env)
8
+ end
9
+ end
10
+ end # Error
11
+ end # BitBucket
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when invalid options are passed to a request body
4
+ module Error
5
+ class InvalidOptions < ClientError
6
+ def initialize(invalid, valid)
7
+ super(
8
+ generate_message(
9
+ problem: "Invalid option #{invalid.keys.join(', ')} provided for this request.",
10
+ summary: 'BitBucket gem checks the request parameters passed to ensure that github api is not hit unnecessairly and to fail fast.',
11
+ resolution: "Valid options are: #{valid.join(', ')}, make sure these are the ones you are using"
12
+ )
13
+ )
14
+ end
15
+ end
16
+ end # Error
17
+ end # BitBucket
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ module Error
4
+ class NoEvents < ClientError
5
+ def initialize
6
+ super 'At least one event is required, none given :('
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns the HTTP status code 404
4
+ module Error
5
+ class NotFound < ServiceError
6
+ def initialize(env)
7
+ super(env)
8
+ end
9
+ end
10
+ end # Error
11
+ end # BitBucket
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when invalid options are passed to a request body
4
+ module Error
5
+ class RequiredParams < ClientError
6
+ def initialize(provided, required)
7
+ super(
8
+ generate_message(
9
+ problem: "Missing required parameters: #{provided.keys.join(', ')} provided for this request.",
10
+ summary: 'BitBucket gem checks the request parameters passed to ensure that github api is not hit unnecessairly and to fail fast.',
11
+ resolution: "Required parameters are: #{required.join(', ')}, make sure these are the ones you are using"
12
+ )
13
+ )
14
+ end
15
+ end
16
+ end # Error
17
+ end # BitBucket
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns any of the HTTP status codes
4
+ module Error
5
+ class ServiceError < BitBucketError
6
+ attr_accessor :http_headers
7
+
8
+ def initialize(env)
9
+ super(generate_message(env))
10
+ @http_headers = env[:response_headers]
11
+ end
12
+
13
+ def generate_message(env)
14
+ "#{env[:method].to_s.upcase} #{env[:url]}: #{env[:status]} #{env[:body]}"
15
+ end
16
+ end
17
+ end # Error
18
+ end # BitBucket
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns the HTTP status code 404
4
+ module Error
5
+ class ServiceUnavailable < BitBucketError
6
+ def initialize(env)
7
+ super(env)
8
+ end
9
+ end
10
+ end # Error
11
+ end # BitBucket
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns the HTTP status code 401
4
+ module Error
5
+ class Unauthorized < BitBucketError
6
+ def initialize(env)
7
+ super(env)
8
+ end
9
+ end
10
+ end # Error
11
+ end # BitBucket
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when invalid options are passed to a request body
4
+ module Error
5
+ class UnknownValue < ClientError
6
+ def initialize(key, value, permitted)
7
+ super(
8
+ generate_message(
9
+ problem: "Wrong value of '#{value}' for the parameter: #{key} provided for this request.",
10
+ summary: 'BitBucket gem checks the request parameters passed to ensure that github api is not hit unnecessairly and fails fast.',
11
+ resolution: "Permitted values are: #{permitted}, make sure these are the ones you are using"
12
+ )
13
+ )
14
+ end
15
+ end
16
+ end # Error
17
+ end # BitBucket
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when BitBucket returns the HTTP status code 422
4
+ module Error
5
+ class UnprocessableEntity < BitBucketError
6
+ def initialize(env)
7
+ super(env)
8
+ end
9
+ end
10
+ end # Error
11
+ end # BitBucket
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket #:nodoc
3
+ # Raised when passed parameters are missing or contain wrong values.
4
+ module Error
5
+ class Validations < ClientError
6
+ def initialize(_errors)
7
+ super(
8
+ generate_message(
9
+ problem: '',
10
+ summary: '',
11
+ resolution: ''
12
+ )
13
+ )
14
+ end
15
+ end
16
+ end # Error
17
+ end # BitBucket
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ class Invitations < API
4
+ def invite(user_name, repo_name, emailaddress, perm)
5
+ _update_user_repo_params(user_name, repo_name)
6
+ _validate_user_repo_params(user, repo) unless user? && repo?
7
+ _validate_presence_of emailaddress
8
+ perm ||= 'write'
9
+
10
+ post_request("/1.0/invitations/#{user}/#{repo.downcase}/#{emailaddress}",
11
+ permission: perm)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+ module BitBucket
3
+ class Issues < API
4
+ extend AutoloadHelper
5
+
6
+ autoload_all 'bitbucket_rest_api/issues',
7
+ Comments: 'comments',
8
+ Components: 'components',
9
+ Milestones: 'milestones'
10
+
11
+ VALID_ISSUE_PARAM_NAMES = %w[
12
+ title
13
+ content
14
+ component
15
+ milestone
16
+ version
17
+ responsible
18
+ priority
19
+ status
20
+ kind
21
+ limit
22
+ start
23
+ search
24
+ sort
25
+ reported_by
26
+ ].freeze
27
+
28
+ VALID_ISSUE_PARAM_VALUES = {
29
+ 'priority' => %w[trivial minor major critical blocker],
30
+ 'status' => ['new', 'open', 'resolved', 'on hold', 'invalid', 'duplicate', 'wontfix'],
31
+ 'kind' => %w[bug enhancement proposal task]
32
+ }.freeze
33
+
34
+ # Creates new Issues API
35
+ def initialize(options = {})
36
+ super(options)
37
+ end
38
+
39
+ # Access to Issues::Comments API
40
+ def comments
41
+ @comments ||= ApiFactory.new 'Issues::Comments'
42
+ end
43
+
44
+ # Access to Issues::Components API
45
+ def components
46
+ @components ||= ApiFactory.new 'Issues::Components'
47
+ end
48
+
49
+ # Access to Issues::Milestones API
50
+ def milestones
51
+ @milestones ||= ApiFactory.new 'Issues::Milestones'
52
+ end
53
+
54
+ # List issues for a repository
55
+ #
56
+ # = Inputs
57
+ # <tt>:limit</tt> - Optional - Number of issues to retrieve, default 15
58
+ # <tt>:start</tt> - Optional - Issue offset, default 0
59
+ # <tt>:search</tt> - Optional - A string to search for
60
+ # <tt>:sort</tt> - Optional - Sorts the output by any of the metadata fields
61
+ # <tt>:title</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue title
62
+ # <tt>:content</tt> - Optional - Contains a filter operation to restrict the list of issues by the issue content
63
+ # <tt>:version</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the version
64
+ # <tt>:milestone</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the milestone
65
+ # <tt>:component</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the component
66
+ # <tt>:kind</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue kind
67
+ # <tt>:status</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the issue status
68
+ # <tt>:responsible</tt> - Optional - Contains an is or ! ( is not) filter to restrict the list of issues by the user responsible
69
+ # <tt>:reported_by</tt> - Optional - Contains a filter operation to restrict the list of issues by the user that reported the issue
70
+ #
71
+ # = Examples
72
+ # bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
73
+ # bitbucket.issues.list_repo :filter => 'kind=bug&kind=enhancement'
74
+ #
75
+ def list_repo(user_name, repo_name, params = {})
76
+ _update_user_repo_params(user_name, repo_name)
77
+ _validate_user_repo_params(user, repo) unless user? && repo?
78
+
79
+ normalize! params
80
+ filter! VALID_ISSUE_PARAM_NAMES, params
81
+ # _merge_mime_type(:issue, params)
82
+ assert_valid_values(VALID_ISSUE_PARAM_VALUES, params)
83
+
84
+ response = get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues", params)
85
+ return response.issues unless block_given?
86
+
87
+ response.issues.each { |el| yield el }
88
+ end
89
+
90
+ alias list_repository list_repo
91
+
92
+ # Get a single issue
93
+ #
94
+ # = Examples
95
+ # bitbucket = BitBucket.new
96
+ # bitbucket.issues.get 'user-name', 'repo-name', 'issue-id'
97
+ #
98
+ def get(user_name, repo_name, issue_id, params = {})
99
+ _update_user_repo_params(user_name, repo_name)
100
+ _validate_user_repo_params(user, repo) unless user? && repo?
101
+ _validate_presence_of issue_id
102
+
103
+ normalize! params
104
+ # _merge_mime_type(:issue, params)
105
+
106
+ get_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}", params)
107
+ end
108
+
109
+ alias find get
110
+
111
+ # Delete a single issue
112
+ #
113
+ # = Examples
114
+ # bitbucket = BitBucket.new
115
+ # bitbucket.issues.delete 'user-name', 'repo-name', 'issue-id'
116
+ #
117
+ def delete(user_name, repo_name, issue_id, params = {})
118
+ _update_user_repo_params(user_name, repo_name)
119
+ _validate_user_repo_params(user, repo) unless user? && repo?
120
+ _validate_presence_of issue_id
121
+
122
+ normalize! params
123
+ # _merge_mime_type(:issue, params)
124
+
125
+ delete_request("/1.0/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
126
+ end
127
+
128
+ # Create an issue
129
+ #
130
+ # = Inputs
131
+ # <tt>:title</tt> - Required string
132
+ # <tt>:content</tt> - Optional string
133
+ # <tt>:responsible</tt> - Optional string - Login for the user that this issue should be assigned to.
134
+ # <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
135
+ # <tt>:version</tt> - Optional number - Version to associate this issue with
136
+ # <tt>:component</tt> - Optional number - Component to associate this issue with
137
+ # <tt>:priority</tt> - Optional string - The priority of this issue
138
+ # * <tt>trivial</tt>
139
+ # * <tt>minor</tt>
140
+ # * <tt>major</tt>
141
+ # * <tt>critical</tt>
142
+ # * <tt>blocker</tt>
143
+ # <tt>:status</tt> - Optional string - The status of this issue
144
+ # * <tt>new</tt>
145
+ # * <tt>open</tt>
146
+ # * <tt>resolved</tt>
147
+ # * <tt>on hold</tt>
148
+ # * <tt>invalid</tt>
149
+ # * <tt>duplicate</tt>
150
+ # * <tt>wontfix</tt>
151
+ # <tt>:kind</tt> - Optional string - The kind of issue
152
+ # * <tt>bug</tt>
153
+ # * <tt>enhancement</tt>
154
+ # * <tt>proposal</tt>
155
+ # * <tt>task</tt>
156
+ #
157
+ # = Examples
158
+ # bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
159
+ # bitbucket.issues.create
160
+ # "title" => "Found a bug",
161
+ # "content" => "I'm having a problem with this.",
162
+ # "responsible" => "octocat",
163
+ # "milestone" => 1,
164
+ # "priority" => "blocker"
165
+ #
166
+ def create(user_name, repo_name, params = {})
167
+ _update_user_repo_params(user_name, repo_name)
168
+ _validate_user_repo_params(user, repo) unless user? && repo?
169
+
170
+ normalize! params
171
+ _merge_user_into_params!(params) unless params.key?('user')
172
+ # _merge_mime_type(:issue, params)
173
+ filter! VALID_ISSUE_PARAM_NAMES, params
174
+ assert_required_keys(%w[title], params)
175
+
176
+ post_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params)
177
+ end
178
+
179
+ # Edit an issue
180
+ #
181
+ # = Inputs
182
+ # <tt>:title</tt> - Required string
183
+ # <tt>:content</tt> - Optional string
184
+ # <tt>:responsible</tt> - Optional string - Login for the user that this issue should be assigned to.
185
+ # <tt>:milestone</tt> - Optional number - Milestone to associate this issue with
186
+ # <tt>:version</tt> - Optional number - Version to associate this issue with
187
+ # <tt>:component</tt> - Optional number - Component to associate this issue with
188
+ # <tt>:priority</tt> - Optional string - The priority of this issue
189
+ # * <tt>trivial</tt>
190
+ # * <tt>minor</tt>
191
+ # * <tt>major</tt>
192
+ # * <tt>critical</tt>
193
+ # * <tt>blocker</tt>
194
+ # <tt>:status</tt> - Optional string - The status of this issue
195
+ # * <tt>new</tt>
196
+ # * <tt>open</tt>
197
+ # * <tt>resolved</tt>
198
+ # * <tt>on hold</tt>
199
+ # * <tt>invalid</tt>
200
+ # * <tt>duplicate</tt>
201
+ # * <tt>wontfix</tt>
202
+ # <tt>:kind</tt> - Optional string - The kind of issue
203
+ # * <tt>bug</tt>
204
+ # * <tt>enhancement</tt>
205
+ # * <tt>proposal</tt>
206
+ # * <tt>task</tt>
207
+ #
208
+ # = Examples
209
+ # bitbucket = BitBucket.new :user => 'user-name', :repo => 'repo-name'
210
+ # bitbucket.issues.create
211
+ # "title" => "Found a bug",
212
+ # "content" => "I'm having a problem with this.",
213
+ # "responsible" => "octocat",
214
+ # "milestone" => 1,
215
+ # "priority" => "blocker"
216
+ #
217
+ def edit(user_name, repo_name, issue_id, params = {})
218
+ _update_user_repo_params(user_name, repo_name)
219
+ _validate_user_repo_params(user, repo) unless user? && repo?
220
+ _validate_presence_of issue_id
221
+
222
+ normalize! params
223
+ # _merge_mime_type(:issue, params)
224
+ filter! VALID_ISSUE_PARAM_NAMES, params
225
+
226
+ put_request("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/", params)
227
+ end
228
+ end # Issues
229
+ end # BitBucket