Module: Git::Semaphore

Defined in:
lib/git/semaphore.rb,
lib/git/semaphore/api.rb,
lib/git/semaphore/gemspec.rb,
lib/git/semaphore/project.rb,
lib/git/semaphore/version.rb,
lib/git/semaphore/api_cache.rb,
lib/git/semaphore/api_enrich.rb

Defined Under Namespace

Classes: API, Project

Constant Summary collapse

PIM =
<<~"PIM".freeze

  The only required setting for \033[1mgit semaphore\33[0m is:

  \tgit config --global --add \033[1msemaphore.authtoken\033[0m <your_semaphore_auth_token>

  Thanks for using \033[1mgit semaphore\033[0m ... the ultimate Semaphore utility for git!

PIM
NAME =
'git-semaphore'.freeze
VERSION =
'2.4.1'.freeze

Class Method Summary collapse

Class Method Details

.auth_tokenObject



74
75
76
# File 'lib/git/semaphore.rb', line 74

def self.auth_token
  git_auth_token || global_auth_token || env_auth_token
end

.cache_dirObject



28
29
30
31
32
33
34
# File 'lib/git/semaphore.rb', line 28

def self.cache_dir
  @cache_dir ||= begin
    File.join(home_dir, '.git', 'semaphore').tap do |cache_dir|
      FileUtils.mkdir_p(cache_dir)
    end
  end
end

.cache_dir_for(identifier) ⇒ Object



36
37
38
39
40
# File 'lib/git/semaphore.rb', line 36

def self.cache_dir_for(identifier)
  File.join(cache_dir, identifier).tap do |cache_dir|
    FileUtils.mkdir_p(cache_dir)
  end
end

.empty_cache_dirObject



42
43
44
# File 'lib/git/semaphore.rb', line 42

def self.empty_cache_dir
  FileUtils.rm_r Dir.glob(File.join(cache_dir, '*'))
end

.env_auth_tokenObject



62
63
64
# File 'lib/git/semaphore.rb', line 62

def self.env_auth_token
  @env_auth_token ||= ENV['SEMAPHORE_AUTH_TOKEN']
end

.from_json_cache(path, refresh = false) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/git/semaphore.rb', line 46

def self.from_json_cache(path, refresh = false)
  if !refresh && File.exist?(path)
    JSON.parse(File.read(path))
  else
    yield.tap do |content|
      File.open(path, 'w') { |file| file.write content.to_json }
    end
  end
end

.git_auth_tokenObject



70
71
72
# File 'lib/git/semaphore.rb', line 70

def self.git_auth_token
  git_repo&.config&.get('semaphore.authtoken')
end

.git_repoObject



56
57
58
59
60
# File 'lib/git/semaphore.rb', line 56

def self.git_repo
  Rugged::Repository.new(Dir.pwd)
rescue Rugged::RepositoryError
  nil
end

.global_auth_tokenObject



66
67
68
# File 'lib/git/semaphore.rb', line 66

def self.global_auth_token
  Rugged::Config.global['semaphore.authtoken']
end

.home_dirObject



22
23
24
25
26
# File 'lib/git/semaphore.rb', line 22

def self.home_dir
  @home_dir ||= begin
    ENV['HOME'] || File.expand_path("~#{Etc.getlogin}")
  end
end