Class: Gitjira::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/gitjira/setup.rb

Class Method Summary collapse

Class Method Details

.init(force = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitjira/setup.rb', line 4

def self.init(force = false)
  if self.setup? and not force
    STDERR.puts "Repository is configured. Overwrite with:"
    STDERR.puts "\t$ git-jira init -f # or git-jira init --force."
    return 1
  end
  host = username = password = projectkey= nil

  host = ask("JIRA host (e.g. https://jira.example.org): ")
  host = "#{host}/" if not host.empty? and not host.end_with?("/")

  username = ask("Your JIRA username                       : ")
  password = ask("Your JIRA password                       : "){ |q| q.echo = "*" }
  base64 = Base64.strict_encode64("#{username}:#{password}")
  username = password = nil

  projectkey = ask("Related JIRA project key (e.g. PROJ)     : ")

  if not host.empty? and not projectkey.empty?
    `git config --local gitjira.host #{host}`
    `git config --local gitjira.credentials #{base64.to_s}`
    `git config --local gitjira.projectkey #{projectkey}`
    return 0
  else
    STDERR.puts "[ERROR] Please fill out all needed fields."
    return 1
  end

end

.setup?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/gitjira/setup.rb', line 34

def self.setup?
  `git config --local --get gitjira.host`.empty? ? false : true
end