Class: Git::Semaphore::App

Inherits:
Object
  • Object
show all
Defined in:
lib/git-semaphore/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(working_dir, config = ENV) ⇒ 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_nameObject



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

#commitObject

Returns the value of attribute commit.



10
11
12
# File 'lib/git-semaphore/app.rb', line 10

def commit
  @commit
end

#env_auth_tokenObject

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_tokenObject

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_nameObject



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_dirObject

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_tokenObject



42
43
44
# File 'lib/git-semaphore/app.rb', line 42

def auth_token
  git_auth_token || env_auth_token
end

#branchesObject



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_statusObject



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_tokenObject



24
25
26
# File 'lib/git-semaphore/app.rb', line 24

def git_auth_token
  git_repo.config['semaphore.authtoken']
end

#git_project_tokenObject



28
29
30
# File 'lib/git-semaphore/app.rb', line 28

def git_project_token
  git_repo.config['semaphore.projecttoken']
end

#git_repoObject



32
33
34
# File 'lib/git-semaphore/app.rb', line 32

def git_repo
  @git_repo ||= Grit::Repo.new(working_dir)
end

#project_tokenObject



46
47
48
# File 'lib/git-semaphore/app.rb', line 46

def project_token
  git_project_token || env_project_token
end

#projectsObject



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

#rebuild_last_revisionObject



88
89
90
91
# File 'lib/git-semaphore/app.rb', line 88

def rebuild_last_revision
  uri = Git::Semaphore::Api.last_revision_uri(project_hash_id, branch_id, auth_token)
  Git::Semaphore::Api.get_response(uri, :post).body
end

#statusObject



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

#validateObject



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

def validate
  '' != branch_name.to_s.gsub(/\s+/, '')
rescue
  false
end