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, Error, 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 =
'3.1.0'.freeze

Class Method Summary collapse

Class Method Details

.auth_tokenObject



80
81
82
# File 'lib/git/semaphore.rb', line 80

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

.cache_dirObject



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

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



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

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



48
49
50
# File 'lib/git/semaphore.rb', line 48

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

.env_auth_tokenObject



68
69
70
# File 'lib/git/semaphore.rb', line 68

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

.from_json_cache(path, refresh = false) ⇒ Object



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

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



76
77
78
# File 'lib/git/semaphore.rb', line 76

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

.git_repoObject



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

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

.global_auth_tokenObject



72
73
74
# File 'lib/git/semaphore.rb', line 72

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

.home_dirObject



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

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

.versionObject



6
7
8
# File 'lib/git/semaphore/version.rb', line 6

def self.version
  "#{NAME} v#{VERSION}"
end