danger 0.6.0 → 0.6.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bf96232696dca35c69a7d338d10bf16af6917a2
4
- data.tar.gz: e5e7f69f74d8419ce1c0f2c0df2725aa8b1874bf
3
+ metadata.gz: 583874b396b59f83aa7e2150e2a11072d7a05b1b
4
+ data.tar.gz: a5391cce92d93f75753a903cbe1d395b337af929
5
5
  SHA512:
6
- metadata.gz: c69c8d1096130a36a0749c55a6f1e7e90d2df55ee0048bfdd13d13f83760071e66c7a65ad188b3c12a4d71613f75d982698e3e7776438bc1dc3ec227a94fd445
7
- data.tar.gz: 16a07e94b369b7da16ab0bab5c4d9935c40442a3284c43985254811f92da77439d81dc8c19dbb6f4a9893f1ea89fcac6155736f9dd07f9b000b1457c1d2d31ad
6
+ metadata.gz: 4b6fc6777fcd152333dbf0cdbe4c48c23f243aa4711c51b0fc149cf2d4de20ea1dd1c8bf7f4f3864a3dd55b0e4818f4e06e9963bb079e1d3642b26804f82c727
7
+ data.tar.gz: 946a75817a7d7fd2c1966c4177cd64cf229e017c228b63dbdbab324f4f2747e1610510cfabde9e498ecfb879eca5029a85433533654c05df94cdc5d1fa266ae8
data/README.md CHANGED
@@ -38,7 +38,7 @@ bundle exec danger init
38
38
  bundle exec danger
39
39
  ```
40
40
 
41
- This will look at your `Dangerfile` and update the pull request accordingly. While you are setting up Danger, you may want to use: `--verbose` for more debug information.
41
+ This will look at your `Dangerfile` and update the pull request accordingly. While you are setting up Danger, you may want to use: `--verbose` for more debug information.
42
42
 
43
43
  ## What happens?
44
44
 
@@ -49,9 +49,9 @@ Danger runs at the end of a CI build, she will execute a `Dangerfile`. This file
49
49
    |   | Danger :no_entry_sign:
50
50
  -------------: | ------------- | ----
51
51
  :sparkles: | `lines_of_code` | The total amount of lines of code in the diff
52
- :pencil2: | `files_modified` | The list of files modified
53
- :ship: | `files_added` | The list of files added
54
- :recycle: | `files_removed` | The list of files removed
52
+ :pencil2: | `modified_files` | The list of modified files
53
+ :ship: | `added_files` | The list of added files
54
+ :recycle: | `deleted_files` | The list of removed files
55
55
  :abc: | `pr_title` | The title of the PR
56
56
  :book: | `pr_body` | The body of the PR
57
57
  :busts_in_silhouette: | `pr_author` | The author who submitted the PR
@@ -74,11 +74,11 @@ warn("PR is classed as Work in Progress") if pr_title.include? "[WIP]"
74
74
 
75
75
  ``` ruby
76
76
  # Devs shouldn't ship changes to this file
77
- fail("Developer Specific file shouldn't be changed") if files_modified.include?("Artsy/View_Controllers/App_Navigation/ARTopMenuViewController+DeveloperExtras.m")
77
+ fail("Developer Specific file shouldn't be changed") if modified_files.include?("Artsy/View_Controllers/App_Navigation/ARTopMenuViewController+DeveloperExtras.m")
78
78
 
79
79
  # Did you make analytics changes? Well you should also include a change to our analytics spec
80
- made_analytics_changes = files_modified.include?("/Artsy/App/ARAppDelegate+Analytics.m")
81
- made_analytics_specs_changes = files_modified.include?("/Artsy_Tests/Analytics_Tests/ARAppAnalyticsSpec.m")
80
+ made_analytics_changes = modified_files.include?("/Artsy/App/ARAppDelegate+Analytics.m")
81
+ made_analytics_specs_changes = modified_files.include?("/Artsy_Tests/Analytics_Tests/ARAppAnalyticsSpec.m")
82
82
  if made_analytics_changes
83
83
  fail("Analytics changes should have reflected specs changes") if !made_analytics_specs_changes
84
84
 
@@ -91,7 +91,7 @@ end
91
91
  #### Pinging people when a specific file has changed
92
92
 
