Class: Lazylead::Jira

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/system/jira.rb

Overview

Jira system for manipulation with issues.

Jira official documentation:

- https://docs.atlassian.com/jira-software/REST/7.3.1/#agile/1.0/issue-getIssue
- https://developer.atlassian.com/server/jira/platform/rest-apis/
Author

Yurii Dubinka ([email protected])

Copyright

Copyright © 2019-2020 Yurii Dubinka

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(opts, salt = NoSalt.new, log = Log.new) ⇒ Jira

TODO:

#57/DEV The debug method should be moved outside of ctor. This was moved here from ‘client’ method because Rubocop failed the build due to ‘Metrics/AbcSize’ violation.

Returns a new instance of Jira.



45
46
47
48
49
50
51
52
# File 'lib/lazylead/system/jira.rb', line 45

def initialize(opts, salt = NoSalt.new, log = Log.new)
  @opts = opts
  @salt = salt
  @log = log
  @log.debug "Initiate a Jira client using following opts: " \
             "#{@opts.except 'password', :password} " \
             " and salt #{@salt.id} (found=#{@salt.specified?})"
end

Instance Method Details

#issues(jql, opts = { max_results: 50, fields: nil, expand: nil }) ⇒ Object

Find the jira issues by ‘JQL’

Parameters:

  • -Jirasearchquery ('jql')

    jql’ - Jira search query

  • -ParametersforJirasearchquery. ('opts')

    :max_results => maximum number of tickets per one iteration. :fields => ticket fields to be fetched like assignee, summary, etc.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/lazylead/system/jira.rb', line 59

def issues(jql, opts = { max_results: 50, fields: nil, expand: nil })
  raw do |jira|
    start = 0
    tickets = []
    total = jira.Issue.jql(jql, max_results: 0)
    @log.debug "Found #{total} ticket(s) in '#{jql}'"
    loop do
      tickets.concat(jira.Issue.jql(jql, opts.merge(start_at: start))
                         .map { |i| Lazylead::Issue.new(i, jira) })
      @log.debug "Fetched #{tickets.size}"
      start += opts.fetch(:max_results, 50).to_i
      break if start > total
    end
    tickets
  end
end

#raw {|client| ... } ⇒ Object

Execute request to the ticketing system using raw client. For Jira the raw client is ‘jira-ruby’ gem.

Yields:

  • (client)


78
79
80
81
# File 'lib/lazylead/system/jira.rb', line 78

def raw
  raise "ll-009: No block given to method" unless block_given?
  yield client
end