danger 8.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +161 -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,10 @@
1
+ module Danger
2
+ class RepoInfo
3
+ attr_reader :slug, :id
4
+
5
+ def initialize(slug, id)
6
+ @slug = slug
7
+ @id = id
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ # http://github.com/surf-build/surf
2
+ require "danger/request_sources/github/github"
3
+
4
+ module Danger
5
+ # ### CI Setup
6
+ #
7
+ # You want to add `bundle exec danger` to your `build.sh` file to run Danger at the
8
+ # end of your build.
9
+ #
10
+ # ### Token Setup
11
+ #
12
+ # As this is self-hosted, you will need to add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV. The alternative
13
+ # is to pass in the token as a prefix to the command `DANGER_GITHUB_API_TOKEN="123" bundle exec danger`.
14
+ #
15
+ class Surf < CI
16
+ def self.validates_as_ci?(env)
17
+ return ["SURF_REPO", "SURF_NWO"].all? { |x| env[x] && !env[x].empty? }
18
+ end
19
+
20
+ def self.validates_as_pr?(env)
21
+ validates_as_ci?(env)
22
+ end
23
+
24
+ def supported_request_sources
25
+ @supported_request_sources ||= [Danger::RequestSources::GitHub]
26
+ end
27
+
28
+ def initialize(env)
29
+ self.repo_slug = env["SURF_NWO"]
30
+ if env["SURF_PR_NUM"].to_i > 0
31
+ self.pull_request_id = env["SURF_PR_NUM"]
32
+ end
33
+
34
+ self.repo_url = env["SURF_REPO"]
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,161 @@
1
+ # https://www.jetbrains.com/teamcity/
2
+ require "danger/request_sources/github/github"
3
+ require "danger/request_sources/gitlab"
4
+
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # You need to go to your project settings. Then depending on the type of your build settings, you may need
9
+ # to add a new build step for Danger. You want to be able to run the command `bundle exec danger`, so
10
+ # the "Simple Command Runner" should be all you need to do that.
11
+ #
12
+ # ### Token + Environment Setup
13
+ #
14
+ # #### GitHub
15
+ #
16
+ # As this is self-hosted, you will need to add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV. The alternative
17
+ # is to pass in the token as a prefix to the command `DANGER_GITHUB_API_TOKEN="123" bundle exec danger`.
18
+ #
19
+ # However, you will need to find a way to add the environment vars: `GITHUB_REPO_SLUG`, `GITHUB_PULL_REQUEST_ID` and
20
+ # `GITHUB_REPO_URL`. These are not added by default. You can manually add `GITHUB_REPO_SLUG` and `GITHUB_REPO_URL`
21
+ # as build parameters or by exporting them inside your Simple Command Runner.
22
+ #
23
+ # As for `GITHUB_PULL_REQUEST_ID`, TeamCity provides the `%teamcity.build.branch%` variable which is in the format
24
+ # `PR_NUMBER/merge`. You can slice the Pull Request ID out by doing the following:
25
+ #
26
+ # ```sh
27
+ # branch="%teamcity.build.branch%"
28
+ # export GITHUB_PULL_REQUEST_ID=(${branch//\// })
29
+ # ```
30
+ # Or if you are using the pull request feature you can set an environment parameter called `GITHUB_PULL_REQUEST_ID`
31
+ # to the value of: `%teamcity.pullRequest.number`
32
+ #
33
+ # #### GitLab
34
+ #
35
+ # As this is self-hosted, you will need to add the `DANGER_GITLAB_API_TOKEN` to your build user's ENV. The alternative
36
+ # is to pass in the token as a prefix to the command `DANGER_GITLAB_API_TOKEN="123" bundle exec danger`.
37
+ #
38
+ # However, you will need to find a way to add the environment vars: `GITLAB_REPO_SLUG`, `GITLAB_PULL_REQUEST_ID` and
39
+ # `GITLAB_REPO_URL`. These are not added by default. You could do this via the GitLab API potentially.
40
+ #
41
+ # We would love some advice on improving this setup.
42
+ #
43
+ # #### BitBucket Cloud
44
+ #
45
+ # You will need to add the following environment variables as build parameters or by exporting them inside your
46
+ # Simple Command Runner.
47
+ #
48
+ #
49
+ # - `BITBUCKET_REPO_SLUG`
50
+ # - `BITBUCKET_REPO_URL`
51
+ #
52
+ # - `DANGER_BITBUCKETCLOUD_USERNAME`
53
+ # - `DANGER_BITBUCKETCLOUD_PASSWORD`
54
+ #
55
+ # or
56
+ #
57
+ # - `DANGER_BITBUCKETCLOUD_OAUTH_KEY`
58
+ # - `DANGER_BITBUCKETCLOUD_OAUTH_SECRET`
59
+ #
60
+ # You will also need to set the `BITBUCKET_BRANCH_NAME` environment variable.
61
+ # TeamCity provides `%teamcity.build.branch%`, which you can use at the top of your Simple Command Runner:
62
+ # ```sh
63
+ # export BITBUCKET_BRANCH_NAME="%teamcity.build.branch%"
64
+ # ```
65
+ #
66
+ # #### BitBucket Server
67
+ #
68
+ # You will need to add the following environment variables as build parameters or by exporting them inside your
69
+ # Simple Command Runner.
70
+ #
71
+ # - `DANGER_BITBUCKETSERVER_USERNAME`
72
+ # - `DANGER_BITBUCKETSERVER_PASSWORD`
73
+ # - `DANGER_BITBUCKETSERVER_HOST`
74
+ # - `BITBUCKETSERVER_REPO_SLUG`
75
+ # - `BITBUCKETSERVER_PULL_REQUEST_ID`
76
+ # - `BITBUCKETSERVER_REPO_URL`
77
+ #
78
+ class TeamCity < CI
79
+ class << self
80
+ def validates_as_github_pr?(env)
81
+ ["GITHUB_PULL_REQUEST_ID", "GITHUB_REPO_URL"].all? { |x| env[x] && !env[x].empty? }
82
+ end
83
+
84
+ def validates_as_gitlab_pr?(env)
85
+ ["GITLAB_REPO_SLUG", "GITLAB_PULL_REQUEST_ID", "GITLAB_REPO_URL"].all? { |x| env[x] && !env[x].empty? }
86
+ end
87
+
88
+ def validates_as_bitbucket_cloud_pr?(env)
89
+ ["BITBUCKET_REPO_SLUG", "BITBUCKET_BRANCH_NAME", "BITBUCKET_REPO_URL"].all? { |x| env[x] && !env[x].empty? }
90
+ end
91
+
92
+ def validates_as_bitbucket_server_pr?(env)
93
+ ["BITBUCKETSERVER_REPO_SLUG", "BITBUCKETSERVER_PULL_REQUEST_ID", "BITBUCKETSERVER_REPO_URL"].all? { |x| env[x] && !env[x].empty? }
94
+ end
95
+ end
96
+
97
+ def self.validates_as_ci?(env)
98
+ env.key? "TEAMCITY_VERSION"
99
+ end
100
+
101
+ def self.validates_as_pr?(env)
102
+ validates_as_github_pr?(env) || validates_as_gitlab_pr?(env) || validates_as_bitbucket_cloud_pr?(env) || validates_as_bitbucket_server_pr?(env)
103
+ end
104
+
105
+ def supported_request_sources
106
+ @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::GitLab, Danger::RequestSources::BitbucketCloud, Danger::RequestSources::BitbucketServer]
107
+ end
108
+
109
+ def initialize(env)
110
+ # NB: Unfortunately TeamCity doesn't provide these variables
111
+ # automatically so you have to add these variables manually to your
112
+ # project or build configuration
113
+ if self.class.validates_as_github_pr?(env)
114
+ extract_github_variables!(env)
115
+ elsif self.class.validates_as_gitlab_pr?(env)
116
+ extract_gitlab_variables!(env)
117
+ elsif self.class.validates_as_bitbucket_cloud_pr?(env)
118
+ extract_bitbucket_variables!(env)
119
+ elsif self.class.validates_as_bitbucket_server_pr?(env)
120
+ extract_bitbucket_server_variables!(env)
121
+ end
122
+ end
123
+
124
+ private
125
+
126
+ def extract_github_variables!(env)
127
+ self.repo_slug = env["GITHUB_REPO_SLUG"]
128
+ self.pull_request_id = env["GITHUB_PULL_REQUEST_ID"].to_i
129
+ self.repo_url = env["GITHUB_REPO_URL"]
130
+ end
131
+
132
+ def extract_gitlab_variables!(env)
133
+ self.repo_slug = env["GITLAB_REPO_SLUG"]
134
+ self.pull_request_id = env["GITLAB_PULL_REQUEST_ID"].to_i
135
+ self.repo_url = env["GITLAB_REPO_URL"]
136
+ end
137
+
138
+ def extract_bitbucket_variables!(env)
139
+ self.repo_slug = env["BITBUCKET_REPO_SLUG"]
140
+ self.pull_request_id = bitbucket_pr_from_env(env)
141
+ self.repo_url = env["BITBUCKET_REPO_URL"]
142
+ end
143
+
144
+ def extract_bitbucket_server_variables!(env)
145
+ self.repo_slug = env["BITBUCKETSERVER_REPO_SLUG"]
146
+ self.pull_request_id = env["BITBUCKETSERVER_PULL_REQUEST_ID"].to_i
147
+ self.repo_url = env["BITBUCKETSERVER_REPO_URL"]
148
+ end
149
+
150
+ # This is a little hacky, because Bitbucket doesn't provide us a PR id
151
+ def bitbucket_pr_from_env(env)
152
+ branch_name = env["BITBUCKET_BRANCH_NAME"]
153
+ repo_slug = env["BITBUCKET_REPO_SLUG"]
154
+ begin
155
+ Danger::RequestSources::BitbucketCloudAPI.new(repo_slug, nil, branch_name, env).pull_request_id
156
+ rescue
157
+ raise "Failed to find a pull request for branch \"#{branch_name}\" on Bitbucket."
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,51 @@
1
+ # http://docs.travis-ci.com/user/osx-ci-environment/
2
+ # http://docs.travis-ci.com/user/environment-variables/
3
+ require "danger/request_sources/github/github"
4
+
5
+ module Danger
6
+ # ### CI Setup
7
+ # You need to edit your `.travis.yml` to include `bundle exec danger`. If you already have
8
+ # a `script:` section then we recommend adding this command at the end of the script step: `- bundle exec danger`.
9
+ #
10
+ # Otherwise, add a `before_script` step to the root of the `.travis.yml` with `bundle exec danger`
11
+ #
12
+ # ```ruby
13
+ # before_script:
14
+ # - bundle exec danger
15
+ # ```
16
+ #
17
+ # Adding this to your `.travis.yml` allows Danger to fail your build, both on the TravisCI website and within your Pull Request.
18
+ # With that set up, you can edit your job to add `bundle exec danger` at the build action.
19
+ #
20
+ # _Note:_ Travis CI defaults to using an older version of Ruby, so you may need to add `rvm: 2.0.0` to the root your `.travis.yml`.
21
+ #
22
+ # ### Token Setup
23
+ #
24
+ # You need to add the `DANGER_GITHUB_API_TOKEN` environment variable, to do this,
25
+ # go to your repo's settings, which should look like: `https://travis-ci.org/[user]/[repo]/settings`.
26
+ #
27
+ # If you have an open source project, you should ensure "Display value in build log" enabled, so that PRs from forks work.
28
+ #
29
+ class Travis < CI
30
+ def self.validates_as_ci?(env)
31
+ env.key? "HAS_JOSH_K_SEAL_OF_APPROVAL"
32
+ end
33
+
34
+ def self.validates_as_pr?(env)
35
+ exists = ["TRAVIS_PULL_REQUEST", "TRAVIS_REPO_SLUG"].all? { |x| env[x] && !env[x].empty? }
36
+ exists && env["TRAVIS_PULL_REQUEST"].to_i > 0
37
+ end
38
+
39
+ def supported_request_sources
40
+ @supported_request_sources ||= [Danger::RequestSources::GitHub]
41
+ end
42
+
43
+ def initialize(env)
44
+ self.repo_slug = env["TRAVIS_REPO_SLUG"]
45
+ if env["TRAVIS_PULL_REQUEST"].to_i > 0
46
+ self.pull_request_id = env["TRAVIS_PULL_REQUEST"]
47
+ end
48
+ self.repo_url = GitRepo.new.origins # Travis doesn't provide a repo url env variable :/
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,73 @@
1
+ require "danger/request_sources/github/github"
2
+ require "danger/request_sources/vsts"
3
+
4
+ module Danger
5
+ # ### CI Setup
6
+ #
7
+ # You need to go to your project's build definition. Then add a "Command Line" Task with the "Tool" field set to "bundle"
8
+ # and the "Arguments" field set to "exec danger".
9
+ #
10
+ # ### Token Setup
11
+ #
12
+ # #### GitHub
13
+ #
14
+ # You need to add the `DANGER_GITHUB_API_TOKEN` environment variable, to do this, go to your build definition's variables tab.
15
+ #
16
+ # Make sure that `DANGER_GITHUB_API_TOKEN` is not set to secret since vsts does not expose secret variables while building.
17
+ #
18
+ # #### VSTS
19
+ #
20
+ # You need to add the `DANGER_VSTS_API_TOKEN` and `DANGER_VSTS_HOST` environment variable, to do this,
21
+ # go to your build definition's variables tab. The `DANGER_VSTS_API_TOKEN` is your vsts personal access token.
22
+ # Instructions for creating a personal access token can be found [here](https://www.visualstudio.com/en-us/docs/setup-admin/team-services/use-personal-access-tokens-to-authenticate).
23
+ # For the `DANGER_VSTS_HOST` variable the suggested value is `$(System.TeamFoundationCollectionUri)$(System.TeamProject)`
24
+ # which will automatically get your vsts domain and your project name needed for the vsts api.
25
+ #
26
+ # Make sure that `DANGER_VSTS_API_TOKEN` is not set to secret since vsts does not expose secret variables while building.
27
+ #
28
+ class VSTS < CI
29
+ class << self
30
+ def github_slug(env)
31
+ env["BUILD_REPOSITORY_NAME"]
32
+ end
33
+
34
+ def vsts_slug(env)
35
+ project_name = env["SYSTEM_TEAMPROJECT"]
36
+ repo_name = env["BUILD_REPOSITORY_NAME"]
37
+
38
+ "#{project_name}/#{repo_name}"
39
+ end
40
+ end
41
+
42
+ def self.validates_as_ci?(env)
43
+ has_all_variables = ["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", "BUILD_REPOSITORY_PROVIDER"].all? { |x| env[x] && !env[x].empty? }
44
+
45
+ is_support_source_control = ["GitHub", "TfsGit"].include?(env["BUILD_REPOSITORY_PROVIDER"])
46
+
47
+ has_all_variables && is_support_source_control
48
+ end
49
+
50
+ def self.validates_as_pr?(env)
51
+ has_all_variables = ["BUILD_SOURCEBRANCH", "BUILD_REPOSITORY_URI", "BUILD_REASON", "BUILD_REPOSITORY_NAME"].all? { |x| env[x] && !env[x].empty? }
52
+
53
+ has_all_variables && env["BUILD_REASON"] == "PullRequest"
54
+ end
55
+
56
+ def supported_request_sources
57
+ @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::VSTS]
58
+ end
59
+
60
+ def initialize(env)
61
+ case env["BUILD_REPOSITORY_PROVIDER"]
62
+ when "GitHub"
63
+ self.repo_slug = self.class.github_slug(env)
64
+ when "TfsGit"
65
+ self.repo_slug = self.class.vsts_slug(env)
66
+ end
67
+
68
+ repo_matches = env["BUILD_SOURCEBRANCH"].match(%r{refs\/pull\/([0-9]+)\/merge})
69
+ self.pull_request_id = repo_matches[1] unless repo_matches.nil?
70
+ self.repo_url = env["BUILD_REPOSITORY_URI"]
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,48 @@
1
+ # Following the advice from @czechboy0 https://github.com/danger/danger/issues/171
2
+ # https://github.com/czechboy0/Buildasaur
3
+ require "danger/request_sources/github/github"
4
+
5
+ module Danger
6
+ # ### CI Setup
7
+ #
8
+ # If you're bold enough to use Xcode Bots. You will need to use [Buildasaur](https://github.com/czechboy0/Buildasaur)
9
+ # in order to work with Danger. This will set up your build environment for you, as the name of the bot contains all
10
+ # of the environment variables that Danger needs to work.
11
+ #
12
+ # With Buildasaur set up, you can edit your job to add `bundle exec danger` as a post-action build script.
13
+ #
14
+ # ### Token Setup
15
+ #
16
+ # As this is self-hosted, you will need to add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV. The alternative
17
+ # is to pass in the token as a prefix to the command `DANGER_GITHUB_API_TOKEN="123" bundle exec danger`.`.
18
+ #
19
+ class XcodeServer < CI
20
+ def self.validates_as_ci?(env)
21
+ env.key? "XCS_BOT_NAME"
22
+ end
23
+
24
+ def self.validates_as_pr?(env)
25
+ value = env["XCS_BOT_NAME"]
26
+ !value.nil? && value.include?("BuildaBot")
27
+ end
28
+
29
+ def supported_request_sources
30
+ @supported_request_sources ||= [
31
+ Danger::RequestSources::GitHub,
32
+ Danger::RequestSources::BitbucketServer,
33
+ Danger::RequestSources::BitbucketCloud
34
+ ]
35
+ end
36
+
37
+ def initialize(env)
38
+ bot_name = env["XCS_BOT_NAME"]
39
+ return if bot_name.nil?
40
+
41
+ repo_matches = bot_name.match(/\[(.+)\]/)
42
+ self.repo_slug = repo_matches[1] unless repo_matches.nil?
43
+ pull_request_id_matches = bot_name.match(/#(\d+)/)
44
+ self.pull_request_id = pull_request_id_matches[1] unless pull_request_id_matches.nil?
45
+ self.repo_url = GitRepo.new.origins # Xcode Server doesn't provide a repo url env variable :/
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,14 @@
1
+ module Danger
2
+ class RubyGemsClient
3
+ API_URL = "https://rubygems.org/api/v1/versions/danger/latest.json".freeze
4
+ DUMMY_VERSION = "0.0.0".freeze
5
+
6
+ def self.latest_danger_version
7
+ require "json"
8
+ json = JSON.parse(Faraday.get(API_URL).body)
9
+ json.fetch("version") { DUMMY_VERSION }
10
+ rescue StandardError => _e
11
+ DUMMY_VERSION
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ require "claide_plugin"
2
+ require "danger/commands/dangerfile/init"
3
+
4
+ module Danger
5
+ class DangerfileGem < DangerfileCommand
6
+ self.summary = "Create a gem-based Dangerfile quickly."
7
+ def self.description
8
+ <<-DESC
9
+ Creates a scaffold for the development of a new gem based Dangerfile
10
+ named `NAME` according to the best practices.
11
+ DESC
12
+ end
13
+ self.command = "gem"
14
+ self.arguments = [
15
+ CLAide::Argument.new("NAME", true)
16
+ ]
17
+
18
+ def initialize(argv)
19
+ @name = argv.shift_argument
20
+ prefix = "dangerfile" + "-"
21
+ unless @name.nil? || @name.empty? || @name.start_with?(prefix)
22
+ @name = prefix + @name.dup
23
+ end
24
+ @template_url = argv.shift_argument
25
+ super
26
+ end
27
+
28
+ def validate!
29
+ super
30
+ if @name.nil? || @name.empty?
31
+ help! "A name for the plugin is required."
32
+ end
33
+
34
+ help! "The plugin name cannot contain spaces." if @name =~ /\s/
35
+ end
36
+
37
+ def run
38
+ runner = CLAide::TemplateRunner.new(@name, "https://github.com/danger/dangerfile-gem-template")
39
+ runner.clone_template
40
+ runner.configure_template
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ require "danger/danger_core/dangerfile_generator"
2
+
3
+ # Mainly so we can have a nice structure for commands
4
+
5
+ module Danger
6
+ class DangerfileCommand < Runner
7
+ self.summary = "Easily create you Dangerfiles."
8
+ self.command = "dangerfile"
9
+
10
+ self.abstract_command = true
11
+ def self.options
12
+ []
13
+ end
14
+ end
15
+ end
16
+
17
+ # Just a less verbose way of doing the Dangerfile from `danger init`.
18
+
19
+ module Danger
20
+ class DangerfileInit < DangerfileCommand
21
+ self.summary = "Create an example Dangerfile."
22
+ self.command = "init"
23
+
24
+ def run
25
+ content = DangerfileGenerator.create_dangerfile(".", cork)
26
+ File.write("Dangerfile", content)
27
+ cork.puts "Created" + "./Dangerfile".green
28
+ end
29
+ end
30
+ end