93
93
  ```ruby
94
- message("@orta something changed in elan!") if files_modified.include? "/components/lib/variables/colors.json"
94
+ message("@orta something changed in elan!") if modified_files.include? "/components/lib/variables/colors.json"
95
95
  ```
96
96
 
97
97
  #### Exposing aspects of CI logs into the PR discussion
@@ -8,9 +8,9 @@ module Danger
8
8
  def self.scm
9
9
  [
10
10
  :lines_of_code,
11
- :files_modified,
12
- :files_deleted,
13
- :files_added,
11
+ :modified_files,
12
+ :deleted_files,
13
+ :added_files,
14
14
  :deletions,
15
15
  :insertions
16
16
  ]
@@ -1,6 +1,6 @@
1
1
  # For more info see: https://github.com/schacon/ruby-git
2
2
 
3
- require 'grit'
3
+ require 'git'
4
4
  require 'uri'
5
5
 
6
6
  module Danger
@@ -13,35 +13,35 @@ module Danger
13
13
  end
14
14
 
15
15
  def git
16
- @git ||= Grit::Git.new(".")
16
+ @git ||= GitRepo.new
17
17
  end
18
18
 
19
19
  def run_git(command)
20
- binary = Grit::Git.git_binary
21
- git.sh "#{binary} #{command}"
20
+ git.exec command
22
21
  end
23
22
 
24
- def initialize(*)
23
+ def initialize(env = {})
24
+ github_host = env["DANGER_GITHUB_HOST"] || "github.com"
25
+
25
26
  # get the remote URL
26
27
  remote = run_git "remote show origin -n | grep \"Fetch URL\" | cut -d ':' -f 2-"
27
28
  if remote
