Class: JIRA::Resource::Sprint

Inherits:
Base
  • Object
show all
Defined in:
lib/jira/resource/sprint.rb

Constant Summary

Constants inherited from Base

Base::QUERY_PARAMS_FOR_SEARCH, Base::QUERY_PARAMS_FOR_SINGLE_FETCH

Instance Attribute Summary

Attributes inherited from Base

#attrs, #client, #deleted, #expanded

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, belongs_to, belongs_to_relationships, build, collection_attributes_are_nested, collection_path, #collection_path, #delete, endpoint_name, #fetch, #has_errors?, has_many, has_one, #id, #initialize, key_attribute, #key_value, #method_missing, nested_collections, #new_record?, parse_json, #patched_url, #path_component, #respond_to?, #set_attrs, #set_attrs_from_response, singular_path, #to_json, #to_s, #to_sym, #url

Constructor Details

This class inherits a constructor from JIRA::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JIRA::Base

Class Method Details

.find(client, key) ⇒ Object



7
8
9
10
11
# File 'lib/jira/resource/sprint.rb', line 7

def self.find(client, key)
  response = client.get(agile_path(client, key))
  json = parse_json(response.body)
  client.Sprint.build(json)
end

Instance Method Details

#add_issue(issue) ⇒ Object



20
21
22
23
24
# File 'lib/jira/resource/sprint.rb', line 20

def add_issue(issue)
  request_body = { issues: [issue.id] }.to_json
  response = client.post("#{agile_path}/issue", request_body)
  true
end

#completeObject

WORK IN PROGRESS



88
89
90
91
92
# File 'lib/jira/resource/sprint.rb', line 88

def complete
  complete_url = "#{client.options[:site]}/rest/greenhopper/1.0/sprint/#{id}/complete"
  response = client.put(complete_url)
  self.class.parse_json(response.body)
end

#complete_dateObject



38
39
40
# File 'lib/jira/resource/sprint.rb', line 38

def complete_date
  get_sprint_details_attribute('complete_date')
end

#end_dateObject



34
35
36
# File 'lib/jira/resource/sprint.rb', line 34

def end_date
  get_sprint_details_attribute('end_date')
end

#get_sprint_detailsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jira/resource/sprint.rb', line 49

def get_sprint_details
  search_url =
    "#{client.options[:site]}#{client.options[:client_path]}/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=#{rapidview_id}&sprintId=#{id}"
  begin
    response = client.get(search_url)
  rescue StandardError
    return nil
  end
  json = self.class.parse_json(response.body)

  @start_date = Date.parse(json['sprint']['startDate']) unless json['sprint']['startDate'] == 'None'
  @end_date = Date.parse(json['sprint']['endDate']) unless json['sprint']['endDate'] == 'None'
  @completed_date = Date.parse(json['sprint']['completeDate']) unless json['sprint']['completeDate'] == 'None'
  @sprint_report = client.SprintReport.build(json['contents'])
end

#get_sprint_details_attribute(attribute_name) ⇒ Object



42
43
44
45
46
47
# File 'lib/jira/resource/sprint.rb', line 42

def get_sprint_details_attribute(attribute_name)
  attribute = instance_variable_get("@#{attribute_name}")
  return attribute if attribute
  get_sprint_details
  instance_variable_get("@#{attribute_name}")
end

#issues(options = {}) ⇒ Object

get all issues of sprint



14
15
16
17
18
# File 'lib/jira/resource/sprint.rb', line 14

def issues(options = {})
  jql = 'sprint = ' + id.to_s
  jql += " and updated >= '#{options[:updated]}'" if options[:updated]
  Issue.jql(client, jql)
end

#rapidview_idObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/jira/resource/sprint.rb', line 65

def rapidview_id
  return @attrs['rapidview_id'] if @attrs['rapidview_id']
  search_url = client.options[:site] + '/secure/GHGoToBoard.jspa?sprintId=' + id.to_s
  begin
    response = client.get(search_url)
  rescue JIRA::HTTPError => error
    return unless error.response.instance_of? Net::HTTPFound
    rapid_view_match = /rapidView=(\d+)&/.match(error.response['location'])
    @attrs['rapidview_id'] = rapid_view_match[1] unless rapid_view_match.nil?
  end
end

#save(attrs = {}, _path = nil) ⇒ Object



77
78
79
80
# File 'lib/jira/resource/sprint.rb', line 77

def save(attrs = {}, _path = nil)
  attrs = @attrs if attrs.empty?
  super(attrs, agile_path)
end

#save!(attrs = {}, _path = nil) ⇒ Object



82
83
84
85
# File 'lib/jira/resource/sprint.rb', line 82

def save!(attrs = {}, _path = nil)
  attrs = @attrs if attrs.empty?
  super(attrs, agile_path)
end

#sprint_reportObject



26
27
28
# File 'lib/jira/resource/sprint.rb', line 26

def sprint_report
  get_sprint_details_attribute('sprint_report')
end

#start_dateObject



30
31
32
# File 'lib/jira/resource/sprint.rb', line 30

def start_date
  get_sprint_details_attribute('start_date')
end