danger 0.9.0 → 0.9.1
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 +4 -4
- data/lib/danger/ci_source/local_git_repo.rb +3 -3
- data/lib/danger/commands/plugins/plugin_json.rb +40 -0
- data/lib/danger/commands/plugins/plugin_lint.rb +7 -1
- data/lib/danger/commands/runner.rb +1 -0
- data/lib/danger/plugin_support/plugin_linter.rb +154 -0
- data/lib/danger/plugin_support/plugin_parser.rb +7 -2
- data/lib/danger/scm_source/git_repo.rb +1 -1
- data/lib/danger/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e02bc78c88ffbdd9d2c7c7b4abd87939c2a76837
|
4
|
+
data.tar.gz: 173e0a2993c408b5b6e53c379239e97228839bc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001cd98d2bd528920fd6aafffea0aca00b41672e32e52588ba30f1eb2e9614cd246bf066f7ced68bbe6ec289f90e0c03774ea8e6d075de1ced383f20909a8854
|
7
|
+
data.tar.gz: 65669c564bcae4590b3bc384b5d3a96c16b74404e48d4489eaef4cc6d17a8a53270db8e5cfa3969579c3bac5176b47187de777f31012b92dcc52b660a5b59591
|
@@ -28,7 +28,7 @@ module Danger
|
|
28
28
|
github_host = env["DANGER_GITHUB_HOST"] || "github.com"
|
29
29
|
|
30
30
|
# get the remote URL
|
31
|
-
remote = run_git
|
31
|
+
remote = run_git("remote show origin -n").lines.grep(/Fetch URL/)[0].split(": ", 2)[1]
|
32
32
|
if remote
|
33
33
|
remote_url_matches = remote.match(%r{#{Regexp.escape github_host}(:|/)(?<repo_slug>.+/.+?)(?:\.git)?$})
|
34
34
|
if !remote_url_matches.nil? and remote_url_matches["repo_slug"]
|
@@ -40,10 +40,10 @@ module Danger
|
|
40
40
|
|
41
41
|
specific_pr = env["LOCAL_GIT_PR_ID"]
|
42
42
|
pr_ref = specific_pr ? "##{specific_pr}" : ""
|
43
|
-
pr_command = "log --merges --oneline
|
43
|
+
pr_command = "log --merges --oneline"
|
44
44
|
|
45
45
|
# get the most recent PR merge
|
46
|
-
pr_merge = run_git
|
46
|
+
pr_merge = run_git(pr_command.strip).lines.grep(Regexp.new("Merge pull request " + pr_ref))[0]
|
47
47
|
|
48
48
|
if pr_merge.to_s.empty?
|
49
49
|
if specific_pr
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "danger/plugin_support/plugin_parser"
|
2
|
+
require "danger/plugin_support/plugin_file_resolver"
|
3
|
+
|
4
|
+
module Danger
|
5
|
+
class PluginJSON < CLAide::Command::Plugins
|
6
|
+
self.summary = "Prints the JSON documentation representing a plugin"
|
7
|
+
self.command = "json"
|
8
|
+
|
9
|
+
attr_accessor :cork
|
10
|
+
|
11
|
+
def initialize(argv)
|
12
|
+
@refs = argv.arguments! unless argv.arguments.empty?
|
13
|
+
@cork = Cork::Board.new(silent: argv.option("silent", false),
|
14
|
+
verbose: argv.option("verbose", false))
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
self.summary = "Lint plugins from files, gems or the current folder. Outputs JSON array representation of Plugins on success."
|
19
|
+
|
20
|
+
self.description = <<-DESC
|
21
|
+
Converts a collection of file paths of Danger plugins into a JSON format.
|
22
|
+
Note: Before 1.0, it will also parse the represented JSON to validate whether http://danger.systems would
|
23
|
+
show the plugin on the website.
|
24
|
+
DESC
|
25
|
+
|
26
|
+
self.arguments = [
|
27
|
+
CLAide::Argument.new("Paths, Gems or Nothing", false, true)
|
28
|
+
]
|
29
|
+
|
30
|
+
def run
|
31
|
+
file_resolver = PluginFileResolver.new(@refs)
|
32
|
+
paths = file_resolver.resolve_to_paths
|
33
|
+
|
34
|
+
parser = PluginParser.new(paths)
|
35
|
+
parser.parse
|
36
|
+
json = parser.to_json_string
|
37
|
+
cork.puts json
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "danger/plugin_support/plugin_parser"
|
2
2
|
require "danger/plugin_support/plugin_file_resolver"
|
3
|
+
require "danger/plugin_support/plugin_linter"
|
3
4
|
|
4
5
|
module Danger
|
5
6
|
class PluginLint < CLAide::Command::Plugins
|
@@ -34,7 +35,12 @@ module Danger
|
|
34
35
|
parser = PluginParser.new(paths)
|
35
36
|
parser.parse
|
36
37
|
json = parser.to_json
|
37
|
-
|
38
|
+
|
39
|
+
linter = PluginLinter.new(json)
|
40
|
+
linter.lint
|
41
|
+
linter.print_summary(cork)
|
42
|
+
|
43
|
+
exit(1) if linter.failed?
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
@@ -13,6 +13,7 @@ module Danger
|
|
13
13
|
"https://github.com/danger/danger-plugin-template")
|
14
14
|
|
15
15
|
require "danger/commands/plugins/plugin_lint"
|
16
|
+
require "danger/commands/plugins/plugin_json"
|
16
17
|
require "danger/commands/plugins/plugin_readme"
|
17
18
|
|
18
19
|
self.summary = "Run the Dangerfile."
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module Danger
|
2
|
+
class PluginLinter
|
3
|
+
# An internal class that is used to represent a rule for the linter.
|
4
|
+
class Rule
|
5
|
+
attr_accessor :modifier, :description, :title, :function, :ref, :metadata, :type
|
6
|
+
|
7
|
+
def initialize(modifier, ref, title, description, function)
|
8
|
+
@modifier = modifier
|
9
|
+
@title = title
|
10
|
+
@description = description
|
11
|
+
@function = function
|
12
|
+
@ref = ref
|
13
|
+
end
|
14
|
+
|
15
|
+
def object_applied_to
|
16
|
+
metadata[:name].to_s.bold + " (" + type + ")"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_accessor :json, :warnings, :errors
|
21
|
+
|
22
|
+
def initialize(json)
|
23
|
+
@json = json
|
24
|
+
@warnings = []
|
25
|
+
@errors = []
|
26
|
+
end
|
27
|
+
|
28
|
+
# Lints the current JSON, looking at:
|
29
|
+
# * Class rules
|
30
|
+
# * Method rules
|
31
|
+
# * Attribute rules
|
32
|
+
#
|
33
|
+
def lint
|
34
|
+
json.each do |plugin|
|
35
|
+
apply_rules(plugin, "class", class_rules)
|
36
|
+
|
37
|
+
plugin[:methods].each do |method|
|
38
|
+
apply_rules(method, "method", method_rules)
|
39
|
+
end
|
40
|
+
|
41
|
+
plugin[:attributes].each do |method_hash|
|
42
|
+
method_name = method_hash.keys.first
|
43
|
+
method = method_hash[method_name]
|
44
|
+
|
45
|
+
value = method[:write] || method[:read]
|
46
|
+
apply_rules(value, "attribute", method_rules)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Did the linter pass/fail?
|
52
|
+
#
|
53
|
+
def failed?
|
54
|
+
errors.empty? == false
|
55
|
+
end
|
56
|
+
|
57
|
+
# Prints a summary of the errors and warnings.
|
58
|
+
#
|
59
|
+
def print_summary(ui)
|
60
|
+
# Print whether it passed/failed at the top
|
61
|
+
if failed?
|
62
|
+
ui.notice "Passed\n"
|
63
|
+
else
|
64
|
+
ui.puts "\n[!] Failed\n".red
|
65
|
+
end
|
66
|
+
|
67
|
+
# A generic proc to handle the similarities between
|
68
|
+
# erros and warnings.
|
69
|
+
do_rules = proc do |name, rules|
|
70
|
+
unless rules.empty?
|
71
|
+
ui.section(name.bold) do
|
72
|
+
rules.each do |rule|
|
73
|
+
title = rule.title.bold + " - #{rule.object_applied_to}"
|
74
|
+
ui.labeled(title, [rule.description, link(rule.ref)])
|
75
|
+
ui.puts ""
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Run the rules
|
82
|
+
do_rules.call("Errors".red, errors)
|
83
|
+
do_rules.call("Warnings".yellow, warnings)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
# Rules that apply to a class
|
89
|
+
#
|
90
|
+
def class_rules
|
91
|
+
[
|
92
|
+
Rule.new(:error, 4..6, "Description Markdown", "Above your class you need documentation that covers the scope, and the usage of your plugin.", proc do |json|
|
93
|
+
json[:body_md] && json[:body_md].empty?
|
94
|
+
end),
|
95
|
+
Rule.new(:warning, 30, "Tags", "This plugin does not include `@tags tag1, tag2` and thus will be harder to find in search.", proc do |json|
|
96
|
+
json[:tags] && json[:tags].empty?
|
97
|
+
end),
|
98
|
+
Rule.new(:warning, 29, "References", "Ideally, you have a reference implementation of your plugin that you can show to people, add `@see org/repo` to have the site auto link it.", proc do |json|
|
99
|
+
json[:see] && json[:see].empty?
|
100
|
+
end),
|
101
|
+
Rule.new(:error, 8..27, "Examples", "You should include some examples of common use-cases for your plugin.", proc do |json|
|
102
|
+
json[:example_code] && json[:example_code].empty?
|
103
|
+
end)
|
104
|
+
]
|
105
|
+
end
|
106
|
+
|
107
|
+
# Rules that apply to individual methods, and attributes
|
108
|
+
#
|
109
|
+
def method_rules
|
110
|
+
[
|
111
|
+
Rule.new(:error, 40..41, "Description", "You should include a description for your method.", proc do |json|
|
112
|
+
json[:body_md] && json[:body_md].empty?
|
113
|
+
end),
|
114
|
+
Rule.new(:warning, 43..45, "Params", "If the function has no useful return value, use ` @return [void]`.", proc do |json|
|
115
|
+
json[:param_couplets] && json[:param_couplets].flat_map(&:values).include?(nil)
|
116
|
+
end),
|
117
|
+
Rule.new(:warning, 46, "Return Type", "If the function has no useful return value, use ` @return [void]` - this will be ignored by documentation generators.", proc do |json|
|
118
|
+
json[:return] && json[:return].empty?
|
119
|
+
end)
|
120
|
+
]
|
121
|
+
end
|
122
|
+
|
123
|
+
# Generates a link to see an example of said rule
|
124
|
+
#
|
125
|
+
def link(ref)
|
126
|
+
if ref.kind_of? Range
|
127
|
+
"@see - " + "https://github.com/dbgrandi/danger-prose/blob/v2.0.0/lib/danger_plugin.rb#L#{ref.min}#-L#{ref.max}".blue
|
128
|
+
elsif ref.kind_of? Fixnum
|
129
|
+
"@see - " + "https://github.com/dbgrandi/danger-prose/blob/v2.0.0/lib/danger_plugin.rb#L#{ref}".blue
|
130
|
+
else
|
131
|
+
"@see - " + "https://github.com/dbgrandi/danger-prose/blob/v2.0.0/lib/danger_plugin.rb".blue
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Runs the rule, if it fails then additional metadata
|
136
|
+
# is added to the rule (for printing later) and it's
|
137
|
+
# added to either `warnings` or `errors`.
|
138
|
+
#
|
139
|
+
def apply_rules(json, type, rules)
|
140
|
+
rules.each do |rule|
|
141
|
+
next unless rule.function.call(json)
|
142
|
+
rule.metadata = json
|
143
|
+
rule.type = type
|
144
|
+
|
145
|
+
case rule.modifier
|
146
|
+
when :warning
|
147
|
+
warnings << rule
|
148
|
+
when :error
|
149
|
+
errors << rule
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -68,7 +68,12 @@ module Danger
|
|
68
68
|
|
69
69
|
def to_json
|
70
70
|
plugins = plugins_from_classes(classes_in_file)
|
71
|
-
|
71
|
+
to_h(plugins)
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_json_string
|
75
|
+
plugins = plugins_from_classes(classes_in_file)
|
76
|
+
to_h(plugins).to_json
|
72
77
|
end
|
73
78
|
|
74
79
|
# rubocop:disable Metrics/AbcSize
|
@@ -140,7 +145,7 @@ module Danger
|
|
140
145
|
}
|
141
146
|
end
|
142
147
|
|
143
|
-
def
|
148
|
+
def to_h(classes)
|
144
149
|
classes.map do |klass|
|
145
150
|
# Adds the class being parsed into the ruby runtime, so that we can access it's instance_name
|
146
151
|
require klass.file
|
data/lib/danger/version.rb
CHANGED
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.9.
|
4
|
+
version: 0.9.1
|
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-07-
|
12
|
+
date: 2016-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -322,6 +322,7 @@ files:
|
|
322
322
|
- lib/danger/commands/init.rb
|
323
323
|
- lib/danger/commands/init_helpers/interviewer.rb
|
324
324
|
- lib/danger/commands/local.rb
|
325
|
+
- lib/danger/commands/plugins/plugin_json.rb
|
325
326
|
- lib/danger/commands/plugins/plugin_lint.rb
|
326
327
|
- lib/danger/commands/plugins/plugin_readme.rb
|
327
328
|
- lib/danger/commands/runner.rb
|
@@ -339,6 +340,7 @@ files:
|
|
339
340
|
- lib/danger/danger_core/violation.rb
|
340
341
|
- lib/danger/plugin_support/plugin.rb
|
341
342
|
- lib/danger/plugin_support/plugin_file_resolver.rb
|
343
|
+
- lib/danger/plugin_support/plugin_linter.rb
|
342
344
|
- lib/danger/plugin_support/plugin_parser.rb
|
343
345
|
- lib/danger/plugin_support/templates/readme_table.html.erb
|
344
346
|
- lib/danger/request_source/github.rb
|