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.
27
28
29
30
31
32
33
34
35
|
# File 'lib/danger/ci_source/code_build.rb', line 27
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/danger/ci_source/code_build.rb', line 51
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
|
37
38
39
40
41
42
43
|
# File 'lib/danger/ci_source/code_build.rb', line 37
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
|
45
46
47
48
49
|
# File 'lib/danger/ci_source/code_build.rb', line 45
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
15
16
17
|
# File 'lib/danger/ci_source/code_build.rb', line 15
def self.validates_as_ci?(env)
env.key? "CODEBUILD_BUILD_ID"
end
|
.validates_as_pr?(env) ⇒ Boolean
19
20
21
|
# File 'lib/danger/ci_source/code_build.rb', line 19
def self.validates_as_pr?(env)
!!self.(env)
end
|
Instance Method Details
#supported_request_sources ⇒ Object
23
24
25
|
# File 'lib/danger/ci_source/code_build.rb', line 23
def supported_request_sources
@supported_request_sources ||= [Danger::RequestSources::GitHub]
end
|