Class: Danger::CodeBuild
- Inherits:
-
CI
- Object
- CI
- Danger::CodeBuild
show all
- Defined in:
- lib/danger/ci_source/code_build.rb
Overview
CI Setup
In CodeBuild, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_SOURCE_VERSION, CODEBUILD_SOURCE_REPO_URL and DANGER_GITHUB_API_TOKEN.
In CodeBuild with batch builds, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_WEBHOOK_TRIGGER, CODEBUILD_SOURCE_REPO_URL, CODEBUILD_BATCH_BUILD_IDENTIFIER and DANGER_GITHUB_API_TOKEN.
Token Setup
Add your DANGER_GITHUB_API_TOKEN to your project. Edit -> Environment -> Additional configuration -> Create a parameter
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) ⇒ CodeBuild
Returns a new instance of CodeBuild.
29
30
31
32
33
34
35
36
37
|
# File 'lib/danger/ci_source/code_build.rb', line 29
def initialize(env)
self.repo_slug = self.class.(env)
if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
self.pull_request_id = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")[1].to_i
else
self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
end
self.repo_url = self.class.(env)
end
|
Class Method Details
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/danger/ci_source/code_build.rb', line 53
def self.(env)
if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
return nil unless env.key? "CODEBUILD_WEBHOOK_TRIGGER"
return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
return nil unless env["CODEBUILD_WEBHOOK_TRIGGER"].split("/").length == 2
event_type, pr_number = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")
return nil unless event_type == "pr"
else
return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
_source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
end
github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
"#{github_repo_url}/pull/#{pr_number}"
end
|
39
40
41
42
43
44
45
|
# File 'lib/danger/ci_source/code_build.rb', line 39
def self.(env)
return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
gh_host = env["DANGER_GITHUB_HOST"] || "github.com"
env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}/(.*?)(\.git)?$}, '\1')
end
|
47
48
49
50
51
|
# File 'lib/danger/ci_source/code_build.rb', line 47
def self.(env)
return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
end
|
.validates_as_ci?(env) ⇒ Boolean
17
18
19
|
# File 'lib/danger/ci_source/code_build.rb', line 17
def self.validates_as_ci?(env)
env.key? "CODEBUILD_BUILD_ID"
end
|
.validates_as_pr?(env) ⇒ Boolean
21
22
23
|
# File 'lib/danger/ci_source/code_build.rb', line 21
def self.validates_as_pr?(env)
!!self.(env)
end
|
Instance Method Details
#supported_request_sources ⇒ Object
25
26
27
|
# File 'lib/danger/ci_source/code_build.rb', line 25
def supported_request_sources
@supported_request_sources ||= [Danger::RequestSources::GitHub]
end
|