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`.

“‘yaml

script:
  - bundle exec danger --verbose

“‘

### Token Setup

For username and password, you need to set.

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

  • Open [BitBucket Cloud Website](bitbucket.org)

  • Navigate to Settings > OAuth > Add consumer

  • Put ‘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](support.atlassian.com/bitbucket-cloud/docs/repository-access-tokens/), 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.



52
53
54
55
56
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 52

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)


40
41
42
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 40

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

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 44

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

Instance Method Details

#supported_request_sourcesObject



48
49
50
# File 'lib/danger/ci_source/bitbucket_pipelines.rb', line 48

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