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



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

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:



165
166
167
# File 'lib/circleci/project.rb', line 165

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

#buildCircleCi::Response

Build the latest master push for this project

Returns:



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

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:



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

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:



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

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:



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

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:



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

def delete_checkout_key(fingerprint)
  CircleCi.request(conf, "#{base_path}/checkout-key/#{fingerprint}").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:



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

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

#envvarCircleCi::Response

Get the project envvars

Returns:



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

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

#followCircleCi::Response

Follow the project

Returns:



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

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:



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

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:



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

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:



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

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:



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

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

#recent_builds_branch(branch) ⇒ CircleCi::Response

Get all recent builds for a specific branch of a project

Parameters:

  • branch (String)
    • Name of branch

Returns:



146
147
148
# File 'lib/circleci/project.rb', line 146

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

#settingsCircleCi::Response

Get the project configuration

Returns:



155
156
157
# File 'lib/circleci/project.rb', line 155

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:



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

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:



186
187
188
# File 'lib/circleci/project.rb', line 186

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