Skip to content

Commit

Permalink
Correct safe auto-correctable offense
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Nov 22, 2022
1 parent a4cf36a commit 6ff54b1
Show file tree
Hide file tree
Showing 107 changed files with 461 additions and 1,266 deletions.
745 changes: 4 additions & 741 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ end
message(":tada:") if is_version_bump && github.pr_author != "orta"

# Make a note about contributors not in the organization
unless github.api.organization_member?("danger", github.pr_author)
# Pay extra attention if they modify the gemspec
if git.modified_files.include?("*.gemspec")
warn "External contributor has edited the Gemspec"
end
# Pay extra attention if they modify the gemspec
if !github.api.organization_member?("danger", github.pr_author) && git.modified_files.include?("*.gemspec")
warn "External contributor has edited the Gemspec"
end

# Mainly to encourage writing up some reasoning about the PR, rather than
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ gem "webmock", "~> 2.1"
gem "yard", "~> 0.9.11"

if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.5.0")
gem "gitlab", "< 4.14.1"
end
gem "gitlab", "< 4.14.1"
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ end

desc "Runs chandler for current version"
task :chandler do
lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "danger/version"
if ENV["CHANDLER_GITHUB_API_TOKEN"]
Expand Down
2 changes: 1 addition & 1 deletion bin/danger
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
$LOAD_PATH.push File.expand_path("../../lib", __FILE__)
$LOAD_PATH.push File.expand_path("../lib", __dir__)

require "danger"
Danger::Runner.run ARGV
11 changes: 4 additions & 7 deletions danger.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# coding: utf-8

lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "danger/version"
Gem::Specification.new do |spec|
Expand All @@ -22,15 +20,14 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "claide", "~> 1.0"
spec.add_runtime_dependency "claide-plugins", ">= 0.9.2"
spec.add_runtime_dependency "git", "~> 1.7"
spec.add_runtime_dependency "colored2", "~> 3.1"
spec.add_runtime_dependency "cork", "~> 0.1"

This comment has been minimized.

Copy link
@almalkisaleh55
spec.add_runtime_dependency "faraday", ">= 0.9.0", "< 2.0"
spec.add_runtime_dependency "faraday-http-cache", "~> 2.0"
spec.add_runtime_dependency "git", "~> 1.7"
spec.add_runtime_dependency "kramdown", "~> 2.3"
spec.add_runtime_dependency "kramdown-parser-gfm", "~> 1.0"
spec.add_runtime_dependency "no_proxy_fix"
spec.add_runtime_dependency "octokit", "~> 5.0"
spec.add_runtime_dependency "terminal-table", ">= 1", "< 4"
spec.add_runtime_dependency "cork", "~> 0.1"
spec.add_runtime_dependency "no_proxy_fix"
end
# rubocop:enable Metrics/BlockLength
1 change: 1 addition & 0 deletions lib/danger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def self.gem_path
if Gem::Specification.find_all_by_name(GEM_NAME).empty?
raise "Couldn't find gem directory for 'danger'"
end

return Gem::Specification.find_by_name(GEM_NAME).gem_dir
end

Expand Down
142 changes: 71 additions & 71 deletions lib/danger/ci_source/appcircle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,81 @@
require "danger/request_sources/github/github"
require "danger/request_sources/gitlab"
module Danger
# ### 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*.
# https://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.
#
class Appcircle < CI
def self.validates_as_ci?(env)
env.key? "AC_APPCIRCLE"
end

def self.validates_as_pr?(env)
return false unless env.key? "AC_PULL_NUMBER"
env["AC_PULL_NUMBER"].to_i > 0
end
# ### 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*.
# https://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.
#
class Appcircle < CI
def self.validates_as_ci?(env)
env.key? "AC_APPCIRCLE"
end

def supported_request_sources
@supported_request_sources ||= [
Danger::RequestSources::GitHub,
Danger::RequestSources::BitbucketCloud,
Danger::RequestSources::BitbucketServer,
Danger::RequestSources::GitLab
]
end
def self.validates_as_pr?(env)
return false unless env.key? "AC_PULL_NUMBER"

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

def repo_slug_from(url)
if url =~ URI::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(/^(\/)/,'').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
env["AC_PULL_NUMBER"].to_i > 0
end

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

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

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

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

def repo_slug_asgiturl(url)
matcher_url = url
repo_matches = matcher_url.match(%r{([/:])(([^/]+/)+[^/]+?)(\.git$|$)})[2]
return repo_matches unless repo_matches.nil?
end
end
end
1 change: 1 addition & 0 deletions lib/danger/ci_source/appveyor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def self.validates_as_ci?(env)

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

env["APPVEYOR_PULL_REQUEST_NUMBER"].to_i > 0
end

Expand Down
6 changes: 3 additions & 3 deletions lib/danger/ci_source/azure_pipelines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class AzurePipelines < CI
def self.validates_as_ci?(env)
# AGENT_ID is being used by AppCenter as well, so checking here to make sure AppCenter CI doesn't get a false positive for AzurePipelines
# Anyone working with AzurePipelines could provide a better/truly unique env key to avoid checking for AppCenter
!Danger::Appcenter::validates_as_ci?(env) &&
env.key?("AGENT_ID") &&
env["BUILD_REPOSITORY_PROVIDER"] != "TfsGit"
!Danger::Appcenter.validates_as_ci?(env) &&
env.key?("AGENT_ID") &&
env["BUILD_REPOSITORY_PROVIDER"] != "TfsGit"
end