28
- remote_url_matches = remote.first.chomp.match(%r{github\.com(:|/)(?<repo_slug>.+/.+?)(?:\.git)?$})
29
+ remote_url_matches = remote.match(%r{#{Regexp.escape github_host}(:|/)(?<repo_slug>.+/.+?)(?:\.git)?$})
29
30
  if !remote_url_matches.nil? and remote_url_matches["repo_slug"]
30
31
  self.repo_slug = remote_url_matches["repo_slug"]
31
32
  else
32
- puts "Danger local requires a repository hosted on github."
33
+ puts "Danger local requires a repository hosted on GitHub.com or GitHub Enterprise."
33
34
  end
34
35
  end
35
36
 
36
37
  # get the most recent PR merge
37
- logs = run_git "log --since='2 weeks ago' --merges --oneline | grep \"Merge pull request\" | head -n 1"
38
- pr_merge = logs[0].strip
38
+ pr_merge = run_git "log --since='2 weeks ago' --merges --oneline | grep \"Merge pull request\" | head -n 1".strip
39
39
  if pr_merge
40
- self.pull_request_id = pr_merge.match("#[0-9]*")[0].delete("#")
40
+ self.pull_request_id = pr_merge.match("#([0-9]+)")[1]
41
41
  sha = pr_merge.split(" ")[0]
42
- parents = run_git "rev-list --parents -n 1 #{sha}"
43
- self.base_commit = parents[0].strip.split(" ")[0]
44
- self.head_commit = parents[0].strip.split(" ")[1]
42
+ parents = run_git("rev-list --parents -n 1 #{sha}").strip.split(" ")
43
+ self.base_commit = parents[0]
44
+ self.head_commit = parents[1]
45
45
  end
46
46
  end
47
47
  end
@@ -22,12 +22,14 @@ module Danger
22
22
  dm.env = EnvironmentManager.new(ENV)
23
23
 
24
24
  source = dm.env.ci_source
25
- unless source.repo_slug
26
- puts "danger local".red " failed because it only works with GitHub projects at the moment. Sorry."
25
+ if source.nil? or source.repo_slug.empty?
26
+ puts "danger local failed because it only works with GitHub projects at the moment. Sorry.".red
27
27
  exit 0
28
28
  end
29
29
 
30
- puts "Running your Dangerfile against this PR - https://github.com/#{source.repo_slug}/pull/#{source.pull_request_id}"
30
+ gh = dm.env.request_source
31
+
32
+ puts "Running your Dangerfile against this PR - https://#{gh.github_host}/#{source.repo_slug}/pull/#{source.pull_request_id}"
31
33
 
32
34
  if verbose != true
33
35
  puts "Turning on --verbose"
@@ -36,7 +38,6 @@ module Danger
36
38
 
37
39
  puts ""
38
40
 
39
- gh = GitHub.new(dm.env.ci_source, ENV)
40
41
  # We can use tokenless here, as it's running on someone's computer
41
42
  # and is IP locked, as opposed to on the CI.
42
43
  gh.support_tokenless_auth = true
@@ -33,17 +33,20 @@ module Danger
33
33
  dm.verbose = verbose
34
34
  dm.env = EnvironmentManager.new(ENV)
35
35
  return unless dm.env.ci_source # if it's not a PR
36
- dm.env.fill_environment_vars
37
36
 
38
- gh = dm.env.request_source
39
- ci_base = @base || gh.base_commit
40
- ci_head = @head || gh.head_commit
37
+ dm.env.fill_environment_vars
38
+ dm.env.ensure_danger_branches_are_setup
41
39
 
40
+ # Offer the chance for a user to specify a branch through the command line
41
+ ci_base = @base || dm.env.danger_head_branch
42
+ ci_head = @head || dm.env.danger_base_branch
42
43
  dm.env.scm.diff_for_folder(".", from: ci_base, to: ci_head)
43
44
 
44
45
  dm.parse Pathname.new(@dangerfile_path)
45
46
 
46
47
  post_results(dm)
48
+
49
+ dm.env.clean_up
47
50
  end
48
51
 
49
52
  def post_results(dm)
@@ -26,8 +26,8 @@ module Danger
26
26
  rows = []
27
27
 
28
28
  AvailableValues.all.each do |key|
29
- next if key == :pr_body
30
29
  value = self.send(key)
30
+ value = value.scan(/.{,80}/).to_a.each(&:strip!).join("\n") if key == :pr_body
31
31
 
32
32
  # So that we either have one value per row
33
33
  # or we have [] for an empty array
@@ -40,8 +40,8 @@ module Danger
40
40
  rows << ["SCM", env.scm.class]
41
41
  rows << ["Source", env.ci_source.class]
42
42
  rows << ["Requests", env.request_source.class]
43
- rows << ["Base Commit", env.request_source.base_commit]
44
- rows << ["Head Commit", env.request_source.head_commit]
43
+ rows << ["Base Commit", env.meta_info_for_base]
44
+ rows << ["Head Commit", env.meta_info_for_head]
45
45
 
46
46
  params = {}
47
47
  params[:rows] = rows.each { |current| current[0] = current[0].yellow }
@@ -49,8 +49,6 @@ module Danger
49
49
 
50
50
  puts ""
51
51
  puts Terminal::Table.new(params)
52
- puts "PR Body:"
53
- puts self.pr_body.cyan
54
52
  puts ""
55
53
  end
56
54
 
@@ -32,5 +32,40 @@ module Danger
32
32
 
33
33
  self.scm = GitRepo.new # For now
34
34
  end
35
+
36
+ def ensure_danger_branches_are_setup
37
+ # As this currently just works with GitHub, we can use a github specific feature here:
38
+ pull_id = ci_source.pull_request_id
39
+ test_branch = request_source.base_commit
40
+
41
+ # Next, we want to ensure that we have a version of the current branch that at a know location
42
+ scm.exec "branch #{danger_base_branch} #{test_branch}"
43
+
44
+ # OK, so we want to ensure that we have a known head branch, this will always represent
45
+ # the head ( e.g. the most recent commit that will be merged. )
46
+ scm.exec "fetch origin +refs/pull/#{pull_id}/merge:#{danger_head_branch}"
47
+ end
48
+
49
+ def clean_up
50
+ [danger_base_branch, danger_base_branch].each do |branch|
51
+ scm.exec "branch -d #{branch}"
52
+ end
53
+ end
54
+
55
+ def meta_info_for_base
56
+ scm.exec("--no-pager log #{danger_base_branch} -n1")
57
+ end
58
+
59
+ def meta_info_for_head
60
+ scm.exec("--no-pager log #{danger_head_branch} -n1")
61
+ end
62
+
63
+ def danger_head_branch
64
+ "danger_head"
65
+ end
66
+
67
+ def danger_base_branch
68
+ "danger_base"
69
+ end
35
70
  end
36
71
  end
@@ -7,7 +7,7 @@ module Danger
7
7
  def protect_files(path: nil, message: nil, fail_build: true)
8
8
  broken_rule = false
9
9
  Dir.glob(path) do |current|
10
- broken_rule = true if self.env.scm.files_modified.include?(current)
10
+ broken_rule = true if self.env.scm.modified_files.include?(current)
11
11
  end
12
12
 
13
13
  return unless broken_rule
@@ -4,7 +4,7 @@ require 'redcarpet'
4
4
 
5
5
  module Danger
6
6
  class GitHub
7
- attr_accessor :ci_source, :pr_json, :issue_json, :environment, :base_commit, :head_commit, :support_tokenless_auth, :ignored_violations
7
+ attr_accessor :ci_source, :pr_json, :issue_json, :environment, :base_commit, :head_commit, :support_tokenless_auth, :ignored_violations, :github_host
8
8
 
9
9
  def initialize(ci_source, environment)
10
10
  self.ci_source = ci_source
@@ -12,14 +12,18 @@ module Danger
12
12
  self.support_tokenless_auth = false
13
13
 
14
14
  Octokit.auto_paginate = true
15
+ @token = @environment["DANGER_GITHUB_API_TOKEN"]
16
+ self.github_host = @environment["DANGER_GITHUB_HOST"] || "github.com"
17
+ if @environment["DANGER_GITHUB_API_HOST"]
18
+ Octokit.api_endpoint = @environment["DANGER_GITHUB_API_HOST"]
19
+ end
15
20
  end
16
21
 
17
22
  def client
18
- token = @environment["DANGER_GITHUB_API_TOKEN"]
19
- raise "No API given, please provide one using `DANGER_GITHUB_API_TOKEN`" if !token && !support_tokenless_auth
23
+ raise "No API given, please provide one using `DANGER_GITHUB_API_TOKEN`" if !@token && !support_tokenless_auth
20
24
 
21
25
  @client ||= Octokit::Client.new(
22
- access_token: token
26
+ access_token: @token
23
27
  )
24
28
  end
25
29
 
@@ -52,6 +56,10 @@ module Danger
52
56
  self.pr_json[:head][:sha]
53
57
  end
54
58
 
59
+ def branch_for_merge
60
+ self.pr_json[:base][:ref]
61
+ end
62
+
55
63
  def pr_title
56
64
  self.pr_json[:title].to_s
57
65
  end
@@ -1,38 +1,42 @@
1
1
  # For more info see: https://github.com/schacon/ruby-git
2
2
 
3
- require 'grit'
3
+ require 'git'
4
4
 
5
5
  module Danger
6
6
  class GitRepo
7
7
  attr_accessor :diff
8
8
 
9
9
  def diff_for_folder(folder, from: "master", to: 'HEAD')
10
- repo = Grit::Repo.new folder
10
+ repo = Git.open folder
11
11
  self.diff = repo.diff(from, to)
12
12
  end
13
13
 
14
- def files_added
15
- @diff.select(&:new_file).map(&:b_path)
14
+ def exec(string)
15
+ `git #{string}`.strip
16
16
  end
17
17
 
18
- def files_deleted
19
- @diff.select(&:deleted_file).map(&:a_path)
18
+ def added_files
19
+ @diff.select { |diff| diff.type == "new" }.map(&:path)
20
20
  end
21
21
 
22
- def files_modified
23
- @diff.reject(&:deleted_file).reject(&:new_file).map(&:a_path)
22
+ def deleted_files
23
+ @diff.select { |diff| diff.type == "deleted" }.map(&:path)
24
+ end
25
+
26
+ def modified_files
27
+ @diff.stats[:files].keys
24
28
  end
25
29
 
26
30
  def lines_of_code
27
- @diff.map(&:diff).map(&:lines).flatten.count { |l| l.start_with?("+") || l.start_with?("-") }
31
+ @diff.lines
28
32
  end
29
33
 
30
34
  def deletions
31
- @diff.map(&:diff).map(&:lines).flatten.count { |l| l.start_with?("-") }
35
+ @diff.deletions
32
36
  end
33
37
 
34
38
  def insertions
35
- @diff.map(&:diff).map(&:lines).flatten.count { |l| l.start_with?("+") }
39
+ @diff.insertions
36
40
  end
37
41
  end
38
42
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.5"
3
3
  DESCRIPTION = "Automate your PR etiquette."
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-10 00:00:00.000000000 Z
12
+ date: 2016-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -26,19 +26,19 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: grit
29
+ name: git
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.5.0
34
+ version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 2.5.0
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: colored
44
44
  requirement: !ruby/object:Gem::Requirement