Class: Danger::Codeship

Inherits:
CI
  • Object
show all
Defined in:
lib/danger/ci_source/codeship.rb

Overview

### CI Setup

In Codeship, go to your “Project Settings”, then add ‘bundle exec danger` as a test step inside one of your pipelines.

### Token Setup

Add your ‘DANGER_GITHUB_API_TOKEN` to “Environment” section in “Project Settings”.

Instance Attribute Summary

Attributes inherited from CI

#pull_request_id, #repo_slug, #repo_url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CI

available_ci_sources, inherited, #supports?

Constructor Details

#initialize(env) ⇒ Codeship

Returns a new instance of Codeship.



38
39
40
41
42
# File 'lib/danger/ci_source/codeship.rb', line 38

def initialize(env)
  self.repo_slug = env["CI_REPO_NAME"]
  self.pull_request_id = self.class.pr_from_env(env)
  self.repo_url = GitRepo.new.origins
end

Class Method Details

.owner_for_github(env) ⇒ Object



25
26
27
# File 'lib/danger/ci_source/codeship.rb', line 25

def self.owner_for_github(env)
  env["CI_REPO_NAME"].split("/").first
end

.pr_from_env(env) ⇒ Object



30
31
32
# File 'lib/danger/ci_source/codeship.rb', line 30

def self.pr_from_env(env)
  Danger::RequestSources::GitHub.new(nil, env).get_pr_from_branch(env["CI_REPO_NAME"], env["CI_BRANCH"], owner_for_github(env))
end

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/danger/ci_source/codeship.rb', line 15

def self.validates_as_ci?(env)
  env["CI_NAME"] == "codeship"
end

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/danger/ci_source/codeship.rb', line 19

def self.validates_as_pr?(env)
  return false unless env["CI_BRANCH"] && !env["CI_BRANCH"].empty?

  !pr_from_env(env).nil?
end

Instance Method Details

#supported_request_sourcesObject



34
35
36
# File 'lib/danger/ci_source/codeship.rb', line 34

def supported_request_sources
  @supported_request_sources ||= [Danger::RequestSources::GitHub]
end