Class: Jirawatch::Interactors::Worklogger
- Inherits:
-
Object
- Object
- Jirawatch::Interactors::Worklogger
- Defined in:
- lib/jirawatch/interactors/worklogger.rb
Instance Method Summary collapse
- #call(jira_client, issue_key, total_time_spent, tracking_started_at, default_message: "") ⇒ Object
-
#initialize(editor: TTY::Editor) ⇒ Worklogger
constructor
A new instance of Worklogger.
Constructor Details
#initialize(editor: TTY::Editor) ⇒ Worklogger
Returns a new instance of Worklogger.
4 5 6 |
# File 'lib/jirawatch/interactors/worklogger.rb', line 4 def initialize (editor: TTY::Editor) @editor = editor end |
Instance Method Details
#call(jira_client, issue_key, total_time_spent, tracking_started_at, default_message: "") ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jirawatch/interactors/worklogger.rb', line 8 def call(jira_client, issue_key, total_time_spent, tracking_started_at, default_message: "") # Jira work logs have minute sensitivity thus API calls will fail with a time spent # which is less than 60 seconds fail! Jirawatch.strings.tracking_less_than_60_secs if total_time_spent < 60 worklog_file = Jirawatch.configuration.template_worklog_file % tracking_started_at.to_i worklog_lines = [] File.write worklog_file, @editor.open( worklog_file, content: Jirawatch.strings.tracking_file_content % (total_time_spent / 60) ) if .empty? File.readlines(Jirawatch.configuration.template_worklog_file % tracking_started_at.to_i).each do |line| worklog_lines << line unless line.start_with?("#") or line.strip.empty? end jira_client.Issue.find(issue_key).worklogs.build.save( { timeSpentSeconds: total_time_spent, started: tracking_started_at.strftime("%Y-%m-%dT%H:%M:%S.%L%z"), comment: worklog_lines.join("\n") } ) unless worklog_lines.empty? puts Jirawatch.strings.error_empty_worklog if worklog_lines.empty? File.delete worklog_file end |