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/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, 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



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

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

#auth ⇒ Object

Returns the value of attribute auth.



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

def auth
  @auth
end

#client ⇒ Object

Returns the value of attribute client.



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

def client
  @client
end

#token ⇒ Object

Returns the value of attribute token.



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

def token
  @token
end

#url ⇒ Object

Returns the value of attribute url.



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

def url
  @url
end

#username ⇒ Object

Returns the value of attribute username.



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

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:



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

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



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

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