Class: BitBucket::Issues

Inherits:
API
  • Object
show all
Extended by:
AutoloadHelper
Defined in:
lib/bitbucket_rest_api/issues.rb

Defined Under Namespace

Classes: Comments, Components, Milestones

Constant Summary collapse

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 ]
}

Constants included from Validations

Validations::VALID_API_KEYS

Constants included from Validations::Token

Validations::Token::TOKEN_REQUIRED, Validations::Token::TOKEN_REQUIRED_REGEXP

Constants included from Request

Request::METHODS, Request::METHODS_WITH_BODIES

Constants included from Connection

Connection::ALLOWED_OPTIONS

Constants included from Constants

Constants::ACCEPT, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::QUERY_STR_SEP, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT

Instance Method Summary collapse

Methods included from AutoloadHelper

autoload_all, lookup_constant, register_constant

Methods inherited from API

#_merge_mime_type, #_merge_user_into_params!, #_merge_user_repo_into_params!, #_update_user_repo_params, #api_methods_in, inherited, #method_missing, #process_basic_auth, #set_api_client, #setup, #update_and_validate_user_repo_params

Methods included from Normalizer

#normalize!

Methods included from ParameterFilter

#filter!

Methods included from Validations::Required

#assert_required_keys, #assert_required_values_present, #parse_values

Methods included from Validations::Token

#validates_token_for

Methods included from Validations::Format

#assert_valid_values

Methods included from Validations::Presence

#_validate_presence_of, #_validate_user_repo_params

Methods included from Request

#delete_request, #get_request, #patch_request, #post_request, #put_request, #request

Methods included from Connection

#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack

Methods included from Authorization

#authenticated?, #authentication, #basic_authed?

Constructor Details

#initialize(options = { }) ⇒ Issues

Creates new Issues API


36
37
38
# File 'lib/bitbucket_rest_api/issues.rb', line 36

def initialize(options = { })
  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BitBucket::API

Instance Method Details

#commentsObject

Access to Issues::Comments API


41
42
43
# File 'lib/bitbucket_rest_api/issues.rb', line 41

def comments
  @comments ||= ApiFactory.new 'Issues::Comments'
end

#componentsObject

Access to Issues::Components API


46
47
48
# File 'lib/bitbucket_rest_api/issues.rb', line 46

def components
  @components ||= ApiFactory.new 'Issues::Components'
end

#create(user_name, repo_name, params = { }) ⇒ Object

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"

166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/bitbucket_rest_api/issues.rb', line 166

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("/1.0/repositories/#{user}/#{repo.downcase}/issues/", params)
end

#delete(user_name, repo_name, issue_id, params = { }) ⇒ Object

Delete a single issue

Examples

bitbucket = BitBucket.new
bitbucket.issues.delete 'user-name', 'repo-name', 'issue-id'

117
118
119
120
121
122
123
124
125
126
# File 'lib/bitbucket_rest_api/issues.rb', line 117

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("/1.0/repositories/#{user}/#{repo}/issues/#{issue_id}", params)
end

#edit(user_name, repo_name, issue_id, params = { }) ⇒ Object

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"

217
218
219
220
221
222
223
224
225
226
227
# File 'lib/bitbucket_rest_api/issues.rb', line 217

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("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}/", params)
end

#get(user_name, repo_name, issue_id, params = { }) ⇒ Object Also known as: find

Get a single issue

Examples

bitbucket = BitBucket.new
bitbucket.issues.get 'user-name', 'repo-name', 'issue-id'

98
99
100
101
102
103
104
105
106
107
# File 'lib/bitbucket_rest_api/issues.rb', line 98

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("/1.0/repositories/#{user}/#{repo.downcase}/issues/#{issue_id}", params)
end

#list_repo(user_name, repo_name, params = { }) ⇒ Object Also known as: list_repository

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  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'

76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bitbucket_rest_api/issues.rb', line 76

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("/1.0/repositories/#{user}/#{repo.downcase}/issues", params)
  return response.issues unless block_given?
  response.issues.each { |el| yield el }
end

#milestonesObject

Access to Issues::Milestones API


51
52
53
# File 'lib/bitbucket_rest_api/issues.rb', line 51

def milestones
  @milestones ||= ApiFactory.new 'Issues::Milestones'
end