danger 8.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +94 -0
  4. data/bin/danger +5 -0
  5. data/lib/assets/DangerfileTemplate +13 -0
  6. data/lib/danger.rb +44 -0
  7. data/lib/danger/ci_source/appcenter.rb +55 -0
  8. data/lib/danger/ci_source/appveyor.rb +60 -0
  9. data/lib/danger/ci_source/azure_pipelines.rb +44 -0
  10. data/lib/danger/ci_source/bamboo.rb +41 -0
  11. data/lib/danger/ci_source/bitbucket_pipelines.rb +37 -0
  12. data/lib/danger/ci_source/bitrise.rb +65 -0
  13. data/lib/danger/ci_source/buddybuild.rb +62 -0
  14. data/lib/danger/ci_source/buildkite.rb +51 -0
  15. data/lib/danger/ci_source/ci_source.rb +37 -0
  16. data/lib/danger/ci_source/circle.rb +94 -0
  17. data/lib/danger/ci_source/circle_api.rb +51 -0
  18. data/lib/danger/ci_source/cirrus.rb +31 -0
  19. data/lib/danger/ci_source/code_build.rb +57 -0
  20. data/lib/danger/ci_source/codefresh.rb +53 -0
  21. data/lib/danger/ci_source/codeship.rb +44 -0
  22. data/lib/danger/ci_source/dotci.rb +52 -0
  23. data/lib/danger/ci_source/drone.rb +71 -0
  24. data/lib/danger/ci_source/github_actions.rb +43 -0
  25. data/lib/danger/ci_source/gitlab_ci.rb +86 -0
  26. data/lib/danger/ci_source/jenkins.rb +149 -0
  27. data/lib/danger/ci_source/local_git_repo.rb +119 -0
  28. data/lib/danger/ci_source/local_only_git_repo.rb +47 -0
  29. data/lib/danger/ci_source/screwdriver.rb +47 -0
  30. data/lib/danger/ci_source/semaphore.rb +37 -0
  31. data/lib/danger/ci_source/support/commits.rb +17 -0
  32. data/lib/danger/ci_source/support/find_repo_info_from_logs.rb +35 -0
  33. data/lib/danger/ci_source/support/find_repo_info_from_url.rb +42 -0
  34. data/lib/danger/ci_source/support/local_pull_request.rb +14 -0
  35. data/lib/danger/ci_source/support/no_pull_request.rb +7 -0
  36. data/lib/danger/ci_source/support/no_repo_info.rb +5 -0
  37. data/lib/danger/ci_source/support/pull_request_finder.rb +179 -0
  38. data/lib/danger/ci_source/support/remote_pull_request.rb +15 -0
  39. data/lib/danger/ci_source/support/repo_info.rb +10 -0
  40. data/lib/danger/ci_source/surf.rb +37 -0
  41. data/lib/danger/ci_source/teamcity.rb +159 -0
  42. data/lib/danger/ci_source/travis.rb +51 -0
  43. data/lib/danger/ci_source/vsts.rb +73 -0
  44. data/lib/danger/ci_source/xcode_server.rb +48 -0
  45. data/lib/danger/clients/rubygems_client.rb +14 -0
  46. data/lib/danger/commands/dangerfile/gem.rb +43 -0
  47. data/lib/danger/commands/dangerfile/init.rb +30 -0
  48. data/lib/danger/commands/dry_run.rb +54 -0
  49. data/lib/danger/commands/init.rb +297 -0
  50. data/lib/danger/commands/init_helpers/interviewer.rb +92 -0
  51. data/lib/danger/commands/local.rb +83 -0
  52. data/lib/danger/commands/local_helpers/http_cache.rb +36 -0
  53. data/lib/danger/commands/local_helpers/local_setup.rb +46 -0
  54. data/lib/danger/commands/local_helpers/pry_setup.rb +31 -0
  55. data/lib/danger/commands/plugins/plugin_json.rb +46 -0
  56. data/lib/danger/commands/plugins/plugin_lint.rb +54 -0
  57. data/lib/danger/commands/plugins/plugin_readme.rb +45 -0
  58. data/lib/danger/commands/pr.rb +92 -0
  59. data/lib/danger/commands/runner.rb +94 -0
  60. data/lib/danger/commands/staging.rb +53 -0
  61. data/lib/danger/commands/systems.rb +43 -0
  62. data/lib/danger/comment_generators/bitbucket_server.md.erb +20 -0
  63. data/lib/danger/comment_generators/bitbucket_server_inline.md.erb +15 -0
  64. data/lib/danger/comment_generators/bitbucket_server_message_group.md.erb +12 -0
  65. data/lib/danger/comment_generators/github.md.erb +55 -0
  66. data/lib/danger/comment_generators/github_inline.md.erb +26 -0
  67. data/lib/danger/comment_generators/gitlab.md.erb +40 -0
  68. data/lib/danger/comment_generators/gitlab_inline.md.erb +26 -0
  69. data/lib/danger/comment_generators/vsts.md.erb +20 -0
  70. data/lib/danger/core_ext/file_list.rb +18 -0
  71. data/lib/danger/core_ext/string.rb +20 -0
  72. data/lib/danger/danger_core/dangerfile.rb +341 -0
  73. data/lib/danger/danger_core/dangerfile_dsl.rb +29 -0
  74. data/lib/danger/danger_core/dangerfile_generator.rb +11 -0
  75. data/lib/danger/danger_core/environment_manager.rb +123 -0
  76. data/lib/danger/danger_core/executor.rb +92 -0
  77. data/lib/danger/danger_core/message_aggregator.rb +49 -0
  78. data/lib/danger/danger_core/message_group.rb +68 -0
  79. data/lib/danger/danger_core/messages/base.rb +56 -0
  80. data/lib/danger/danger_core/messages/markdown.rb +42 -0
  81. data/lib/danger/danger_core/messages/violation.rb +54 -0
  82. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +144 -0
  83. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +211 -0
  84. data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +248 -0
  85. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +158 -0
  86. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +254 -0
  87. data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +240 -0
  88. data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +42 -0
  89. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +218 -0
  90. data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +191 -0
  91. data/lib/danger/danger_core/standard_error.rb +143 -0
  92. data/lib/danger/helpers/array_subclass.rb +61 -0
  93. data/lib/danger/helpers/comment.rb +32 -0
  94. data/lib/danger/helpers/comments_helper.rb +178 -0
  95. data/lib/danger/helpers/comments_parsing_helper.rb +70 -0
  96. data/lib/danger/helpers/emoji_mapper.rb +41 -0
  97. data/lib/danger/helpers/find_max_num_violations.rb +31 -0
  98. data/lib/danger/helpers/message_groups_array_helper.rb +31 -0
  99. data/lib/danger/plugin_support/gems_resolver.rb +77 -0
  100. data/lib/danger/plugin_support/plugin.rb +49 -0
  101. data/lib/danger/plugin_support/plugin_file_resolver.rb +30 -0
  102. data/lib/danger/plugin_support/plugin_linter.rb +161 -0
  103. data/lib/danger/plugin_support/plugin_parser.rb +199 -0
  104. data/lib/danger/plugin_support/templates/readme_table.html.erb +26 -0
  105. data/lib/danger/request_sources/bitbucket_cloud.rb +171 -0
  106. data/lib/danger/request_sources/bitbucket_cloud_api.rb +181 -0
  107. data/lib/danger/request_sources/bitbucket_server.rb +105 -0
  108. data/lib/danger/request_sources/bitbucket_server_api.rb +117 -0
  109. data/lib/danger/request_sources/github/github.rb +530 -0
  110. data/lib/danger/request_sources/github/github_review.rb +126 -0
  111. data/lib/danger/request_sources/github/github_review_resolver.rb +19 -0
  112. data/lib/danger/request_sources/github/github_review_unsupported.rb +25 -0
  113. data/lib/danger/request_sources/gitlab.rb +525 -0
  114. data/lib/danger/request_sources/local_only.rb +53 -0
  115. data/lib/danger/request_sources/request_source.rb +85 -0
  116. data/lib/danger/request_sources/support/get_ignored_violation.rb +17 -0
  117. data/lib/danger/request_sources/vsts.rb +118 -0
  118. data/lib/danger/request_sources/vsts_api.rb +138 -0
  119. data/lib/danger/scm_source/git_repo.rb +181 -0
  120. data/lib/danger/version.rb +4 -0
  121. metadata +339 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f89ff08f152cedf23e9fcb48adc8b256ddb1ef8992c682bb6ad6ef1620ba1f5f
