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
|
require 'cgi'
module JIRA
module Resource
class BoardFactory < JIRA::BaseFactory # :nodoc:
end
class Board < JIRA::Base
def self.all(client)
path = path_base(client) + '/board'
response = client.get(path)
json = parse_json(response.body)
results = json['values']
until json['isLast']
params = { 'startAt' => (json['startAt'] + json['maxResults']).to_s }
response = client.get(url_with_query_params(path, params))
json = parse_json(response.body)
results += json['values']
end
results.map do |board|
client.Board.build(board)
end
end
def self.find(client, key, _options = {})
response = client.get(path_base(client) + "/board/#{key}")
json = parse_json(response.body)
client.Board.build(json)
end
def issues(params = {})
path = path_base(client) + "/board/#{id}/issue"
response = client.get(url_with_query_params(path, params))
json = self.class.parse_json(response.body)
results = json['issues']
while (json['startAt'] + json['maxResults']) < json['total']
params['startAt'] = (json['startAt'] + json['maxResults'])
response = client.get(url_with_query_params(path, params))
json = self.class.parse_json(response.body)
results += json['issues']
end
results.map { |issue| client.Issue.build(issue) }
end
def configuration(params = {})
path = path_base(client) + "/board/#{id}/configuration"
response = client.get(url_with_query_params(path, params))
json = self.class.parse_json(response.body)
client.BoardConfiguration.build(json)
end
# options
# - state ~ future, active, closed, you can define multiple states separated by commas, e.g. state=active,closed
# - maxResults ~ default: 50 (JIRA API), 1000 (this library)
# - startAt ~ base index, starts at 0
def sprints(options = {})
# options.reverse_merge!(DEFAULT_OPTIONS)
response = client.get(path_base(client) + "/board/#{id}/sprint?#{options.to_query}")
json = self.class.parse_json(response.body)
json['values'].map do |sprint|
sprint['rapidview_id'] = id
client.Sprint.build(sprint)
end
end
def project
response = client.get(path_base(client) + "/board/#{id}/project")
json = self.class.parse_json(response.body)
json['values'][0]
end
def add_issue_to_backlog(issue)
client.post(path_base(client) + '/backlog/issue', { issues: [issue.id] }.to_json)
end
private
def self.path_base(client)
client.options[:context_path] + '/rest/agile/1.0'
end
def path_base(client)
self.class.path_base(client)
end
end
end
end
|