Class: FastCI::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_ci/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fast_ci/configuration.rb', line 8

def initialize
  # Settings defaults
  self.run_key = nil
  self.build_id = guess_build_id
  self.commit = guess_commit
  self.commit_msg = `git log -1 --pretty=%B`.chomp
  self.branch = guess_branch
  self.api_url = ENV["FAST_CI_API_URL"] || "apx.fast.ci"
  self.secret_key = ENV.fetch("FAST_CI_SECRET_KEY")
  self.author = guess_author
  self.fastci_main_url = ENV.fetch('FASTCI_MAIN_URL', 'https://events.ruby.ci')
  self.fastci_api_url = ENV.fetch('FASTCI_API_RB_URL', 'https://ruby.fast.ci')
  self.orig_build_id = ENV['FSCI_ORIG_BUILD_ID']
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def api_url
  @api_url
end

#authorObject

Returns the value of attribute author.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def author
  @author
end

#branchObject

Returns the value of attribute branch.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def branch
  @branch
end

#build_idObject

Returns the value of attribute build_id.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def build_id
  @build_id
end

#commitObject

Returns the value of attribute commit.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def commit
  @commit
end

#commit_msgObject

Returns the value of attribute commit_msg.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def commit_msg
  @commit_msg
end

#fastci_api_urlObject

Returns the value of attribute fastci_api_url.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def fastci_api_url
  @fastci_api_url
end

#fastci_main_urlObject

Returns the value of attribute fastci_main_url.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def fastci_main_url
  @fastci_main_url
end

#orig_build_idObject

Returns the value of attribute orig_build_id.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def orig_build_id
  @orig_build_id
end

#run_keyObject

Returns the value of attribute run_key.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def run_key
  @run_key
end

#secret_keyObject

Returns the value of attribute secret_key.



5
6
7
# File 'lib/fast_ci/configuration.rb', line 5

def secret_key
  @secret_key
end

Instance Method Details

#guess_authorObject



31
32
33
34
35
36
37
38
# File 'lib/fast_ci/configuration.rb', line 31

def guess_author
  author_Line = `git show | grep Author:`
  name, email = author_Line.scan(/Author: (.*) <(.*)>/).first
  {
    name: name,
    email: email
  }
end

#guess_branchObject



54
55
56
57
58
59
# File 'lib/fast_ci/configuration.rb', line 54

def guess_branch
  %w[FSCI_BRANCH _BRANCH _REF].find do |keyword|
    key = ENV.keys.find { |k| k[keyword] }
    break ENV[key] if key && ENV[key]
  end || `git rev-parse --abbrev-ref HEAD`.chomp
end

#guess_build_idObject



40
41
42
43
44
45
# File 'lib/fast_ci/configuration.rb', line 40

def guess_build_id
  %w[FSCI_BUILD_ID GITHUB_RUN_ID BUILD_ID CIRCLE_BUILD_NUM].find do |keyword|
    key = ENV.keys.find { |k| k[keyword] }
    break ENV[key] if key && ENV[key]
  end || guess_commit
end

#guess_commitObject



47
48
49
50
51
52
# File 'lib/fast_ci/configuration.rb', line 47

def guess_commit
  %w[FSCI_COMMIT _COMMIT _SHA1 _SHA].find do |keyword|
    key = ENV.keys.find { |k| k[keyword] }
    break ENV[key] if key && ENV[key]
  end || `git rev-parse HEAD`.chomp
end

#resetObject



23
24
25
# File 'lib/fast_ci/configuration.rb', line 23

def reset
  initialize
end