Class: Danger::CustomCIWithGithub

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

Overview

### CI Setup

Custom CI with GitHub

This CI source is for custom, most likely internal, CI systems that are use GitHub as source control. An example could be argo-workflows or tekton hosted in your own Kubernetes cluster.

The following environment variables are required:

  • ‘CUSTOM_CI_WITH_GITHUB` - Set to any value to indicate that this is a custom CI with GitHub

### Token Setup

#### GitHub As you own the setup, it’s up to you to add the environment variable for the ‘DANGER_GITHUB_API_TOKEN`.

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

Returns a new instance of CustomCIWithGithub.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/danger/ci_source/custom_ci_with_github.rb', line 35

def initialize(env)
  super

  self.repo_slug = env["GITHUB_REPOSITORY"]
  pull_request_event = JSON.parse(File.read(env["GITHUB_EVENT_PATH"]))
  self.pull_request_id = pull_request_event["number"]
  self.repo_url = pull_request_event["repository"]["clone_url"]

  # if environment variable DANGER_GITHUB_API_TOKEN is not set, use env GITHUB_TOKEN
  if (env.key? "CUSTOM_CI_WITH_GITHUB") && (!env.key? "DANGER_GITHUB_API_TOKEN")
    env["DANGER_GITHUB_API_TOKEN"] = env["GITHUB_TOKEN"]
  end
end

Class Method Details

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/danger/ci_source/custom_ci_with_github.rb', line 22

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

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.validates_as_pr?(env)
  value = env["GITHUB_EVENT_NAME"]
  ["pull_request", "pull_request_target"].include?(value)
end

Instance Method Details

#supported_request_sourcesObject



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

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