Class: Capistrano::Github::API

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/github/api.rb

Defined Under Namespace

Classes: Deployment

Constant Summary collapse

REPO_FORMAT =
/[email protected]:([\S]*)\/([\S]*).git/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_url, token) ⇒ API

Returns a new instance of API.

Raises:

  • (MissingAccessToken)


18
19
20
21
22
# File 'lib/capistrano/github/api.rb', line 18

def initialize(repo_url, token)
  raise MissingAccessToken unless token
  @client = Octokit::Client.new(access_token: token)
  @repo = parse_repo_url(repo_url)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



16
17
18
# File 'lib/capistrano/github/api.rb', line 16

def client
  @client
end

Instance Method Details

#create_deployment(branch, options = {}) ⇒ Object



24
25
26
# File 'lib/capistrano/github/api.rb', line 24

def create_deployment(branch, options = {})
  @client.create_deployment(@repo, branch, options).id
end

#create_deployment_status(id, state) ⇒ Object



28
29
30
# File 'lib/capistrano/github/api.rb', line 28

def create_deployment_status(id, state)
  @client.create_deployment_status(deployment_url(id), state)
end

#deployments(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/capistrano/github/api.rb', line 32

def deployments(options = {})
  @client.deployments(@repo, options).map do |d|
    Deployment.new.tap do |dep|
      dep.created_at = d.created_at
      dep.sha = d.sha
      dep.ref = d.ref
      dep. = d.creator.
      dep.payload = d.payload
      dep.id = d.id
      dep.environment = d.environment

      dep.statuses = deployment_statuses(d.id)
    end
  end
end