Class: Jira::Core

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

Class Method Summary collapse

Class Method Details

.cli_pathString

Returns path to .jira-cli file.

Returns:

  • (String)

    path to .jira-cli file



71
72
73
# File 'lib/jira/core.rb', line 71

def cli_path
  @cli_path ||= root_path + "/.jira-cli"
end

.configObject



75
76
77
78
79
80
# File 'lib/jira/core.rb', line 75

def config
  @config ||= (
    raise InstallationException unless File.exist?(cli_path)
    IniFile.load(cli_path, comment: '#', encoding: 'UTF-8')
  )
end

Returns JIRA cookie.

Returns:

  • (Hash)

    JIRA cookie



36
37
38
39
# File 'lib/jira/core.rb', line 36

def cookie
  return {} if config[:cookie].nil? || config[:cookie].empty?
  { name: config[:cookie]['name'], value: config[:cookie]['value'] }
end

.passwordString

Returns JIRA password.

Returns:

  • (String)

    JIRA password



22
23
24
# File 'lib/jira/core.rb', line 22

def password
  @password ||= ENV['JIRA_PASSWORD'] || config[:global]['password']
end

.ticketString

Returns default ticket is the current branch.

Returns:

  • (String)

    default ticket is the current branch



44
45
46
# File 'lib/jira/core.rb', line 44

def ticket
  `git rev-parse --abbrev-ref HEAD 2>/dev/null`.strip
end

.ticket?(ticket, verbose = true) ⇒ Boolean

Determines whether or not the input ticket matches the expected JIRA ticketing syntax. Outputs a warning that the input ticket isn’t a valid ticket.

Parameters:

  • ticket (String)

    input ticket name

  • verbose (Boolean) (defaults to: true)

    verbose output of the ticket warning

Returns:

  • (Boolean)

    whether input string matches JIRA ticket syntax



58
59
60
61
62
63
64
# File 'lib/jira/core.rb', line 58

def ticket?(ticket, verbose=true)
  !!ticket.to_s[/^[a-zA-Z]+-[0-9]+$/] and return true
  if verbose
    puts "#{Jira::Format.ticket(ticket)} is not a valid JIRA ticket."
  end
  false
end

.tokenString

Returns JIRA token.

Returns:

  • (String)

    JIRA token



29
30
31
# File 'lib/jira/core.rb', line 29

def token
  @token ||= ENV['JIRA_TOKEN'] || config[:global]['token']
end

.urlString

Returns JIRA project endpoint.

Returns:

  • (String)

    JIRA project endpoint



8
9
10
# File 'lib/jira/core.rb', line 8

def url
  @url ||= ENV['JIRA_URL'] || config[:global]['url']
end

.usernameString

Returns JIRA username.

Returns:

  • (String)

    JIRA username



15
16
17
# File 'lib/jira/core.rb', line 15

def username
  @username ||= ENV['JIRA_USERNAME'] || config[:global]['username']
end