Class: CircleCi::Project

Inherits:
ApiProjectResource show all
Defined in:
lib/circleci/project.rb

Overview

Class for interacting with Projects

Constant Summary

Constants inherited from ApiProjectResource

ApiProjectResource::DEFAULT_VCS_TYPE, ApiProjectResource::VALID_VCS_TYPES

Instance Attribute Summary

Attributes inherited from ApiProjectResource

#vcs_type

Attributes inherited from ApiResource

#conf, #project, #username

Instance Method Summary collapse

Methods inherited from ApiProjectResource

#base_path

Methods inherited from ApiResource

default_config, #default_config

Constructor Details

#initialize(username = nil, project = nil, vcs_type = nil, conf = nil) ⇒ CircleCi::Project

Initialize a new Project API interaction

Parameters:

  • username (String) (defaults to: nil)
    • The vcs username or org name for project

  • project (String) (defaults to: nil)
    • The project name

  • vcs_type (String) (defaults to: nil)
    • The vcs type i.e. github or bitbucket

  • conf (CircleCi::Config) (defaults to: nil)
    • Optional config to use for request



17
18
19
# File 'lib/circleci/project.rb', line 17

def initialize(username = nil, project = nil, vcs_type = nil, conf = nil)
  super(username, project, vcs_type, nil, conf)
end

Instance Method Details

#add_envvar(envvar) ⇒ CircleCi::Response

Adds an envvar for a project

Parameters:

  • envvar (Hash)
    • ‘foo’, value: ‘bar’

Returns:



167
168
169
# File 'lib/circleci/project.rb', line 167

def add_envvar(envvar)
  CircleCi.request(conf, "#{base_path}/envvar").post(envvar)
end

#buildCircleCi::Response

Build the latest master push for this project

Returns:



26
27
28
# File 'lib/circleci/project.rb', line 26

def build
  CircleCi.request(conf, base_path).post
end

#build_branch(branch, params = {}, body = {}) ⇒ CircleCi::Response

Build the latest push for this branch of a specific project

Parameters:

  • branch (String)
    • Name of branch

  • params (Hash) (defaults to: {})
    • Optional params to send for building

  • body (Hash) (defaults to: {})
    • Optional post body with build parameters

Returns:



38
39
40
# File 'lib/circleci/project.rb', line 38

def build_branch(branch, params = {}, body = {})
  CircleCi.request(conf, "#{base_path}/tree/#{branch}", params).post(body)
end

#build_ssh_key(build, key, hostname) ⇒ CircleCi::Response

Add a ssh key to a build

Parameters:

  • build (String)
    • Build number

  • key (String)
    • The ssh private key

  • hostname (String)
    • The hostname identified by the key

Returns:



50
51
52
53
# File 'lib/circleci/project.rb', line 50

def build_ssh_key(build, key, hostname)
  body = { hostname: hostname, private_key: key }
  CircleCi.request(conf, "#{base_path}/#{build}/ssh-users").post(body)
end

#clear_cacheCircleCi::Response

Clear the build cache for a specific project

Returns:



60
61
62
# File 'lib/circleci/project.rb', line 60

def clear_cache
  CircleCi.request(conf, "#{base_path}/build-cache").delete
end

#delete_checkout_key(fingerprint) ⇒ CircleCi::Response

Delete a checkout key for a project

Parameters:

  • fingerprint (String)
    • Fingerprint of a checkout key

Returns:



70
71
72
# File 'lib/circleci/project.rb', line 70

def delete_checkout_key(fingerprint)
  CircleCi.request(conf, "#{base_path}/checkout-key/#{fingerprint}").delete
end

#delete_envvar(envvar) ⇒ CircleCi::Response

Deletes an envvar for a project

Parameters:

  • envvar (String)
    • ‘TESTENV’

Returns:



177
178
179
# File 'lib/circleci/project.rb', line 177

def delete_envvar(envvar)
  CircleCi.request(conf, "#{base_path}/envvar/#{envvar}").delete
end

#enableCircleCi::Response

Enable a project in CircleCI. Causes a CircleCI SSH key to be added to the GitHub. Requires admin privilege to the repository.

Returns:



80
81
82
# File 'lib/circleci/project.rb', line 80

def enable
  CircleCi.request(conf, "#{base_path}/enable").post
end

#envvarCircleCi::Response

Get the project envvars

Returns:



89
90
91
# File 'lib/circleci/project.rb', line 89

def envvar
  CircleCi.request(conf, "#{base_path}/envvar").get
end

#followCircleCi::Response

Follow the project

Returns:



98
99
100
# File 'lib/circleci/project.rb', line 98

def follow
  CircleCi.request(conf, "#{base_path}/follow").post
end

#get_checkout_key(fingerprint) ⇒ CircleCi::Response

Get a checkout key for a project

Parameters:

  • fingerprint (String)
    • Fingerprint of a checkout key

Returns:



108
109
110
# File 'lib/circleci/project.rb', line 108

def get_checkout_key(fingerprint)
  CircleCi.request(conf, "#{base_path}/checkout-key/#{fingerprint}").get
end

#list_checkout_keysCircleCi::Response

Get a list of checkout keys for project

Returns:



117
118
119
# File 'lib/circleci/project.rb', line 117

def list_checkout_keys
  CircleCi.request(conf, "#{base_path}/checkout-key").get
end

#new_checkout_key(type) ⇒ CircleCi::Response

Create a checkout key for a project

Parameters:

  • type (String)
    • The type of key to create. Can be ‘deploy-key’ or ‘github-user-key’.

Returns:



127
128
129
# File 'lib/circleci/project.rb', line 127

def new_checkout_key(type)
  CircleCi.request(conf, "#{base_path}/checkout-key").post(type: type)
end

#recent_builds(params = {}) ⇒ CircleCi::Response

Get all recent builds for a specific project

Parameters:

  • params (Hash) (defaults to: {})
    • Parameters for builds (limit, offset, filter)

Returns:



137
138
139
# File 'lib/circleci/project.rb', line 137

def recent_builds(params = {})
  CircleCi.request(conf, base_path, params).get
end

#recent_builds_branch(branch, params = {}) ⇒ CircleCi::Response

Get all recent builds for a specific branch of a project

Parameters:

  • branch (String)
    • Name of branch

  • params (Hash) (defaults to: {})
    • Parameters for builds (limit, offset, filter)

Returns:



148
149
150
# File 'lib/circleci/project.rb', line 148

def recent_builds_branch(branch, params = {})
  CircleCi.request(conf, "#{base_path}/tree/#{branch}", params).get
end

#settingsCircleCi::Response

Get the project configuration

Returns:



157
158
159
# File 'lib/circleci/project.rb', line 157

def settings
  CircleCi.request(conf, "#{base_path}/settings").get
end

#ssh_key(key, hostname) ⇒ CircleCi::Response

Add a ssh key to a project

Parameters:

  • key (String)
    • The ssh private key

  • hostname (String)
    • The hostname identified by the key

Returns:



188
189
190
191
# File 'lib/circleci/project.rb', line 188

def ssh_key(key, hostname)
  body = { hostname: hostname, private_key: key }
  CircleCi.request(conf, "#{base_path}/ssh-key").post(body)
end

#unfollowCircleCi::Response

Unfollow the project

Returns:



198
199
200
# File 'lib/circleci/project.rb', line 198

def unfollow
  CircleCi.request(conf, "#{base_path}/unfollow").post
end