Class: Git::Semaphore::Project
- Inherits:
-
Object
- Object
- Git::Semaphore::Project
- Defined in:
- lib/git/semaphore/project.rb
Class Method Summary collapse
-
.all ⇒ 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 ⇒ Object
-
#build_number ⇒ Object
build-related queries: default to latest one…
- #build_result ⇒ Object
- #build_url ⇒ Object
- #history ⇒ Object
- #information ⇒ Object
-
#initialize(full_name:, branch_name:, options:) ⇒ Project
constructor
A new instance of Project.
- #internals ⇒ Object
- #log ⇒ Object
-
#project_url ⇒ Object
direct links to semaphore.ci.
- #rebuild ⇒ Object
- #settings ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(full_name:, branch_name:, options:) ⇒ Project
Returns a new instance of Project.
27 28 29 30 31 32 33 34 |
# File 'lib/git/semaphore/project.rb', line 27 def initialize full_name:, branch_name:, options: @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 |
Class Method Details
.all ⇒ Object Also known as: projects
API related queries
106 107 108 |
# File 'lib/git/semaphore/project.rb', line 106 def self.all Git::Semaphore::API::Cache.projects(Git::Semaphore.auth_token) end |
.env_overrides ⇒ Object
3 4 5 |
# File 'lib/git/semaphore/project.rb', line 3 def self.env_overrides ENV.to_h.select { |key, _| key.start_with? 'SEMAPHORE_' } end |
.from_config(config) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/git/semaphore/project.rb', line 16 def self.from_config config self.new( full_name: config['SEMAPHORE_PROJECT_NAME'], branch_name: config['SEMAPHORE_BRANCH_NAME'], options: { commit_sha: config['SEMAPHORE_COMMIT_SHA'], build_number: config['SEMAPHORE_BUILD_NUMBER'], } ) end |
.from_repo(git_repo) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/git/semaphore/project.rb', line 7 def self.from_repo git_repo self.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
88 89 90 91 92 93 |
# File 'lib/git/semaphore/project.rb', line 88 def branch_url branch_hash = project_hash['branches'].find { |hash| hash['branch_name'] == @branch_name } branch_hash['branch_url'] end |
#branches ⇒ Object
114 115 116 |
# File 'lib/git/semaphore/project.rb', line 114 def branches Git::Semaphore::API::Cache.branches(project_hash_id, @auth_token) end |
#build_number ⇒ Object
build-related queries: default to latest one…
72 73 74 |
# File 'lib/git/semaphore/project.rb', line 72 def build_number @build_number ||= history['builds'].first['build_number'].to_s end |
#build_result ⇒ Object
76 77 78 |
# File 'lib/git/semaphore/project.rb', line 76 def build_result @build_result ||= history['builds'].first['result'] end |
#build_url ⇒ Object
95 96 97 98 99 100 |
# File 'lib/git/semaphore/project.rb', line 95 def build_url build_hash = history['builds'].find { |hash| hash['build_number'].to_s == @build_number } build_hash['build_url'] end |
#history ⇒ Object
122 123 124 |
# File 'lib/git/semaphore/project.rb', line 122 def history Git::Semaphore::API::Cache.history(project_hash_id, branch_id, @auth_token) end |
#information ⇒ Object
126 127 128 |
# File 'lib/git/semaphore/project.rb', line 126 def information Git::Semaphore::API::Cache.information(project_hash_id, branch_id, build_number, @auth_token,) end |
#internals ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/git/semaphore/project.rb', line 46 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 ⇒ Object
130 131 132 |
# File 'lib/git/semaphore/project.rb', line 130 def log Git::Semaphore::API::Cache.log(project_hash_id, branch_id, build_number, @auth_token,) end |
#project_url ⇒ Object
direct links to semaphore.ci
84 85 86 |
# File 'lib/git/semaphore/project.rb', line 84 def project_url project_hash['html_url'] end |
#rebuild ⇒ Object
134 135 136 |
# File 'lib/git/semaphore/project.rb', line 134 def rebuild Git::Semaphore::API.rebuild(project_hash_id, branch_id, @auth_token) end |
#settings ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/git/semaphore/project.rb', line 36 def settings { auth_token: @auth_token, project_name: @full_name, branch_name: @branch_name, commit_sha: @commit_sha, build_number: @build_number, } end |