Class: Danger::Appcircle

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

Overview

### CI Setup

Add a Custom Script step to your workflow and set it as a bash:

“‘shell

cd $AC_REPOSITORY_DIR
bundle install
bundle exec danger

“‘ ### Token Setup

Login to Appcircle and select your build profile. Go to your Config and choose *Environment Variables*. docs.appcircle.io/environment-variables/managing-variables

#### GitHub Add the ‘DANGER_GITHUB_API_TOKEN` to your profile’s ENV.

#### GitLab Add the ‘DANGER_GITLAB_API_TOKEN` to your profile’s ENV.

#### Bitbucket Cloud Add the ‘DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD` to your profile’s ENV.

#### Bitbucket server Add the ‘DANGER_BITBUCKETSERVER_USERNAME`, `DANGER_BITBUCKETSERVER_PASSWORD` and `DANGER_BITBUCKETSERVER_HOST` to your profile’s ENV.

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

Returns a new instance of Appcircle.



55
56
57
58
59
# File 'lib/danger/ci_source/appcircle.rb', line 55

def initialize(env)
  self.pull_request_id = env["AC_PULL_NUMBER"]
  self.repo_url = env["AC_GIT_URL"]
  self.repo_slug = repo_slug_from(self.repo_url)
end

Class Method Details

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/danger/ci_source/appcircle.rb', line 36

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

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/danger/ci_source/appcircle.rb', line 40

def self.validates_as_pr?(env)
  return false unless env.key? "AC_PULL_NUMBER"

  env["AC_PULL_NUMBER"].to_i > 0
end

Instance Method Details

#repo_slug_asgiturl(url) ⇒ Object



77
78
79
80
81
# File 'lib/danger/ci_source/appcircle.rb', line 77

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/danger/ci_source/appcircle.rb', line 61

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



46
47
48
49
50
51
52
53
# File 'lib/danger/ci_source/appcircle.rb', line 46

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