def self.validates_as_pr?(env)
Expand Down
2 changes: 1 addition & 1 deletion lib/danger/ci_source/bamboo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def self.validates_as_pr?(env)
def initialize(env)
self.repo_url = env["bamboo_planRepository_repositoryUrl"]
self.pull_request_id = env["bamboo_repository_pr_key"]
repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+?)(\.git$|$)})
repo_matches = self.repo_url.match(%r{([/:])([^/]+/[^/]+?)(\.git$|$)})
self.repo_slug = repo_matches[2] unless repo_matches.nil?
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/danger/ci_source/bitbucket_pipelines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Danger
# You can find them in Settings > Pipelines > Repository Variables

class BitbucketPipelines < CI

def self.validates_as_ci?(env)
env.key? "BITBUCKET_BUILD_NUMBER"
end
Expand All @@ -31,7 +30,7 @@ def supported_request_sources

def initialize(env)
self.repo_url = env["BITBUCKET_GIT_HTTP_ORIGIN"]
self.repo_slug = "#{env["BITBUCKET_REPO_OWNER"]}/#{env["BITBUCKET_REPO_SLUG"]}"
self.repo_slug = "#{env['BITBUCKET_REPO_OWNER']}/#{env['BITBUCKET_REPO_SLUG']}"
self.pull_request_id = env["BITBUCKET_PR_ID"]
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/danger/ci_source/bitrise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def initialize(env)
end

def repo_slug_from(url)
if url =~ URI::regexp
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(/^(\/)/,'').sub(/(.git)$/,'')
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)
Expand All @@ -71,7 +71,7 @@ def repo_slug_from(url)

def repo_slug_asgiturl(url)
matcher_url = url
repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
repo_matches = matcher_url.match(%r{([/:])(([^/]+/)+[^/]+?)(\.git$|$)})[2]
return repo_matches unless repo_matches.nil?
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/danger/ci_source/buildkite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize(env)
self.repo_url = env["BUILDKITE_REPO"]
self.pull_request_id = env["BUILDKITE_PULL_REQUEST"]

repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+?)(\.git$|$)})
repo_matches = self.repo_url.match(%r{([/:])([^/]+/[^/]+?)(\.git$|$)})
self.repo_slug = repo_matches[2] unless repo_matches.nil?
end

Expand Down
4 changes: 2 additions & 2 deletions lib/danger/ci_source/circle_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def fetch_pull_request_url(repo_slug, build_number, token)
build_json = fetch_build(repo_slug, build_number, token)
pull_requests = build_json[:pull_requests]
return nil unless pull_requests && pull_requests.first

pull_requests.first[:url]
end

Expand All @@ -44,8 +45,7 @@ def fetch_build(repo_slug, build_number, token)
url = "project/#{repo_slug}/#{build_number}"
params = { "circle-token" => token }
response = client.get url, params, accept: "application/json"
json = JSON.parse(response.body, symbolize_names: true)
json
JSON.parse(response.body, symbolize_names: true)
end
end
end
2 changes: 1 addition & 1 deletion lib/danger/ci_source/code_build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.extract_repo_slug(env)

gh_host = env["DANGER_GITHUB_HOST"] || "github.com"

env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}\/(.*?)(\.git)?$}, '\1')
env["CODEBUILD_SOURCE_REPO_URL"].gsub(%r{^.*?#{Regexp.escape(gh_host)}/(.*?)(\.git)?$}, '\1')
end

def self.extract_repo_url(env)
Expand Down
2 changes: 1 addition & 1 deletion lib/danger/ci_source/codefresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.slug_from(env)
end

def initialize(env)
self.repo_url = env["CF_COMMIT_URL"].to_s.gsub(/\/commit.+$/, "")
self.repo_url = env["CF_COMMIT_URL"].to_s.gsub(%r{/commit.+$}, "")
self.repo_slug = self.class.slug_from(env)
self.pull_request_id = env["CF_PULL_REQUEST_NUMBER"]
end
Expand Down
9 changes: 4 additions & 5 deletions lib/danger/ci_source/concourse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require "danger/request_sources/local_only"

module Danger
# Concourse CI Integration
#
# https://concourse-ci.org/
#
# Concourse CI Integration
#
# https://concourse-ci.org/
#
# ### CI Setup
#
# With Concourse, you run the docker images yourself, so you will want to add `yarn danger ci` within one of your build jobs.
Expand Down Expand Up @@ -56,6 +56,5 @@ def initialize(env)
end
self.repo_url = GitRepo.new.origins
end

end
end
10 changes: 4 additions & 6 deletions lib/danger/ci_source/dotci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ def self.validates_as_pr?(env)
end

def supported_request_sources
@supported_request_sources ||= begin
[
Danger::RequestSources::GitHub
]
end
@supported_request_sources ||= [
Danger::RequestSources::GitHub
]
end

def initialize(env)
self.repo_url = self.class.repo_url(env)
self.pull_request_id = self.class.pull_request_id(env)
repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+)$})
repo_matches = self.repo_url.match(%r{([/:])([^/]+/[^/]+)$})
self.repo_slug = repo_matches[2].gsub(/\.git$/, "") unless repo_matches.nil?
end

Expand Down

0 comments on commit 6ff54b1

Please sign in to comment.