Module: Itriagetestrail::Milestones
- Included in:
- TestRailInterface
- Defined in:
- lib/itriagetestrail/testrail_objects/milestones.rb
Instance Method Summary collapse
-
#fetch_milestone(requested_milestone_name) ⇒ Object
returns the id for a requested milestone by name, or creates one if the milestone does not exist.
-
#milestone_archive_name(milestone_name, date) ⇒ Object
return a standardized name for a milestone to be archived.
-
#milestone_due_date ⇒ Object
determine the due date (end of quarter) for a new milestone being added.
-
#milestone_period_start ⇒ Object
returns timestamp for begining of first day of current quarter.
-
#milestone_runs(milestone_name) ⇒ Object
return all the runs associated with an existing milestone.
-
#normalize_milestone ⇒ Object
Establish the milestone name based on origin passed in, usually origin represents a branch or environment.
- #normalize_origin ⇒ Object
-
#rename_milestone(id, new_name) ⇒ Object
testrail call to rename a milestone (for archiving).
-
#reset_milestone(milestone_name) ⇒ Object
this archives a milestone at the turn of a quarter and creates a new one in its place.
Instance Method Details
#fetch_milestone(requested_milestone_name) ⇒ Object
returns the id for a requested milestone by name, or creates one if the milestone does not exist
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 71 def fetch_milestone(requested_milestone_name) milestones = @client.send_get("get_milestones/#{@project_id}") res = -1 milestones.each do |milestone| res = milestone['id'] if milestone['name'] == requested_milestone_name end if res == -1 # We need to add the milestone to TestRail body = { name: requested_milestone_name, due_on: milestone_due_date } res = @client.send_post("add_milestone/#{@project_id}", body)['id'] end res end |
#milestone_archive_name(milestone_name, date) ⇒ Object
return a standardized name for a milestone to be archived
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 92 def milestone_archive_name(milestone_name, date) year = date.year month = date.mon if month <= 3 "#{milestone_name} #{year}-Q1" elsif month <= 6 "#{milestone_name} #{year}-Q2" elsif month <= 9 "#{milestone_name} #{year}-Q3" else "#{milestone_name} #{year}-Q4" end end |
#milestone_due_date ⇒ Object
determine the due date (end of quarter) for a new milestone being added
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 53 def milestone_due_date time_zone = TZInfo::Timezone.get('America/Denver') current_year = time_zone.now.year month = time_zone.now.mon # determine which quarter we are in if month <= 3 Time.utc(current_year, 3, 31).strftime('%s') elsif month <= 6 Time.utc(current_year, 6, 30).strftime('%s') elsif month <= 9 Time.utc(current_year, 9, 30).strftime('%s') else Time.new(current_year, 12, 31).strftime('%s') end end |
#milestone_period_start ⇒ Object
returns timestamp for begining of first day of current quarter
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 35 def milestone_period_start time_zone = TZInfo::Timezone.get('America/Denver') current_year = time_zone.now.year month = time_zone.now.mon # determine which quarter we are in if month <= 3 time_zone.utc_to_local(Time.utc(current_year, 1, 1)) elsif month <= 6 time_zone.utc_to_local(Time.utc(current_year, 4, 1)) elsif month <= 9 time_zone.utc_to_local(Time.utc(current_year, 7, 1)) else time_zone.utc_to_local(Time.utc(current_year, 10, 1)) end end |
#milestone_runs(milestone_name) ⇒ Object
return all the runs associated with an existing milestone
108 109 110 111 112 113 114 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 108 def milestone_runs(milestone_name) # use the matching milestone id for project milestone_id = fetch_milestone(milestone_name) # fetch all test runs associated with the milestone id for project @client.send_get("get_runs/#{@project_id}&milestone_id=#{milestone_id}&is_completed=1") || [] end |
#normalize_milestone ⇒ Object
Establish the milestone name based on origin passed in, usually origin represents a branch or environment
26 27 28 29 30 31 32 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 26 def normalize_milestone if @testrail_config[:milestone].nil? || @testrail_config[:milestone].empty? normalize_origin else @testrail_config[:milestone] end end |
#normalize_origin ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 7 def normalize_origin case @testrail_config[:origin] when 'prd', 'production', 'origin/production' 'Production' when 'stg', 'staging', 'origin/staging' 'Staging' when 'dev', 'development', 'origin/development' 'Development' when 'local', '' 'Local' when 'master', 'origin/master' 'Master' else 'Dev Branch' end end |
#rename_milestone(id, new_name) ⇒ Object
testrail call to rename a milestone (for archiving)
117 118 119 120 121 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 117 def rename_milestone(id, new_name) # TODO: rename milestone with previous_milestone body = { name: new_name } @client.send_post("update_milestone/#{id}", body)['id'] end |
#reset_milestone(milestone_name) ⇒ Object
this archives a milestone at the turn of a quarter and creates a new one in its place
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/itriagetestrail/testrail_objects/milestones.rb', line 124 def reset_milestone(milestone_name) runs = milestone_runs(milestone_name) return if runs.empty? last_run_time = Time.at(runs.last['completed_on']) # if last run time is smaller than period start, do below return unless last_run_time < milestone_period_start rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time)) @milestone_id = fetch_milestone(@milestone_name) end |