4
+ data.tar.gz: d9f689cd3b403177e3475d364f2aebe5b49a78e72eebfaeab49fad8d6ec3f619
5
+ SHA512:
6
+ metadata.gz: 9b1db5d7f0ed5106614a967c5bd45cdb8b896327f29512d259f662c0ad994438bb2c9240c122aab93f228eb21bf2f80029d6cf851d7f315f7559e491aa60cb04
7
+ data.tar.gz: 51413afca0478a350693672cb831e67e5ed92ff5a6d026caa805bdb58ff09bf7b8bfbbdd5cfc16c83878d8164af26088036fbc5aa354d57c990c75dcb15f8f6f
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019-present Orta, Felix Krause
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,94 @@
1
+ # Danger :no_entry_sign:
2
+
3
+ [![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/orta/danger/blob/master/LICENSE)
4
+ [![Gem](https://img.shields.io/gem/v/danger.svg?style=flat)](http://rubygems.org/gems/danger)
5
+ [![Travis CI](https://img.shields.io/travis/danger/danger.svg?style=flat)](https://travis-ci.org/danger/danger)
6
+ [![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/danger)
7
+
8
+ Formalize your Pull Request etiquette.
9
+
10
+ -------
11
+
12
+ <p align="center">
13
+ <a href="#what-is-danger">What is Danger?</a> &bull;
14
+ <a href="VISION.md">Vision</a> &bull;
15
+ <a href="#im-here-to-help-out">Helping Out</a> &bull;
16
+ <a href="https://danger.systems/guides/creating_your_first_plugin.html">Plugin Development</a>
17
+ </p>
18
+
19
+ -------
20
+
21
+ ## What is Danger?
22
+
23
+ Danger runs after your CI, automating your team's conventions surrounding code review.
24
+
25
+ This provides another logical step in your process, through this Danger can help lint your rote tasks in daily code review.
26
+
27
+ You can use Danger to codify your team's norms, leaving humans to think about harder problems.
28
+
29
+ ## For example?
30
+
31
+ You can:
32
+
33
+ * Enforce CHANGELOGs
34
+ * Enforce links to Trello/JIRA in PR/MR bodies
35
+ * Enforce using descriptive labels
36
+ * Look out for common anti-patterns
37
+ * Highlight interesting build artifacts
38
+ * Give specific files extra focus
39
+
40
+ Danger provides the glue to let _you_ build out the rules specific to your team's culture, offering useful metadata and a comprehensive plugin system to share common issues.
41
+
42
+ ## Getting Started
43
+
44
+ Alright. So, actually, you may be in the wrong place. From here on in, this README is going to be for people who are interested in working on and improving on Danger.
45
+
46
+ We keep all of the end-user documentation at [https://danger.systems](https://danger.systems).
47
+
48
+ Some quick links: [Guides Index](https://danger.systems/guides.html), [DSL Reference](https://danger.systems/reference.html), [Getting Started](https://danger.systems/guides/getting_started.html) and [What does Danger Do?](https://danger.systems/guides/what_does_danger_do.html).
49
+
50
+ ## I'm here to help out!
51
+
52
+ Brilliant. So, let's get you set up.
53
+
54
+ ``` sh
55
+ git clone https://github.com/danger/danger.git
56
+ cd danger
57
+ bundle install
58
+ bundle exec rake spec
59
+ ```
60
+
61
+ This sets everything up and runs all of the tests.
62
+
63
+ #### Theory
64
+
65
+ Danger has a [VISION.md](https://github.com/danger/danger/blob/master/VISION.md) file, which sums up the ideas around what Danger is. It is the lower bounds of what Danger means. Orta has written on handling and creating Danger [on the Artsy blog](http://artsy.github.io/blog/categories/danger/), too.
66
+
67
+ #### Documentation
68
+
69
+ The code you write may end up in the public part of the website — the easiest way to tell is that it is vastly overdocumented. If you are working in a space that looks over-documented, please be extra considerate to add documentation. We expect the consumers of that documentation to be non-rubyists, thus you should avoid specific jargon and try to provide duplicate overlapping examples.
70
+
71
+ #### Testing
72
+
73
+ So far, we've not really figured out the right way to make tests for our CLI commands. When we have done so, they've ended up being brittle. So, ideally, try to move any logic that would go into a command into separate classes, and test those. We're okay with the command not having coverage, but ideally the classes that make up what it does will.
74
+
75
+ I'd strongly recommend using `bundle exec guard` to run your tests as you work. Any changes you make in the lib, or specs will have corresponding tests run instantly.
76
+
77
+ #### Debugging
78
+
79
+ Ruby is super dynamic. One of the best ways to debug Ruby code is by using [pry](http://pryrepl.org/). We include pry for developers: when you have a problem, copy these two lines just before your problem and follow the instructions from "[I Want To Be A Danger Wizard](https://danger.systems/guides/troubleshooting.html#i-want-to-be-a-danger-wizard)."
80
+
81
+ ```ruby
82
+ require 'pry'
83
+ binding.pry
84
+ ```
85
+
86
+ ## License, Contributor's Guidelines and Code of Conduct
87
+
88
+ We try to keep as much discussion as possible in GitHub issues, but also have a pretty inactive Slack --- if you'd like an invite, ping [@Orta](https://twitter.com/orta/) a DM on Twitter with your email. It's mostly interesting if you want to stay on top of Danger without all the emails from GitHub.
89
+
90
+ > This project is open source under the MIT license, which means you have full access to the source code and can modify it to fit your own needs.
91
+
92
+ > This project subscribes to the [Moya Contributors Guidelines](https://github.com/Moya/contributors) which TLDR: means we give out push access easily and often.
93
+
94
+ > Contributors subscribe to the [Contributor Code of Conduct](https://contributor-covenant.org/version/1/3/0/) based on the [Contributor Covenant](https://contributor-covenant.org) version 1.3.0.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.push File.expand_path("../../lib", __FILE__)
3
+
4
+ require "danger"
5
+ Danger::Runner.run ARGV
@@ -0,0 +1,13 @@
1
+ # Sometimes it's a README fix, or something like that - which isn't relevant for
2
+ # including in a project's CHANGELOG for example
3
+ declared_trivial = github.pr_title.include? "#trivial"
4
+
5
+ # Make it more obvious that a PR is a work in progress and shouldn't be merged yet
6
+ warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
7
+
8
+ # Warn when there is a big PR
9
+ warn("Big PR") if git.lines_of_code > 500
10
+
11
+ # Don't let testing shortcuts get into master by accident
12
+ fail("fdescribe left in tests") if `grep -r fdescribe specs/ `.length > 1
13
+ fail("fit left in tests") if `grep -r fit specs/ `.length > 1
@@ -0,0 +1,44 @@
1
+ require "danger/version"
2
+ require "danger/danger_core/dangerfile"
3
+ require "danger/danger_core/environment_manager"
4
+ require "danger/commands/runner"
5
+ require "danger/plugin_support/plugin"
6
+ require "danger/core_ext/string"
7
+ require "danger/danger_core/executor"
8
+
9
+ require "claide"
10
+ require "colored2"
11
+ require "pathname"
12
+ require "terminal-table"
13
+ require "cork"
14
+
15
+ # Import all the Sources (CI, Request and SCM)
16
+ Dir[File.expand_path("danger/*source/*.rb", File.dirname(__FILE__))].each do |file|
17
+ require file
18
+ end
19
+
20
+ module Danger
21
+ GEM_NAME = "danger".freeze
22
+
23
+ # @return [String] The path to the local gem directory
24
+ def self.gem_path
25
+ if Gem::Specification.find_all_by_name(GEM_NAME).empty?
26
+ raise "Couldn't find gem directory for 'danger'"
27
+ end
28
+ return Gem::Specification.find_by_name(GEM_NAME).gem_dir
29
+ end
30
+
31
+ # @return [String] Latest version of Danger on https://rubygems.org
32
+ def self.danger_outdated?
33
+ require "danger/clients/rubygems_client"
34
+ latest_version = RubyGemsClient.latest_danger_version
35
+
36
+ if Gem::Version.new(latest_version) > Gem::Version.new(Danger::VERSION)
37
+ latest_version
38
+ else
39
+ false
40
+ end
41
+ rescue StandardError => _e
42
+ false
43
+ end
44
+ end
@@ -0,0 +1,55 @@
1
+ # https://docs.microsoft.com/en-us/appcenter/build/custom/variables/
2
+ require "uri"
3
+ require "danger/request_sources/github/github"
4
+
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # Add a script step to your appcenter-post-build.sh:
9
+ #
10
+ # ``` shell
11
+ # #!/usr/bin/env bash
12
+ # bundle install
13
+ # bundle exec danger
14
+ # ```
15
+ #
16
+ # ### Token Setup
17
+ #
18
+ # Add the `DANGER_GITHUB_API_TOKEN` to your environment variables.
19
+ #
20
+ class Appcenter < CI
21
+ def self.validates_as_ci?(env)
22
+ env.key? "APPCENTER_BUILD_ID"
23
+ end
24
+
25
+ def self.validates_as_pr?(env)
26
+ return env["BUILD_REASON"] == "PullRequest"
27
+ end
28
+
29
+ def self.owner_for_github(env)
30
+ URI.parse(env["BUILD_REPOSITORY_URI"]).path.split("/")[1]
31
+ end
32
+
33
+ def self.repo_identifier_for_github(env)
34
+ repo_name = env["BUILD_REPOSITORY_NAME"]
35
+ owner = owner_for_github(env)
36
+ "#{owner}/#{repo_name}"
37
+ end
38
+
39
+ # Hopefully it's a temporary workaround (same as in Codeship integration) because App Center
40
+ # doesn't expose PR's ID. There's a future request https://github.com/Microsoft/appcenter/issues/79
41
+ def self.pr_from_env(env)
42
+ Danger::RequestSources::GitHub.new(nil, env).get_pr_from_branch(repo_identifier_for_github(env), env["BUILD_SOURCEBRANCHNAME"], owner_for_github(env))
43
+ end
44
+
45
+ def supported_request_sources
46
+ @supported_request_sources ||= [Danger::RequestSources::GitHub]
47
+ end
48
+
49
+ def initialize(env)
50
+ self.pull_request_id = self.class.pr_from_env(env)
51
+ self.repo_url = env["BUILD_REPOSITORY_URI"]
52
+ self.repo_slug = self.class.repo_identifier_for_github(env)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,60 @@
1
+ # https://www.appveyor.com/docs/build-configuration/
2
+ module Danger
3
+ # ### CI Setup
4
+ #
5
+ # Install dependencies and add a danger step to your `appveyor.yml`.
6
+ # ```yaml
7
+ # install:
8
+ # - cmd: >-
9
+ # set PATH=C:\Ruby25-x64\bin;%PATH%
10
+ #
11
+ # bundle install
12
+ # after_test:
13
+ # - cmd: >-
14
+ # bundle exec danger
15
+ # ```
16
+ #
17
+ # ### Token Setup
18
+ #
19
+ # For public repositories, add your plain token to environment variables in `appveyor.yml`.
20
+ # Encrypted environment variables will not be decrypted on PR builds.
21
+ # see here: https://www.appveyor.com/docs/build-configuration/#secure-variables
22
+ # ```yaml
23
+ # environment:
24
+ # DANGER_GITHUB_API_TOKEN: <YOUR_TOKEN_HERE>
25
+ # ```
26
+ #
27
+ # For private repositories, enter your token in `Settings>Environment>Environment variables>Add variable` and turn on `variable encryption`.
28
+ # You will see encrypted variable text in `Settings>Export YAML` so just copy to your `appveyor.yml`.
29
+ # ```yaml
30
+ # environment:
31
+ # DANGER_GITHUB_API_TOKEN:
32
+ # secure: <YOUR_ENCRYPTED_TOKEN_HERE>
33
+ # ```
34
+ #
35
+ class AppVeyor < CI
36
+ def self.validates_as_ci?(env)
37
+ env.key? "APPVEYOR"
38
+ end
39
+
40
+ def self.validates_as_pr?(env)
41
+ return false unless env.key? "APPVEYOR_PULL_REQUEST_NUMBER"
42
+ env["APPVEYOR_PULL_REQUEST_NUMBER"].to_i > 0
43
+ end
44
+
45
+ def initialize(env)
46
+ self.repo_slug = env["APPVEYOR_REPO_NAME"]
47
+ self.pull_request_id = env["APPVEYOR_PULL_REQUEST_NUMBER"]
48
+ self.repo_url = GitRepo.new.origins # AppVeyor doesn't provide a repo url env variable for now
49
+ end
50
+
51
+ def supported_request_sources
52
+ @supported_request_sources ||= [
53
+ Danger::RequestSources::GitHub,
54
+ Danger::RequestSources::BitbucketCloud,
55
+ Danger::RequestSources::BitbucketServer,
56
+ Danger::RequestSources::GitLab
57
+ ]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,44 @@
1
+ # https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
2
+ require "uri"
3
+ require "danger/request_sources/github/github"
4
+
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # Add a script step:
9
+ #
10
+ # ``` shell
11
+ # #!/usr/bin/env bash
12
+ # bundle install
13
+ # bundle exec danger
14
+ # ```
15
+ #
16
+ # ### Token Setup
17
+ #
18
+ # Add the `DANGER_GITHUB_API_TOKEN` to your environment variables.
19
+ #
20
+ class AzurePipelines < CI
21
+ def self.validates_as_ci?(env)
22
+ env.key? "AGENT_ID"
23
+ end
24
+
25
+ def self.validates_as_pr?(env)
26
+ return env["BUILD_REASON"] == "PullRequest"
27
+ end
28
+
29
+ def supported_request_sources
30
+ @supported_request_sources ||= [
31
+ Danger::RequestSources::GitHub,
32
+ Danger::RequestSources::GitLab,
33
+ Danger::RequestSources::BitbucketServer,
34
+ Danger::RequestSources::BitbucketCloud
35
+ ]
36
+ end
37
+
38
+ def initialize(env)
39
+ self.pull_request_id = env["SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"] || env["SYSTEM_PULLREQUEST_PULLREQUESTID"]
40
+ self.repo_url = env["BUILD_REPOSITORY_URI"]
41
+ self.repo_slug = env["BUILD_REPOSITORY_NAME"]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ require "set"
2
+
3
+ module Danger
4
+ # ### CI Setup
5
+ #
6
+ # Add a Run Script task that executes `danger` (or `bundle exec danger` if you're using Bundler
7
+ # to manage your gems) as your as part of your Bamboo plan.
8
+ # The minimum supported version is Bamboo 6.9.
9
+ #
10
+ # ### Token Setup
11
+ #
12
+ # IMPORTANT: All required Bamboo environment variables will be available
13
+ # only if the plan is run as part of a pull request. This can be achieved by selecting:
14
+ # Configure plan -> Branches -> Create plan branch: "When pull request is created".
15
+ # Otherwise, `bamboo_repository_pr_key` and `bamboo_planRepository_repositoryUrl`
16
+ # will not be available.
17
+ #
18
+ class Bamboo < CI
19
+ def supported_request_sources
20
+ @supported_request_sources ||= [
21
+ Danger::RequestSources::BitbucketServer
22
+ ]
23
+ end
24
+
25
+ def self.validates_as_ci?(env)
26
+ env.key? "bamboo_buildKey"
27
+ end
28
+
29
+ def self.validates_as_pr?(env)
30
+ exists = ["bamboo_repository_pr_key", "bamboo_planRepository_repositoryUrl"].all? { |x| env[x] && !env[x].empty? }
31
+ exists && env["bamboo_repository_pr_key"].to_i > 0
32
+ end
33
+
34
+ def initialize(env)
35
+ self.repo_url = env["bamboo_planRepository_repositoryUrl"]
36
+ self.pull_request_id = env["bamboo_repository_pr_key"]
37
+ repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+?)(\.git$|$)})
38
+ self.repo_slug = repo_matches[2] unless repo_matches.nil?
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ module Danger
2
+ # ### CI Setup
3
+ #
4
+ # Install dependencies and add a danger step to your `bitbucket-pipelines.yml`.
5
+ # ```yaml
6
+ # script:
7
+ # - bundle exec danger --verbose
8
+ # ```
9
+ #
10
+ # ### Token Setup
11
+ #
12
+ # Add `DANGER_BITBUCKETCLOUD_USERNAME` and `DANGER_BITBUCKETCLOUD_PASSWORD` to your pipeline repository variable
13
+ # or instead using `DANGER_BITBUCKETCLOUD_OAUTH_KEY` and `DANGER_BITBUCKETCLOUD_OAUTH_SECRET`.
14
+ #
15
+ # You can find them in Settings > Pipelines > Repository Variables
16
+
17
+ class BitbucketPipelines < CI
18
+
19
+ def self.validates_as_ci?(env)
20
+ env.key? "BITBUCKET_BUILD_NUMBER"
21
+ end
22
+
23
+ def self.validates_as_pr?(env)
24
+ env.key? "BITBUCKET_PR_ID"
25
+ end
26
+
27
+ def supported_request_sources
28
+ @supported_request_sources ||= [Danger::RequestSources::BitbucketCloud]
29
+ end
30
+
31
+ def initialize(env)
32
+ self.repo_url = env["BITBUCKET_GIT_HTTP_ORIGIN"]
33
+ self.repo_slug = "#{env["BITBUCKET_REPO_OWNER"]}/#{env["BITBUCKET_REPO_SLUG"]}"
34
+ self.pull_request_id = env["BITBUCKET_PR_ID"]
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,65 @@
1
+ # http://devcenter.bitrise.io/docs/available-environment-variables
2
+ require "danger/request_sources/github/github"
3
+ require "danger/request_sources/gitlab"
4
+
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # Add a script step to your workflow:
9
+ #
10
+ # ```yml
11
+ # - script@1.1.2:
12
+ # inputs:
13
+ # - content: |-
14
+ # bundle install
15
+ # bundle exec danger
16
+ # ```
17
+ #
18
+ # ### Token Setup
19
+ #
20
+ # Add the `DANGER_GITHUB_API_TOKEN` to your workflow's [Secret App Env Vars](https://blog.bitrise.io/anyone-even-prs-can-have-secrets).
21
+ #
22
+ # ### bitbucket server and bitrsie
23
+ #
24
+ # Danger will read the environment variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
25
+ # finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
26
+ # comes from the App Settings tab for your Bitrsie App. If you are manually setting a repo URL in the
27
+ # Git Clone Repo step, you may need to set adjust this propery in the settings tab, maybe even fake it.
28
+ # The patterns used are `(%r{\.com/(.*)})` and `(%r{\.com:(.*)})` and .split(/\.git$|$/) to remove ".git" if the URL contains it.
29
+ #
30
+ class Bitrise < CI
31
+ def self.validates_as_ci?(env)
32
+ env.key? "BITRISE_IO"
33
+ end
34
+
35
+ def self.validates_as_pr?(env)
36
+ return !env["BITRISE_PULL_REQUEST"].to_s.empty?
37
+ end
38
+
39
+ def supported_request_sources
40
+ @supported_request_sources ||= [
41
+ Danger::RequestSources::GitHub,
42
+ Danger::RequestSources::GitLab,
43
+ Danger::RequestSources::BitbucketServer,
44
+ Danger::RequestSources::BitbucketCloud
45
+ ]
46
+ end
47
+
48
+ def initialize(env)
49
+ self.pull_request_id = env["BITRISE_PULL_REQUEST"]
50
+ self.repo_url = env["GIT_REPOSITORY_URL"]
51
+
52
+ matcher_url = self.repo_url
53
+
54
+ #If the URL contains https:// as :// leads to inaccurate matching. So we remove it and proceed to match.
55
+ if repo_url.include? "https://"
56
+ matcher_url["https://"] = ''
57
+ end
58
+
59
+ repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
60
+
61
+ self.repo_slug = repo_matches unless repo_matches.nil?
62
+
63
+ end
64
+ end
65
+ end