class Git::Semaphore::Project
Attributes
full_name[RW]
name[RW]
owner[RW]
Public Class Methods
all(refresh = false)
click to toggle source
API
related queries
# File lib/git/semaphore/project.rb, line 112 def self.all(refresh = false) Git::Semaphore::API::Cache.projects(refresh) end
Also aliased as: projects
env_overrides()
click to toggle source
# File lib/git/semaphore/project.rb, line 5 def self.env_overrides ENV.to_h.select { |key, _| key.start_with? 'SEMAPHORE_' } end
from_config(config)
click to toggle source
# File lib/git/semaphore/project.rb, line 18 def self.from_config(config) new( config['SEMAPHORE_PROJECT_NAME'], config['SEMAPHORE_BRANCH_NAME'], commit_sha: config['SEMAPHORE_COMMIT_SHA'], build_number: config['SEMAPHORE_BUILD_NUMBER'], ) end
from_repo(git_repo)
click to toggle source
# File lib/git/semaphore/project.rb, line 9 def self.from_repo(git_repo) from_config({ 'SEMAPHORE_PROJECT_NAME' => git_repo.full_name, 'SEMAPHORE_BRANCH_NAME' => git_repo.head.name.split('/').last, 'SEMAPHORE_COMMIT_SHA' => git_repo.head.target.oid, 'SEMAPHORE_BUILD_NUMBER' => nil }.merge(env_overrides)) end
new(full_name, branch_name = nil, options = {})
click to toggle source
# File lib/git/semaphore/project.rb, line 29 def initialize(full_name, branch_name = nil, options = {}) @auth_token = Git::Semaphore.auth_token @full_name = full_name @owner, @name = full_name&.split('/') @branch_name = branch_name || 'master' @commit_sha = options[:commit_sha] @build_number = options[:build_number] end
Public Instance Methods
branch_url()
click to toggle source
# File lib/git/semaphore/project.rb, line 94 def branch_url branch_hash = project_hash['branches'].find { |hash| hash['branch_name'] == @branch_name } branch_hash['branch_url'] end
branches(refresh = false)
click to toggle source
# File lib/git/semaphore/project.rb, line 120 def branches(refresh = false) Git::Semaphore::API::Cache.branches(project_hash_id, refresh) end
browse()
click to toggle source
# File lib/git/semaphore/project.rb, line 144 def browse `open #{branch_url}` { url: branch_url } end
build_number()
click to toggle source
build-related queries: default to latest oneā¦
# File lib/git/semaphore/project.rb, line 78 def build_number @build_number ||= history['builds'].first['build_number'].to_s end
build_result()
click to toggle source
# File lib/git/semaphore/project.rb, line 82 def build_result @build_result ||= history['builds'].first['result'] end
build_url()
click to toggle source
# File lib/git/semaphore/project.rb, line 101 def build_url build_hash = history['builds'].find { |hash| hash['build_number'].to_s == @build_number } build_hash['build_url'] end
exist?()
click to toggle source
# File lib/git/semaphore/project.rb, line 38 def exist? !project_hash.nil? end
history(refresh = false)
click to toggle source
# File lib/git/semaphore/project.rb, line 128 def history(refresh = false) Git::Semaphore::API::Cache.history(project_hash_id, branch_id, refresh) end
information(refresh = false)
click to toggle source
# File lib/git/semaphore/project.rb, line 132 def information(refresh = false) Git::Semaphore::API::Cache.information(project_hash_id, branch_id, build_number, refresh) end
internals()
click to toggle source
# File lib/git/semaphore/project.rb, line 52 def internals settings.merge( project: { owner: @owner, name: @name, full_name: @full_name, hash_id: project_hash_id, url: project_url, }, branch: { name: @branch_name, id: branch_id, url: branch_url, }, build: { number: build_number, result: build_result, url: build_url, }, ) end
log(refresh = false)
click to toggle source
# File lib/git/semaphore/project.rb, line 136 def log(refresh = false) Git::Semaphore::API::Cache.log(project_hash_id, branch_id, build_number, refresh) end
project_url()
click to toggle source
direct links to semaphore.ci
# File lib/git/semaphore/project.rb, line 90 def project_url project_hash['html_url'] end
rebuild()
click to toggle source
# File lib/git/semaphore/project.rb, line 140 def rebuild Git::Semaphore::API.rebuild(project_hash_id, branch_id) end
settings()
click to toggle source
# File lib/git/semaphore/project.rb, line 42 def settings { auth_token: @auth_token, project_name: @full_name, branch_name: @branch_name, commit_sha: @commit_sha, build_number: @build_number, } end
status(refresh = false)
click to toggle source
# File lib/git/semaphore/project.rb, line 124 def status(refresh = false) Git::Semaphore::API::Cache.status(project_hash_id, branch_id, refresh) end
Private Instance Methods
branch_hash()
click to toggle source
# File lib/git/semaphore/project.rb, line 175 def branch_hash branch_hash_for(@branch_name) end
branch_hash_for(branch_name)
click to toggle source
# File lib/git/semaphore/project.rb, line 169 def branch_hash_for(branch_name) branches.find { |branch_hash| branch_hash['name'] == branch_name } end
branch_id()
click to toggle source
# File lib/git/semaphore/project.rb, line 183 def branch_id branch_id_for(@branch_name) end
branch_id_for(branch_name)
click to toggle source
# File lib/git/semaphore/project.rb, line 179 def branch_id_for(branch_name) branch_hash_for(branch_name)['id'].to_s end
project_hash()
click to toggle source
# File lib/git/semaphore/project.rb, line 157 def project_hash project_hash_for(@owner, @name) end
project_hash_for(owner, name)
click to toggle source
# File lib/git/semaphore/project.rb, line 151 def project_hash_for(owner, name) self.class.projects.find { |project_hash| project_hash['owner'] == owner && project_hash['name'] == name } end
project_hash_id()
click to toggle source
# File lib/git/semaphore/project.rb, line 165 def project_hash_id project_hash_id_for(@owner, @name) end
project_hash_id_for(owner, name)
click to toggle source
# File lib/git/semaphore/project.rb, line 161 def project_hash_id_for(owner, name) project_hash_for(owner, name)['hash_id'] end