Class: Git::Semaphore::App
- Inherits:
-
Object
- Object
- Git::Semaphore::App
- Defined in:
- lib/git-semaphore/app.rb
Instance Attribute Summary collapse
- #branch_name ⇒ Object
-
#commit ⇒ Object
Returns the value of attribute commit.
-
#env_auth_token ⇒ Object
Returns the value of attribute env_auth_token.
-
#env_project_token ⇒ Object
Returns the value of attribute env_project_token.
- #project_name ⇒ Object
-
#working_dir ⇒ Object
Returns the value of attribute working_dir.
Instance Method Summary collapse
- #auth_token ⇒ Object
- #branches ⇒ Object
- #commit_status ⇒ Object
- #git_auth_token ⇒ Object
- #git_project_token ⇒ Object
- #git_repo ⇒ Object
-
#initialize(working_dir, config = ENV) ⇒ App
constructor
A new instance of App.
- #project_token ⇒ Object
- #projects ⇒ Object
- #status ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(working_dir, config = ENV) ⇒ App
Returns a new instance of App.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/git-semaphore/app.rb', line 13 def initialize working_dir, config = ENV self.working_dir = working_dir self.project_name = config['PROJECT'] self.branch_name = config['BRANCH'] self.commit = config['COMMIT'] self.env_auth_token = config['SEMAPHORE_AUTH_TOKEN'] self.env_project_token = config['SEMAPHORE_PROJECT_TOKEN'] end |
Instance Attribute Details
#branch_name ⇒ Object
55 56 57 58 |
# File 'lib/git-semaphore/app.rb', line 55 def branch_name return @branch_name unless @branch_name.nil? git_repo.head.name end |
#commit ⇒ Object
Returns the value of attribute commit.
10 11 12 |
# File 'lib/git-semaphore/app.rb', line 10 def commit @commit end |
#env_auth_token ⇒ Object
Returns the value of attribute env_auth_token.
5 6 7 |
# File 'lib/git-semaphore/app.rb', line 5 def env_auth_token @env_auth_token end |
#env_project_token ⇒ Object
Returns the value of attribute env_project_token.
6 7 8 |
# File 'lib/git-semaphore/app.rb', line 6 def env_project_token @env_project_token end |
#project_name ⇒ Object
50 51 52 53 |
# File 'lib/git-semaphore/app.rb', line 50 def project_name return @project_name unless @project_name.nil? File.basename working_dir end |
#working_dir ⇒ Object
Returns the value of attribute working_dir.
8 9 10 |
# File 'lib/git-semaphore/app.rb', line 8 def working_dir @working_dir end |
Instance Method Details
#auth_token ⇒ Object
42 43 44 |
# File 'lib/git-semaphore/app.rb', line 42 def auth_token git_auth_token || env_auth_token end |
#branches ⇒ Object
67 68 69 70 71 72 |
# File 'lib/git-semaphore/app.rb', line 67 def branches @branches ||= begin uri = Git::Semaphore::Api.branches_uri(project_hash_id, auth_token) Git::Semaphore::Api.get_response(uri).body end end |
#commit_status ⇒ Object
81 82 83 84 85 86 |
# File 'lib/git-semaphore/app.rb', line 81 def commit_status uri = Git::Semaphore::Api.history_uri(project_hash_id, branch_id, auth_token) j = Git::Semaphore::Api.get_response(uri).body builds = JSON.parse(j)['builds'] build = builds.detect { |b| b['commit']['id'] == commit } end |
#git_auth_token ⇒ Object
24 25 26 |
# File 'lib/git-semaphore/app.rb', line 24 def git_auth_token git_repo.config['semaphore.authtoken'] end |
#git_project_token ⇒ Object
28 29 30 |
# File 'lib/git-semaphore/app.rb', line 28 def git_project_token git_repo.config['semaphore.projecttoken'] end |
#git_repo ⇒ Object
32 33 34 |
# File 'lib/git-semaphore/app.rb', line 32 def git_repo @git_repo ||= Grit::Repo.new(working_dir) end |
#project_token ⇒ Object
46 47 48 |
# File 'lib/git-semaphore/app.rb', line 46 def project_token git_project_token || env_project_token end |
#projects ⇒ Object
60 61 62 63 64 65 |
# File 'lib/git-semaphore/app.rb', line 60 def projects @projects ||= begin uri = Git::Semaphore::Api.projects_uri(auth_token) Git::Semaphore::Api.get_response(uri).body end end |
#status ⇒ Object
74 75 76 77 78 79 |
# File 'lib/git-semaphore/app.rb', line 74 def status @status ||= begin uri = Git::Semaphore::Api.status_uri(project_hash_id, branch_id, auth_token) Git::Semaphore::Api.get_response(uri).body end end |
#validate ⇒ Object
36 37 38 39 40 |
# File 'lib/git-semaphore/app.rb', line 36 def validate '' != branch_name.to_s.gsub(/\s+/, '') rescue false end |