Class: Danger::Bitrise

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

Overview

### CI Setup

Add a script step to your workflow:

“‘yml

“‘

### Token Setup

Add the ‘DANGER_GITHUB_API_TOKEN` to your workflow’s [Secret App Env Vars](blog.bitrise.io/anyone-even-prs-can-have-secrets).

### Bitbucket Server and Bitrise

Danger will read the environment variable ‘GIT_REPOSITORY_URL` to construct the Bitbucket Server API URL finding the project and repo slug in the `GIT_REPOSITORY_URL` variable. This `GIT_REPOSITORY_URL` variable comes from the App Settings tab for your Bitrise App. If you are manually setting a repo URL in the Git Clone Repo step, you may need to set adjust this property in the settings tab, maybe even fake it. The patterns used are `(%rcom/(.com/(.*))` and `(%r.com:(.com:(.*))` and `.split(/.git$|$/)` to remove “.git” if the URL contains it.

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

Returns a new instance of Bitrise.



48
49
50
51
52
53
54
# File 'lib/danger/ci_source/bitrise.rb', line 48

def initialize(env)
  self.pull_request_id = env["BITRISE_PULL_REQUEST"]
  self.repo_url = env["GIT_REPOSITORY_URL"]

  matcher_url = self.repo_url
  self.repo_slug = repo_slug_from(self.repo_url)
end

Class Method Details

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/danger/ci_source/bitrise.rb', line 31

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

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/danger/ci_source/bitrise.rb', line 35

def self.validates_as_pr?(env)
  return !env["BITRISE_PULL_REQUEST"].to_s.empty?
end

Instance Method Details

#repo_slug_asgiturl(url) ⇒ Object



72
73
74
75
76
# File 'lib/danger/ci_source/bitrise.rb', line 72

def repo_slug_asgiturl(url)
  matcher_url = url
  repo_matches = matcher_url.match(%r{([/:])(([^/]+/)+[^/]+?)(\.git$|$)})[2]
  return repo_matches unless repo_matches.nil?
end

#repo_slug_from(url) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/danger/ci_source/bitrise.rb', line 56

def repo_slug_from(url)
  if url =~ URI::DEFAULT_PARSER.make_regexp
    # Try to parse the URL as a valid URI. This should cover the cases of http/https/ssh URLs.
    begin
      uri = URI.parse(url)
      return uri.path.sub(%r{^(/)}, "").sub(/(.git)$/, "")
    rescue URI::InvalidURIError
      # In case URL could not be parsed fallback to git URL parsing.
      repo_slug_asgiturl(url)
    end
  else
    # In case URL could not be parsed fallback to git URL parsing. [email protected]:organization/repo.git
    repo_slug_asgiturl(url)
  end
end

#supported_request_sourcesObject



39
40
41
42
43
44
45
46
# File 'lib/danger/ci_source/bitrise.rb', line 39

def supported_request_sources
  @supported_request_sources ||= [
    Danger::RequestSources::GitHub,
    Danger::RequestSources::GitLab,
    Danger::RequestSources::BitbucketServer,
    Danger::RequestSources::BitbucketCloud
  ]
end