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/parent.rb,
lib/firespring_dev_commands/jira/history.rb,
lib/firespring_dev_commands/jira/project.rb,
lib/firespring_dev_commands/jira/histories.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, Histories, History, Issue, Parent, Project, User

Constant Summary collapse

CONFIG_FILE =

The config file to try to load credentials from

"#{Dir.home}/.env.jira".freeze
JIRA_USERNAME =

The text of the username variable key

'JIRA_USERNAME'.freeze
JIRA_TOKEN =

The text of the token variable key

'JIRA_TOKEN'.freeze
JIRA_URL =

The text of the url variable key

'JIRA_URL'.freeze

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/firespring_dev_commands/jira.rb', line 56

def initialize(username: self.class.config.username, token: self.class.config.token, url: self.class.config.url)
  raise 'username is required' if username.to_s.strip.empty?
  raise 'token is required' if token.to_s.strip.empty?
  raise 'url is required' if url.to_s.strip.empty?

  @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.



53
54
55
# File 'lib/firespring_dev_commands/jira.rb', line 53

def auth
  @auth
end

#clientObject

Returns the value of attribute client.



53
54
55
# File 'lib/firespring_dev_commands/jira.rb', line 53

def client
  @client
end

#tokenObject

Returns the value of attribute token.



53
54
55
# File 'lib/firespring_dev_commands/jira.rb', line 53

def token
  @token
end

#urlObject

Returns the value of attribute url.



53
54
55
# File 'lib/firespring_dev_commands/jira.rb', line 53

def url
  @url
end

#usernameObject

Returns the value of attribute username.



53
54
55
# File 'lib/firespring_dev_commands/jira.rb', line 53

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:



43
44
45
46
47
# File 'lib/firespring_dev_commands/jira.rb', line 43

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/firespring_dev_commands/jira.rb', line 81

def issues(jql, &)
  start_at = 0
  max_results = 100
  expand = self.class.config.expand

  # Query Jira and yield all issues it returns
  issues = @client.Issue.jql(jql, start_at:, max_results:, expand:)
  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:, expand:)
    issues.map { |data| Issue.new(data) }.each(&)
  end
end