Class: Danger::BitbucketPipelines

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

Overview

CI Setup

Install dependencies and add a danger step to your bitbucket-pipelines.yml.

  script:
    - bundle exec danger --verbose

Token Setup

For username and password, you need to set.

  • DANGER_BITBUCKETCLOUD_USERNAME = The username for the account used to comment, as shown on https://bitbucket.org/account/
  • DANGER_BITBUCKETCLOUD_PASSWORD = The password for the account used to comment, you could use App passwords with Read Pull Requests and Read Account Permissions.

For OAuth key and OAuth secret, you can get them from.

  • Open BitBucket Cloud Website

  • Navigate to Settings > OAuth > Add consumer

  • Put https://bitbucket.org/site/oauth2/authorize for Callback URL, and enable Read Pull requests, and Read Account Permission.

  • DANGER_BITBUCKETCLOUD_OAUTH_KEY = The consumer key for the account used to comment, as show as Key on the website.

  • DANGER_BITBUCKETCLOUD_OAUTH_SECRET = The consumer secret for the account used to comment, as show as Secret on the website.

For repository access token, what you need to create one is:

  • Open your repository URL
  • Navigate to Settings > Security > Access Tokens > Create Repository Access Token
  • Give it a name and set Pull requests write scope

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

Returns a new instance of BitbucketPipelines.



54
55
56
57
58
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 54

def initialize(env)
  self.repo_url = env["BITBUCKET_GIT_HTTP_ORIGIN"]
  self.repo_slug = "#{env['BITBUCKET_REPO_OWNER']}/#{env['BITBUCKET_REPO_SLUG']}"
  self.pull_request_id = env["BITBUCKET_PR_ID"]
end

Class Method Details

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 42

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

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 46

def self.validates_as_pr?(env)
  env.key? "BITBUCKET_PR_ID"
end

Instance Method Details

#supported_request_sourcesObject



50
51
52
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 50

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