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



9
10
11
12
13
# File 'lib/jira/resource/sprint.rb', line 9

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



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

def add_issue(issue)
  add_issues([issue]).first
end

#add_issues(issues) ⇒ Object



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

def add_issues(issues)
  issue_ids = issues.map(&:id)
  request_body = { issues: issue_ids }.to_json
  client.post("#{agile_path}/issue", request_body)
  issues
end

#completeObject

WORK IN PROGRESS



79
80
81
82
83
# File 'lib/jira/resource/sprint.rb', line 79

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



41
42
43
# File 'lib/jira/resource/sprint.rb', line 41

def complete_date
  get_sprint_details_attribute('complete_date')
end

#end_dateObject



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

def end_date
  get_sprint_details_attribute('end_date')
end

#get_sprint_detailsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/jira/resource/sprint.rb', line 53

def get_sprint_details
  search_url =
    "#{client.options[:site]}#{client.options[:client_path]}/rest/agile/1.0/sprint/#{id}"
  begin
    response = client.get(search_url)
  rescue StandardError
    return nil
  end
  json = self.class.parse_json(response.body)

  @start_date = json['startDate'] && Date.parse(json['startDate'])
  @end_date = json['endDate'] && Date.parse(json['endDate'])
  @complete_date = json['completeDate'] && Date.parse(json['completeDate'])
end

#get_sprint_details_attribute(attribute_name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/jira/resource/sprint.rb', line 45

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



16
17
18
19
20
# File 'lib/jira/resource/sprint.rb', line 16

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

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



68
69
70
71
# File 'lib/jira/resource/sprint.rb', line 68

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

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



73
74
75
76
# File 'lib/jira/resource/sprint.rb', line 73

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

#start_dateObject



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

def start_date
  get_sprint_details_attribute('start_date')
end