Skip to content

Instantly share code, notes, and snippets.

@pabloelizalde
Last active January 12, 2017 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pabloelizalde/c5fa9938a9e2980be8888016e19945af to your computer and use it in GitHub Desktop.
Save pabloelizalde/c5fa9938a9e2980be8888016e19945af to your computer and use it in GitHub Desktop.
CI source file for Buddybuild
require "danger/request_sources/github"
module Danger
# ### CI Setup
#
# You need to edit your `.buddybuild_postclone.sh` to include `bundle install` and `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`.
#
# However, you will need to find a way to add the environment vars: `BUDDYBUILD_PULL_REQUEST_ID`,
# you can do that following the custom build steps (http://docs.buddybuild.com/v6/docs/custom-prebuild-and-postbuild-steps#section-post-clone)
class BuddyBuildCI < CI
def self.validate_as_ci?(env)
env.key? "BUDDYBUILD_BUILD_NUMBER"
end
def self.validate_as_pr?(env)
return !env["BUDDYBUILD_PULL_REQUEST_ID"].to_s.empty?
end
def supported_request_sources
@supported_request_sources ||= [Danger::RequestSources::GitHub]
end
def initialize(env)
self.repo_url = GitRepo.new.origins # Buddybuild doesn't provide a repo url env variable :/
self.pull_request_id = env["BUDDYBUILD_PULL_REQUEST_ID"]
repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
self.repo_slug = repo_matches[2] unless repo_matches.nil?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment