lib/danger/ci_source/drone.rb in danger-5.0.3 vs lib/danger/ci_source/drone.rb in danger-5.1.0
- old
+ new
@@ -9,23 +9,35 @@
# your `.drone.yml`.
#
# ``` shell
# build:
# image: golang
- # commands:
- # - ...
- # - bundle exec danger
+ # commands:
+ # - ...
+ # - bundle exec danger
# ```
#
# ### Token Setup
#
- # As this is self-hosted, you will need to add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV. The alternative
- # is to pass in the token as a prefix to the command `DANGER_GITHUB_API_TOKEN="123" bundle exec danger`.
+ # As this is self-hosted, you will need to expose the `DANGER_GITHUB_API_TOKEN` as a secret to your
+ # builds:
#
+ # Drone secrets: http://readme.drone.io/usage/secret-guide/
+ # NOTE: This is a new syntax in DroneCI 0.6+
+ #
+ # ```
+ # build:
+ # image: golang
+ # secrets:
+ # - DANGER_GITHUB_API_TOKEN
+ # commands:
+ # - ...
+ # - bundle exec danger
+ # ```
class Drone < CI
def self.validates_as_ci?(env)
- env.key? "DRONE_REPO"
+ validates_as_ci_post_06?(env) or validates_as_ci_pre_06?(env)
end
def self.validates_as_pr?(env)
env["DRONE_PULL_REQUEST"].to_i > 0
end
@@ -33,11 +45,27 @@
def supported_request_sources
@supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]
end
def initialize(env)
- self.repo_slug = env["DRONE_REPO"]
+ if self.class.validates_as_ci_post_06?(env)
+ self.repo_slug = "#{env['DRONE_REPO_OWNER']}/#{env['DRONE_REPO_NAME']}"
+ self.repo_url = env["DRONE_REPO_LINK"] if self.class.validates_as_ci_post_06?(env)
+ elsif self.class.validates_as_ci_pre_06?(env)
+ self.repo_slug = env["DRONE_REPO"]
+ self.repo_url = GitRepo.new.origins
+ end
+
self.pull_request_id = env["DRONE_PULL_REQUEST"]
- self.repo_url = GitRepo.new.origins # Drone doesn't provide a repo url env variable :/
+ end
+
+ # Check if this build is valid for CI with drone 0.6 or later
+ def self.validates_as_ci_post_06?(env)
+ env.key? "DRONE_REPO_OWNER" and env.key? "DRONE_REPO_NAME"
+ end
+
+ # Checks if this build is valid for CI with drone 0.5 or earlier
+ def self.validates_as_ci_pre_06?(env)
+ env.key? "DRONE_REPO"
end
end
end