Module: OnlyofficeTestrailWrapper::TestrailProjectMilestoneMethods

Included in:
TestrailProject
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb

Overview

Methods to perform operations on milestones

Instance Method Summary collapse

Instance Method Details

#create_new_milestone(name, description = '') ⇒ TestrailMilestone

Create new milestone

Parameters:

  • name (String)

    of milestone

  • description (String) (defaults to: '')

    of milestone

Returns:



58
59
60
61
62
63
64
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb', line 58

def create_new_milestone(name, description = '')
  new_milestone = TestrailMilestone.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_milestone/#{@id}",
                                                                           :name => StringHelper.warnstrip!(name.to_s),
                                                                           description => description))
  OnlyofficeLoggerHelper.log "Created new milestone: #{new_milestone.name}"
  new_milestone
end

#get_milestone_by_id(id) ⇒ TestrailMilestone

Get milestone by it’s id

Parameters:

  • id (Integer)

    of milestone

Returns:



32
33
34
35
36
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb', line 32

def get_milestone_by_id(id)
  milestone = TestrailMilestone.new.init_from_hash(Testrail2.http_get("index.php?/api/v2/get_milestone/#{id}"))
  OnlyofficeLoggerHelper.log("Initialized milestone: #{milestone.name}")
  milestone
end

#get_milestone_by_name(name) ⇒ TestrailMilestone?

Get milestone data by it’s name

Parameters:

  • name (String)

    of milestone

Returns:



41
42
43
44
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb', line 41

def get_milestone_by_name(name)
  get_milestones if @milestones_names.empty?
  @milestones_names[StringHelper.warnstrip!(name.to_s)].nil? ? nil : get_milestone_by_id(@milestones_names[name])
end

#get_milestonesArray<TestrailMilestone>

Get list of all milestones

Returns:



48
49
50
51
52
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb', line 48

def get_milestones
  milestones = Testrail2.http_get("index.php?/api/v2/get_milestones/#{@id}")
  @milestones_names = name_id_pairs(milestones) if @milestones_names.empty?
  milestones
end

#init_milestone_by_name(name) ⇒ TestrailMilestone

Get milestone data by it’s name Will create a new one if no one found

Parameters:

  • name (String)

    of milestone

Returns:



24
25
26
27
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb', line 24

def init_milestone_by_name(name)
  found_milestone = get_milestone_by_name name
  found_milestone.nil? ? create_new_milestone(name) : found_milestone
end

#milestone(name_or_id) ⇒ TestrailMilestone

Get milestone data by parameter

Parameters:

  • name_or_id (String, Integer)

    id or name of milestone

Returns:



9
10
11
12
13
14
15
16
17
18
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_milestone_methods.rb', line 9

def milestone(name_or_id)
  case name_or_id.class.to_s
  when 'Fixnum', 'Integer'
    get_milestone_by_id name_or_id
  when 'String'
    init_milestone_by_name name_or_id
  else
    raise 'Wrong argument. Must be name [String] or id [Integer]'
  end
end