Class: Danger::Screwdriver

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

Overview

### CI Setup

Install dependencies and add a danger step to your screwdriver.yaml: “‘ yml jobs:

danger:
  requires: [~pr, ~commit]
  steps:
    - setup: bundle install --path vendor
    - danger: bundle exec danger
  secrets:
    - DANGER_GITHUB_API_TOKEN

“‘

### Token Setup

Add the ‘DANGER_GITHUB_API_TOKEN` to your pipeline env as a [build secret](docs.screwdriver.cd/user-guide/configuration/secrets)

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) ⇒ Screwdriver

Returns a new instance of Screwdriver.



39
40
41
42
43
44
45
# File 'lib/danger/ci_source/screwdriver.rb', line 39

def initialize(env)
  self.repo_slug = env["SCM_URL"].split(":").last.gsub(".git", "").split("#", 2).first
  self.repo_url = env["SCM_URL"].split("#", 2).first
  if env["SD_PULL_REQUEST"].to_i > 0
    self.pull_request_id = env["SD_PULL_REQUEST"]
  end
end

Class Method Details

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/danger/ci_source/screwdriver.rb', line 26

def self.validates_as_ci?(env)
  env.key? "SCREWDRIVER"
end

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.validates_as_pr?(env)
  exists = ["SD_PULL_REQUEST", "SCM_URL"].all? { |x| env[x] && !env[x].empty? }
  exists && env["SD_PULL_REQUEST"].to_i > 0
end

Instance Method Details

#supported_request_sourcesObject



35
36
37
# File 'lib/danger/ci_source/screwdriver.rb', line 35

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