Class: Dev::Jira

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/jira.rb,
lib/firespring_dev_commands/jira/user.rb,
lib/firespring_dev_commands/jira/issue.rb,
lib/firespring_dev_commands/jira/project.rb,
lib/firespring_dev_commands/jira/user/type.rb

Overview

Class which contains methods to conenct to jira and query issues

Defined Under Namespace

Classes: Config, Issue, Project, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username: self.class.config.username, token: self.class.config.token, url: self.class.config.url) ⇒ Jira

Initialize a new jira client using the given inputs



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/firespring_dev_commands/jira.rb', line 41

def initialize(username: self.class.config.username, token: self.class.config.token, url: self.class.config.url)
  @username = username
  @token = token
  @url = url
  @auth = Base64.strict_encode64("#{@username}:#{@token}")

  options = {
    auth_type: :basic,
    site: @url,
    default_headers: {Authorization: "Basic #{@auth}"},
    context_path: '',
    read_timeout: self.class.config.read_timeout,
    use_ssl: true,
    ssl_verify_mode: OpenSSL::SSL::VERIFY_PEER,
    http_debug: self.class.config.http_debug
  }

  @client = JIRA::Client.new(options)
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



38
39
40
# File 'lib/firespring_dev_commands/jira.rb', line 38

def auth
  @auth
end

#clientObject

Returns the value of attribute client.



38
39
40
# File 'lib/firespring_dev_commands/jira.rb', line 38

def client
  @client
end

#tokenObject

Returns the value of attribute token.



38
39
40
# File 'lib/firespring_dev_commands/jira.rb', line 38

def token
  @token
end

#urlObject

Returns the value of attribute url.



38
39
40
# File 'lib/firespring_dev_commands/jira.rb', line 38

def url
  @url
end

#usernameObject

Returns the value of attribute username.



38
39
40
# File 'lib/firespring_dev_commands/jira.rb', line 38

def username
  @username
end

Class Method Details

.config {|@config| ... } ⇒ Object Also known as: configure

Instantiates a new top level config object if one hasn’t already been created Yields that config object to any given block Returns the resulting config object

Yields:



28
29
30
31
32
# File 'lib/firespring_dev_commands/jira.rb', line 28

def config
  @config ||= Config.new
  yield(@config) if block_given?
  @config
end

Instance Method Details

#issues(jql) ⇒ Object

Query jira using the given jql and yield each matching result



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/firespring_dev_commands/jira.rb', line 62

def issues(jql, &)
  start_at = 0
  max_results = 100

  # Query Jira and yield all issues it returns
  issues = @client.Issue.jql(jql, start_at:, max_results:)
  issues.map { |data| Issue.new(data) }.each(&)

  # If we returned the max_results then there may be more - add the max results to where we start at and query again
  while issues.length >= max_results
    start_at += max_results
    issues = @client.Issue.jql(jql, start_at:, max_results:)
    issues.map { |data| Issue.new(data) }.each(&)
  end
end