Class: Git::Semaphore::Project
- Inherits:
-
Object
- Object
- Git::Semaphore::Project
- Defined in:
- lib/git/semaphore/project.rb
Instance Attribute Summary collapse
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
Class Method Summary collapse
-
.all(refresh = false) ⇒ Object
(also: projects)
API related queries.
- .env_overrides ⇒ Object
- .from_config(config) ⇒ Object
- .from_repo(git_repo) ⇒ Object
Instance Method Summary collapse
- #branch_url ⇒ Object
- #branches(refresh = false) ⇒ Object
- #browse ⇒ Object
-
#build_number ⇒ Object
build-related queries: default to latest one…
- #build_result ⇒ Object
- #build_url ⇒ Object
- #exist? ⇒ Boolean
- #history(refresh = false) ⇒ Object
- #information(refresh = false) ⇒ Object
-
#initialize(full_name, branch_name = nil, options = {}) ⇒ Project
constructor
A new instance of Project.
- #internals ⇒ Object
- #log(refresh = false) ⇒ Object
-
#project_url ⇒ Object
direct links to semaphore.ci.
- #rebuild ⇒ Object
- #settings ⇒ Object
- #status(refresh = false) ⇒ Object
Constructor Details
#initialize(full_name, branch_name = nil, options = {}) ⇒ Project
Returns a new instance of Project.
29 30 31 32 33 34 35 36 |
# File 'lib/git/semaphore/project.rb', line 29 def initialize(full_name, branch_name = nil, = {}) @auth_token = Git::Semaphore.auth_token @full_name = full_name @owner, @name = full_name&.split('/') @branch_name = branch_name || 'master' @commit_sha = [:commit_sha] @build_number = [:build_number] end |
Instance Attribute Details
#full_name ⇒ Object
Returns the value of attribute full_name.
27 28 29 |
# File 'lib/git/semaphore/project.rb', line 27 def full_name @full_name end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/git/semaphore/project.rb', line 27 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner.
27 28 29 |
# File 'lib/git/semaphore/project.rb', line 27 def owner @owner end |
Class Method Details
.all(refresh = false) ⇒ Object Also known as: projects
API related queries
112 113 114 |
# File 'lib/git/semaphore/project.rb', line 112 def self.all(refresh = false) Git::Semaphore::API::Cache.projects(refresh) end |
.env_overrides ⇒ Object
5 6 7 |
# 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) ⇒ Object
18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
9 10 11 12 13 14 15 16 |
# 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 |
Instance Method Details
#branch_url ⇒ Object
94 95 96 97 98 99 |
# 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) ⇒ Object
120 121 122 |
# File 'lib/git/semaphore/project.rb', line 120 def branches(refresh = false) Git::Semaphore::API::Cache.branches(project_hash_id, refresh) end |
#browse ⇒ Object
144 145 146 147 |
# File 'lib/git/semaphore/project.rb', line 144 def browse `open #{branch_url}` { url: branch_url } end |
#build_number ⇒ Object
build-related queries: default to latest one…
78 79 80 |
# File 'lib/git/semaphore/project.rb', line 78 def build_number @build_number ||= history['builds'].first['build_number'].to_s end |
#build_result ⇒ Object
82 83 84 |
# File 'lib/git/semaphore/project.rb', line 82 def build_result @build_result ||= history['builds'].first['result'] end |
#build_url ⇒ Object
101 102 103 104 105 106 |
# 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? ⇒ Boolean
38 39 40 |
# File 'lib/git/semaphore/project.rb', line 38 def exist? !project_hash.nil? end |
#history(refresh = false) ⇒ Object
128 129 130 |
# 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) ⇒ Object
132 133 134 |
# 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 ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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) ⇒ Object
136 137 138 |
# 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 ⇒ Object
direct links to semaphore.ci
90 91 92 |
# File 'lib/git/semaphore/project.rb', line 90 def project_url project_hash['html_url'] end |
#rebuild ⇒ Object
140 141 142 |
# File 'lib/git/semaphore/project.rb', line 140 def rebuild Git::Semaphore::API.rebuild(project_hash_id, branch_id) end |
#settings ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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) ⇒ Object
124 125 126 |
# File 'lib/git/semaphore/project.rb', line 124 def status(refresh = false) Git::Semaphore::API::Cache.status(project_hash_id, branch_id, refresh) end |