Class: Gitloggl::Gitlab::Cli

Inherits:
Object
  • Object
show all
Includes:
Hooks, Hooks::InstanceHooks
Defined in:
lib/gitloggl/gitlab/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ Cli

Returns a new instance of Cli.

Yields:

  • (_self)

Yield Parameters:



13
14
15
16
# File 'lib/gitloggl/gitlab/cli.rb', line 13

def initialize(params = {})
  params.each { |k, v| public_send("#{k}=", v) }
  yield(self) if block_given?
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



11
12
13
# File 'lib/gitloggl/gitlab/cli.rb', line 11

def token
  @token
end

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/gitloggl/gitlab/cli.rb', line 11

def url
  @url
end

#verboseObject

Returns the value of attribute verbose.



11
12
13
# File 'lib/gitloggl/gitlab/cli.rb', line 11

def verbose
  @verbose
end

Instance Method Details

#batch(issues) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gitloggl/gitlab/cli.rb', line 18

def batch(issues)
  stack = Middleware::Builder.new do |b|
    b.use Stack::Filter, where: ->(issue) do
      next true if issue.path.present?

      rejected(issue, %{cant recognize gitlab issue-path})

      false
    end

    b.use Stack::DetectProject

    b.use Stack::Filter, where: -> (issue) do
      next true if issue.path.project_id.present?

      rejected(issue, %{cant recognize gitlab projectID for issue})

      false
    end

    b.use Stack::LoadNotes

    b.use Stack::UpdateSpent, callback: ->(issue, diff_sec) do
      updated(issue, diff_sec)
    end
  end

  env = OpenStruct.new(cli: self, issues: issues)

  stack.call(env)
end

#connectionObject



60
61
62
63
64
# File 'lib/gitloggl/gitlab/cli.rb', line 60

def connection
  @connection ||= Connection.new(url, headers: { 'PRIVATE-TOKEN' => token }, verbose: verbose).tap do |c|
    c.transport.basic_auth(token, 'api_token')
  end
end

#current_user_idInteger

Returns:

  • (Integer)


72
73
74
# File 'lib/gitloggl/gitlab/cli.rb', line 72

def current_user_id
  @current_user_id ||= connection.get("/api/v4/user").body.fetch('id')
end

#projectsArray<JSON>

Returns:

  • (Array<JSON>)


67
68
69
# File 'lib/gitloggl/gitlab/cli.rb', line 67

def projects
  @projects ||= connection.get("/api/v4/projects").body
end

#rejected(issue, reason) ⇒ Object



50
51
52
53
# File 'lib/gitloggl/gitlab/cli.rb', line 50

def rejected(issue, reason)
  run_hook(:on_completed, issue)
  run_hook(:on_rejected, issue, reason)
end

#updated(issue, diff) ⇒ Object



55
56
57
58
# File 'lib/gitloggl/gitlab/cli.rb', line 55

def updated(issue, diff)
  run_hook(:on_completed, issue)
  run_hook(:on_updated, issue, diff)
end