class TimeLogRobot::JIRA::WorkLogger
Attributes
errors[RW]
issue_key[RW]
successes[RW]
Public Class Methods
log_all(service:, time_entries:)
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 15 def log_all(service:, time_entries:) time_entries.each do |raw_entry| entry = Entry.new(service: service, raw_entry: raw_entry) log(entry) unless is_logged?(entry) end report! end
Private Class Methods
auth()
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 71 def auth { username: username, password: password } end
build_payload(entry)
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 83 def build_payload(entry) PayloadBuilder.build( start: entry.start, # Add an extra 30 seconds for rounding to nearest minute instead of always rounding down duration_in_seconds: entry.duration_in_seconds + 30, comment: entry.comment ) end
headers()
click to toggle source
@TODO Extract since it's used in several different models
# File lib/time_log_robot/jira/work_logger.rb, line 79 def headers { 'Content-Type' => 'application/json' } end
is_logged?(entry)
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 37 def is_logged?(entry) (log_tags - entry.tags).size < log_tags.size end
log(entry)
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 41 def log(entry) payload = build_payload(entry) @issue_key = parse_issue_key(entry) response = post("/issue/#{issue_key}/worklog", basic_auth: auth, headers: headers, body: payload) if response.success? print "\e[32m.\e[0m" tag!(entry) if should_tag?(entry) @successes << [entry, issue_key, response] else print "\e[31mF\e[0m" @errors << [entry, issue_key, response] if response.code == 401 raise UnauthorizedError, "Please check your username and password and try again" end end end
parse_issue_key(entry)
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 92 def parse_issue_key(entry) IssueKeyParser.parse(entry) end
password()
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 29 def password ENV['JIRA_PASSWORD'] end
report!()
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 59 def report! Reporter.report(errors, successes) end
should_tag?(entry)
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 67 def should_tag?(entry) entry.should_tag? end
tag!(entry)
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 63 def tag!(entry) Tagger.tag(entry) end
username()
click to toggle source
# File lib/time_log_robot/jira/work_logger.rb, line 25 def username ENV['JIRA_USERNAME'] end