Class: Gitloggl::Gitlab::Stack::UpdateSpent

Inherits:
Abstract
  • Object
show all
Defined in:
lib/gitloggl/gitlab/stack/update_spent.rb

Constant Summary collapse

GITLAB_SPENT_NOTE_RE =
/added (.+) of time spent/

Instance Attribute Summary

Attributes inherited from Abstract

#app, #env, #options

Instance Method Summary collapse

Methods inherited from Abstract

#call, #initialize, opt

Constructor Details

This class inherits a constructor from Gitloggl::Gitlab::Stack::Abstract

Instance Method Details

#before_callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitloggl/gitlab/stack/update_spent.rb', line 11

def before_call
  queue = env.issues.each_with_object([]) do |issue, object|
    diff_sec = issue.spent_sec  - spent_sec(issue.notes)
    diff_sec = diff_sec > 0 ? diff_sec : 0

    callback!.call(issue, diff_sec)

    next if diff_sec.zero?

    object << [
      "/api/v4/projects/#{issue.path.project_id}/issues/#{issue.path.issue_id}/add_spent_time",
      duration: "#{diff_sec}sec"
    ]
  end

  env.cli.connection.in_parallel do
    queue.each { |argv| env.cli.connection.post(*argv) }
  end
end