danger-favro 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +152 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +23 -0
- data/danger-favro.gemspec +53 -0
- data/docs/comment-example.png +0 -0
- data/lib/danger_favro.rb +1 -0
- data/lib/danger_plugin.rb +3 -0
- data/lib/favro/api_client.rb +29 -0
- data/lib/favro/card.rb +3 -0
- data/lib/favro/gem_version.rb +3 -0
- data/lib/favro/plugin.rb +140 -0
- data/spec/favro_spec.rb +80 -0
- data/spec/fixtures/api_response.json +25 -0
- data/spec/fixtures/comment_table.html +17 -0
- data/spec/spec_helper.rb +113 -0
- metadata +265 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c882db743398b62d340dbf225f29806a194daa7
|
4
|
+
data.tar.gz: 4e826a153ed0b27a44923ce7b521b4836910af44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21ff88c28363763b24da3478257e0a2922ada01b159a5b01301192dddcb7b986e524070891ca523adc7fc8f013c35d152ff75b35299983833f750d40ed63c418
|
7
|
+
data.tar.gz: 9ed4ad4470212cfcb915608e5743435f558ab02775de2c592a815737c2b4522c5720ceeaf3520a4f67b5cd6a47c150293984778433c9475da0c88920304321be
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
# Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
2
|
+
|
3
|
+
# If you don't like these settings, just delete this file :)
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.1
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
# kind_of? is a good way to check a type
|
13
|
+
Style/ClassCheck:
|
14
|
+
EnforcedStyle: kind_of?
|
15
|
+
|
16
|
+
# It's better to be more explicit about the type
|
17
|
+
Style/BracesAroundHashParameters:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
# specs sometimes have useless assignments, which is fine
|
21
|
+
Lint/UselessAssignment:
|
22
|
+
Exclude:
|
23
|
+
- '**/spec/**/*'
|
24
|
+
|
25
|
+
# We could potentially enable the 2 below:
|
26
|
+
Layout/IndentHash:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Layout/AlignHash:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
# HoundCI doesn't like this rule
|
33
|
+
Layout/DotPosition:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# We allow !! as it's an easy way to convert ot boolean
|
37
|
+
Style/DoubleNegation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
# Cop supports --auto-correct.
|
41
|
+
Lint/UnusedBlockArgument:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
# We want to allow class Fastlane::Class
|
45
|
+
Style/ClassAndModuleChildren:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Metrics/AbcSize:
|
49
|
+
Max: 60
|
50
|
+
|
51
|
+
# The %w might be confusing for new users
|
52
|
+
Style/WordArray:
|
53
|
+
MinSize: 19
|
54
|
+
|
55
|
+
# raise and fail are both okay
|
56
|
+
Style/SignalException:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Better too much 'return' than one missing
|
60
|
+
Style/RedundantReturn:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
# Having if in the same line might not always be good
|
64
|
+
Style/IfUnlessModifier:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
# and and or is okay
|
68
|
+
Style/AndOr:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
# Configuration parameters: CountComments.
|
72
|
+
Metrics/ClassLength:
|
73
|
+
Max: 350
|
74
|
+
|
75
|
+
Metrics/CyclomaticComplexity:
|
76
|
+
Max: 17
|
77
|
+
|
78
|
+
# Configuration parameters: AllowURI, URISchemes.
|
79
|
+
Metrics/LineLength:
|
80
|
+
Max: 370
|
81
|
+
|
82
|
+
# Configuration parameters: CountKeywordArgs.
|
83
|
+
Metrics/ParameterLists:
|
84
|
+
Max: 10
|
85
|
+
|
86
|
+
Metrics/PerceivedComplexity:
|
87
|
+
Max: 18
|
88
|
+
|
89
|
+
# Sometimes it's easier to read without guards
|
90
|
+
Style/GuardClause:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
# something = if something_else
|
94
|
+
# that's confusing
|
95
|
+
Style/ConditionalAssignment:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
# Better to have too much self than missing a self
|
99
|
+
Style/RedundantSelf:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
Metrics/MethodLength:
|
103
|
+
Max: 60
|
104
|
+
|
105
|
+
# We're not there yet
|
106
|
+
Style/Documentation:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# Adds complexity
|
110
|
+
Style/IfInsideElse:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
# danger specific
|
114
|
+
|
115
|
+
Style/BlockComments:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
Layout/MultilineMethodCallIndentation:
|
119
|
+
EnforcedStyle: indented
|
120
|
+
|
121
|
+
# FIXME: 25
|
122
|
+
Metrics/BlockLength:
|
123
|
+
Max: 345
|
124
|
+
Exclude:
|
125
|
+
- "**/*_spec.rb"
|
126
|
+
|
127
|
+
Style/MixinGrouping:
|
128
|
+
Enabled: false
|
129
|
+
|
130
|
+
Naming/FileName:
|
131
|
+
Enabled: false
|
132
|
+
|
133
|
+
Layout/IndentHeredoc:
|
134
|
+
Enabled: false
|
135
|
+
|
136
|
+
Style/SpecialGlobalVars:
|
137
|
+
Enabled: false
|
138
|
+
|
139
|
+
PercentLiteralDelimiters:
|
140
|
+
PreferredDelimiters:
|
141
|
+
"%": ()
|
142
|
+
"%i": ()
|
143
|
+
"%q": ()
|
144
|
+
"%Q": ()
|
145
|
+
"%r": "{}"
|
146
|
+
"%s": ()
|
147
|
+
"%w": ()
|
148
|
+
"%W": ()
|
149
|
+
"%x": ()
|
150
|
+
|
151
|
+
Security/YAMLLoad:
|
152
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# A guardfile for making Danger Plugins
|
2
|
+
# For more info see https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# To run, use `bundle exec guard`.
|
5
|
+
|
6
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
7
|
+
require "guard/rspec/dsl"
|
8
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017 <>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# danger-favro
|
2
|
+
[![Build Status](https://img.shields.io/travis/fwal/danger-favro.svg)](https://travis-ci.org/fwal/danger-favro)
|
3
|
+
[![Coveralls](https://img.shields.io/coveralls/fwal/danger-favro.svg)](https://coveralls.io/github/fwal/danger-favro)
|
4
|
+
[![Gem](https://img.shields.io/gem/v/danger-favro.svg)](http://rubygems.org/gems/danger-favro)
|
5
|
+
|
6
|
+
A [Danger](http://danger.systems) plugin that detect [Favro](https://favro.com) cards referenced in code or PR title and displays basic information about them.
|
7
|
+
|
8
|
+
### Example
|
9
|
+
|
10
|
+
<img alt="Example" src="docs/comment-example.png" />
|
11
|
+
|
12
|
+
### Usage
|
13
|
+
|
14
|
+
<blockquote>Initiate the check
|
15
|
+
<pre>
|
16
|
+
favro.check(
|
17
|
+
user_name: "api-user",
|
18
|
+
api_token: "api-token",
|
19
|
+
organization_id: "org-id",
|
20
|
+
key: "Test"
|
21
|
+
)</pre>
|
22
|
+
</blockquote>
|
23
|
+
|
24
|
+
<blockquote>Environment variables can also be used.
|
25
|
+
<pre>
|
26
|
+
ENV["DANGER_FAVRO_USER_NAME"] = "api-user"
|
27
|
+
ENV["DANGER_FAVRO_API_TOKEN"] = "api-token"
|
28
|
+
ENV["DANGER_FAVRO_ORGANIZATION_ID"] = "org-id"
|
29
|
+
|
30
|
+
favro.check(key: "Test")</pre>
|
31
|
+
</blockquote>
|
32
|
+
|
33
|
+
|
34
|
+
#### Methods
|
35
|
+
|
36
|
+
`check` - Check for cards.
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
1. Clone this repo
|
41
|
+
2. Run `bundle install` to setup dependencies.
|
42
|
+
3. Run `bundle exec rake spec` to run the tests.
|
43
|
+
4. Use `bundle exec guard` to automatically have tests run as you make changes.
|
44
|
+
5. Make your changes.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "rubocop/rake_task"
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:specs)
|
6
|
+
|
7
|
+
task default: :specs
|
8
|
+
|
9
|
+
task :spec do
|
10
|
+
Rake::Task["specs"].invoke
|
11
|
+
Rake::Task["rubocop"].invoke
|
12
|
+
Rake::Task["spec_docs"].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Run RuboCop on the lib/specs directory"
|
16
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
17
|
+
task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Ensure that the plugin passes `danger plugins lint`"
|
21
|
+
task :spec_docs do
|
22
|
+
sh "bundle exec danger plugins lint"
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "favro/gem_version.rb"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "danger-favro"
|
8
|
+
spec.version = Favro::VERSION
|
9
|
+
spec.authors = ["Frederik Wallner"]
|
10
|
+
spec.email = ["frederik.wallner@gmail.com"]
|
11
|
+
spec.description = "Detect Favro cards in PRs"
|
12
|
+
spec.summary = "A Danger plugin that detect Favro cards referenced in code or PR title and displays basic information about them."
|
13
|
+
spec.homepage = "https://github.com/fwal/danger-favro"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
|
22
|
+
spec.add_runtime_dependency "json", "~> 2.1.0"
|
23
|
+
spec.add_runtime_dependency "rest-client", "~> 2.0"
|
24
|
+
|
25
|
+
# General ruby development
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
|
29
|
+
# Testing support
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
31
|
+
spec.add_development_dependency "webmock", "~>3.1.0"
|
32
|
+
|
33
|
+
# Linting code and docs
|
34
|
+
spec.add_development_dependency "coveralls", "~> 0.8.21"
|
35
|
+
spec.add_development_dependency "rubocop", "~> 0.41"
|
36
|
+
spec.add_development_dependency "yard", "~> 0.8"
|
37
|
+
|
38
|
+
# Makes testing easy via `bundle exec guard`
|
39
|
+
spec.add_development_dependency "guard", "~> 2.14"
|
40
|
+
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
41
|
+
|
42
|
+
# If you want to work on older builds of ruby
|
43
|
+
spec.add_development_dependency "listen", "3.0.7"
|
44
|
+
|
45
|
+
# This gives you the chance to run a REPL inside your tests
|
46
|
+
# via:
|
47
|
+
#
|
48
|
+
# require 'pry'
|
49
|
+
# binding.pry
|
50
|
+
#
|
51
|
+
# This will stop test execution and let you inspect the results
|
52
|
+
spec.add_development_dependency "pry"
|
53
|
+
end
|
Binary file
|
data/lib/danger_favro.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "favro/gem_version"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rest-client"
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
class ApiClient
|
5
|
+
def initialize(user_name, api_token, organization_id)
|
6
|
+
@user_name = user_name
|
7
|
+
@api_token = api_token
|
8
|
+
@organization_id = organization_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(card_ids)
|
12
|
+
cards = []
|
13
|
+
card_ids.each do |id|
|
14
|
+
response = request(id)
|
15
|
+
cards << Card.new(id, response.nil? ? "<i>(unknown)</i>" : response["entities"][0]["name"])
|
16
|
+
end
|
17
|
+
cards
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def request(card_id)
|
23
|
+
response = RestClient::Request.execute method: :get, url: "https://favro.com/api/v1/cards?cardSequentialId=#{card_id}&unique=true&limit=1", headers: { accept: :json, organizationId: @organization_id }, user: @user_name, password: @api_token
|
24
|
+
JSON.parse(response)
|
25
|
+
rescue RestClient::ExceptionWithResponse
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/favro/card.rb
ADDED
data/lib/favro/plugin.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
module Danger
|
2
|
+
# This is a danger plugin that detects Favro cards in added code and pr titles
|
3
|
+
#
|
4
|
+
# @example Initiate the check
|
5
|
+
#
|
6
|
+
# favro.check(
|
7
|
+
# user_name: "api-user",
|
8
|
+
# api_token: "api-token",
|
9
|
+
# organization_id: "org-id",
|
10
|
+
# key: "Test"
|
11
|
+
# )
|
12
|
+
#
|
13
|
+
# @example Environment variables can also be used.
|
14
|
+
#
|
15
|
+
# ENV["DANGER_FAVRO_USER_NAME"] = "api-user"
|
16
|
+
# ENV["DANGER_FAVRO_API_TOKEN"] = "api-token"
|
17
|
+
# ENV["DANGER_FAVRO_ORGANIZATION_ID"] = "org-id"
|
18
|
+
#
|
19
|
+
# favro.check(key: "Test")
|
20
|
+
#
|
21
|
+
#
|
22
|
+
# @see /danger-favro
|
23
|
+
# @tags favro issues cards
|
24
|
+
class DangerFavro < Plugin
|
25
|
+
# Check for cards.
|
26
|
+
#
|
27
|
+
# @param [String] user_name
|
28
|
+
# @param [String] api_token
|
29
|
+
# @param [String] organization_id
|
30
|
+
# @param [String] key
|
31
|
+
# @return [void]
|
32
|
+
def check(user_name: nil, api_token: nil, organization_id: nil, key: nil)
|
33
|
+
return unless setup(user_name, api_token, organization_id, key)
|
34
|
+
|
35
|
+
ids = find_card_ids([title] + file_additions)
|
36
|
+
|
37
|
+
return if ids.empty?
|
38
|
+
|
39
|
+
client = ApiClient.new(@user_name, @api_token, @organization_id)
|
40
|
+
cards = client.get(ids)
|
41
|
+
|
42
|
+
render_table(cards)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def setup(user_name, api_token, organization_id, key)
|
48
|
+
@user_name = user_name || ENV["DANGER_FAVRO_USER_NAME"]
|
49
|
+
@api_token = api_token || ENV["DANGER_FAVRO_API_TOKEN"]
|
50
|
+
@organization_id = organization_id || ENV["DANGER_FAVRO_ORGANIZATION_ID"]
|
51
|
+
@key = key || ENV["DANGER_FAVRO_KEY"]
|
52
|
+
@issue_pattern = /(?<card>(#{@key})-(\d+))+/i
|
53
|
+
|
54
|
+
is_valid = true
|
55
|
+
if @user_name.nil? || @user_name.empty?
|
56
|
+
is_valid = false
|
57
|
+
fail("Danger Favro plugin: Missing `user_name`")
|
58
|
+
end
|
59
|
+
|
60
|
+
if @api_token.nil? || @api_token.empty?
|
61
|
+
is_valid = false
|
62
|
+
fail("Danger Favro plugin: Missing `api_token`")
|
63
|
+
end
|
64
|
+
|
65
|
+
if @organization_id.nil? || @organization_id.empty?
|
66
|
+
is_valid = false
|
67
|
+
fail("Danger Favro plugin: Missing `organization_id`")
|
68
|
+
end
|
69
|
+
|
70
|
+
if @key.nil? || @key.empty?
|
71
|
+
is_valid = false
|
72
|
+
fail("Danger Favro plugin: Missing `key`")
|
73
|
+
end
|
74
|
+
|
75
|
+
is_valid
|
76
|
+
end
|
77
|
+
|
78
|
+
def title
|
79
|
+
case danger.scm_provider
|
80
|
+
when :github
|
81
|
+
github.pr_title
|
82
|
+
when :bitbucket_server
|
83
|
+
bitbucket_server.pr_title
|
84
|
+
when :bitbucket_cloud
|
85
|
+
bitbucket_cloud.pr_title
|
86
|
+
when :vsts
|
87
|
+
vsts.pr_title
|
88
|
+
when :gitlab
|
89
|
+
gitlab.mr_title
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def file_additions
|
94
|
+
additions = []
|
95
|
+
(git.modified_files + git.added_files).each do |file|
|
96
|
+
additions += git.diff_for_file(file).patch.scan(/^\+.+/)
|
97
|
+
end
|
98
|
+
additions
|
99
|
+
end
|
100
|
+
|
101
|
+
def find_card_ids(list)
|
102
|
+
matches = []
|
103
|
+
|
104
|
+
list.each do |item|
|
105
|
+
matches += item.scan(@issue_pattern).flatten
|
106
|
+
end
|
107
|
+
|
108
|
+
matches.uniq.collect(&:upcase)
|
109
|
+
end
|
110
|
+
|
111
|
+
def render_table(cards)
|
112
|
+
table = "
|
113
|
+
<table>
|
114
|
+
<thead>
|
115
|
+
<tr>
|
116
|
+
<th width=\"10%\">
|
117
|
+
</th>
|
118
|
+
<th width=\"50%\">
|
119
|
+
#{cards.length} Favro card#{cards.length > 1 ? 's' : ''} referenced
|
120
|
+
</th>
|
121
|
+
</tr>
|
122
|
+
</thead>
|
123
|
+
<tbody>
|
124
|
+
"
|
125
|
+
table << cards.map { |card| render_row(card) }.join("\n")
|
126
|
+
table << "
|
127
|
+
</tbody>
|
128
|
+
</table>"
|
129
|
+
|
130
|
+
markdown table
|
131
|
+
end
|
132
|
+
|
133
|
+
def render_row(card)
|
134
|
+
" <tr>
|
135
|
+
<td><a href=\"https://favro.com/card/#{@organization_id}/#{card.id}\">#{card.id}</a></td>
|
136
|
+
<td>#{card.name}</td>
|
137
|
+
</tr>"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/spec/favro_spec.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
describe Danger::DangerFavro do
|
5
|
+
it "should be a plugin" do
|
6
|
+
expect(Danger::DangerFavro.new(nil)).to be_a Danger::Plugin
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with Dangerfile without configuration" do
|
10
|
+
before do
|
11
|
+
@dangerfile = testing_dangerfile
|
12
|
+
@my_plugin = @dangerfile.favro
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should throw errors when missing values" do
|
16
|
+
@my_plugin.check
|
17
|
+
errors = [
|
18
|
+
"Danger Favro plugin: Missing `user_name`",
|
19
|
+
"Danger Favro plugin: Missing `api_token`",
|
20
|
+
"Danger Favro plugin: Missing `organization_id`",
|
21
|
+
"Danger Favro plugin: Missing `key`"
|
22
|
+
]
|
23
|
+
expect(@dangerfile.status_report[:errors]).to eq(errors)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with Dangerfile" do
|
28
|
+
before do
|
29
|
+
@dangerfile = testing_dangerfile
|
30
|
+
@my_plugin = @dangerfile.favro
|
31
|
+
|
32
|
+
ENV["DANGER_FAVRO_USER_NAME"] = "test_user"
|
33
|
+
ENV["DANGER_FAVRO_API_TOKEN"] = "test_token"
|
34
|
+
ENV["DANGER_FAVRO_ORGANIZATION_ID"] = "test_org"
|
35
|
+
ENV["DANGER_FAVRO_KEY"] = "test"
|
36
|
+
|
37
|
+
testing_pr_title(@dangerfile)
|
38
|
+
testing_changes(@dangerfile)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not throw errors if configured" do
|
42
|
+
@my_plugin.check
|
43
|
+
expect(@dangerfile.status_report[:errors]).to eq([])
|
44
|
+
end
|
45
|
+
|
46
|
+
it "detects cards in added lines" do
|
47
|
+
testing_changes(@dangerfile, added_text: "//TEST-123")
|
48
|
+
testing_api_request("TEST-123")
|
49
|
+
|
50
|
+
@my_plugin.check
|
51
|
+
expect(@dangerfile.status_report[:markdowns][0].message.delete("\n")).to eq(comment_table)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "doesn't detect cards in removed lines" do
|
55
|
+
testing_changes(@dangerfile, modified_text: "//TEST-1234")
|
56
|
+
|
57
|
+
@my_plugin.check
|
58
|
+
expect(@dangerfile.status_report[:markdowns]).to eq([])
|
59
|
+
end
|
60
|
+
|
61
|
+
it "retrieves the name of detected cards" do
|
62
|
+
testing_changes(@dangerfile, added_text: "//TEST-123")
|
63
|
+
testing_api_request("TEST-123")
|
64
|
+
|
65
|
+
@my_plugin.check
|
66
|
+
expect(@dangerfile.status_report[:markdowns][0].message.delete("\n")).to eq(comment_table)
|
67
|
+
end
|
68
|
+
|
69
|
+
context "on GitHub PR" do
|
70
|
+
it "detects Favro card in PR title" do
|
71
|
+
testing_pr_title(@dangerfile, "TEST-123")
|
72
|
+
testing_api_request("TEST-123")
|
73
|
+
|
74
|
+
@my_plugin.check
|
75
|
+
expect(@dangerfile.status_report[:markdowns][0].message.delete("\n")).to eq(comment_table)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"limit": 1,
|
3
|
+
"page": 0,
|
4
|
+
"pages": 1,
|
5
|
+
"requestId": "8cc57b1d8a218fa639c8a0fa",
|
6
|
+
"entities": [{
|
7
|
+
"cardId": "67973f72db34592d8fc96c48",
|
8
|
+
"organizationId": "zk4CJpg5uozhL4R2W",
|
9
|
+
"widgetCommonId": "ff440e8f358c08513a86c8d6",
|
10
|
+
"columnId": "b4d8c6283d9d58f9a39108e7",
|
11
|
+
"name": "This is a card",
|
12
|
+
"customFields": [{
|
13
|
+
"customFieldId": "kj4qQzhLMJ73dybBR",
|
14
|
+
"total": 50400000,
|
15
|
+
"reports": {
|
16
|
+
"XTdS5bP6qX9Ta3rwt": {
|
17
|
+
"reportId": "29ed6478b55f90d91c5f4727",
|
18
|
+
"createdAt": "2016-01-13T00:00:00.000Z",
|
19
|
+
"value": 50400000,
|
20
|
+
"description": "Timesheet report description"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}]
|
24
|
+
}]
|
25
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<table>
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th width="10%">
|
5
|
+
</th>
|
6
|
+
<th width="50%">
|
7
|
+
1 Favro card referenced
|
8
|
+
</th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
<tbody>
|
12
|
+
<tr>
|
13
|
+
<td><a href="https://favro.com/card/test_org/TEST-123">TEST-123</a></td>
|
14
|
+
<td>This is a card</td>
|
15
|
+
</tr>
|
16
|
+
</tbody>
|
17
|
+
</table>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require "pathname"
|
2
|
+
ROOT = Pathname.new(File.expand_path("../../", __FILE__))
|
3
|
+
$:.unshift((ROOT + "lib").to_s)
|
4
|
+
$:.unshift((ROOT + "spec").to_s)
|
5
|
+
|
6
|
+
require "bundler/setup"
|
7
|
+
require "pry"
|
8
|
+
|
9
|
+
require "rspec"
|
10
|
+
require "danger"
|
11
|
+
|
12
|
+
require "webmock/rspec"
|
13
|
+
|
14
|
+
require "coveralls"
|
15
|
+
Coveralls.wear!
|
16
|
+
|
17
|
+
if `git remote -v` == ""
|
18
|
+
puts "You cannot run tests without setting a local git remote on this repo"
|
19
|
+
puts "It's a weird side-effect of Danger's internals."
|
20
|
+
exit(0)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Use coloured output, it's the best.
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.filter_gems_from_backtrace "bundler"
|
26
|
+
config.color = true
|
27
|
+
config.tty = true
|
28
|
+
end
|
29
|
+
|
30
|
+
require "danger_plugin"
|
31
|
+
|
32
|
+
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
33
|
+
# If you are expanding these files, see if it's already been done ^.
|
34
|
+
|
35
|
+
# A silent version of the user interface,
|
36
|
+
# it comes with an extra function `.string` which will
|
37
|
+
# strip all ANSI colours from the string.
|
38
|
+
|
39
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
40
|
+
def testing_ui
|
41
|
+
@output = StringIO.new
|
42
|
+
def @output.winsize
|
43
|
+
[20, 9999]
|
44
|
+
end
|
45
|
+
|
46
|
+
cork = Cork::Board.new(out: @output)
|
47
|
+
def cork.string
|
48
|
+
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
49
|
+
end
|
50
|
+
cork
|
51
|
+
end
|
52
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
53
|
+
|
54
|
+
# Example environment (ENV) that would come from
|
55
|
+
# running a PR on TravisCI
|
56
|
+
def testing_env
|
57
|
+
{
|
58
|
+
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
|
59
|
+
"TRAVIS_PULL_REQUEST" => "800",
|
60
|
+
"TRAVIS_REPO_SLUG" => "artsy/eigen",
|
61
|
+
"TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
|
62
|
+
"DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# A stubbed out Dangerfile for use in tests
|
67
|
+
def testing_dangerfile
|
68
|
+
env = Danger::EnvironmentManager.new(testing_env)
|
69
|
+
Danger::Dangerfile.new(env, testing_ui)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Sets pr title
|
73
|
+
def testing_pr_title(dangerfile, title = "A title")
|
74
|
+
allow(dangerfile.github).to receive(:pr_title).and_return(title)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Prepares tests for an api request
|
78
|
+
def testing_api_request(id)
|
79
|
+
fixture = File.read(File.expand_path("../fixtures/api_response.json", __FILE__))
|
80
|
+
stub_request(:get, "https://favro.com/api/v1/cards?cardSequentialId=#{id}&unique=true&limit=1")
|
81
|
+
.to_return(body: fixture, status: 200)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Sets git changes
|
85
|
+
def testing_changes(dangerfile, added_text: "//new", modified_text: "//modified")
|
86
|
+
modified = Git::Diff::DiffFile.new(
|
87
|
+
"base",
|
88
|
+
path: "modified_dummy.rb",
|
89
|
+
patch: "- #{modified_text}"
|
90
|
+
)
|
91
|
+
added = Git::Diff::DiffFile.new(
|
92
|
+
"base",
|
93
|
+
path: "new_dummy.rb",
|
94
|
+
patch: "+ #{added_text}"
|
95
|
+
)
|
96
|
+
|
97
|
+
allow(dangerfile.git).to receive(:diff_for_file)
|
98
|
+
.with("modified_dummy.rb").and_return(modified)
|
99
|
+
|
100
|
+
allow(dangerfile.git).to receive(:diff_for_file)
|
101
|
+
.with("new_dummy.rb").and_return(added)
|
102
|
+
|
103
|
+
allow(dangerfile.git).to receive(:modified_files)
|
104
|
+
.and_return(["modified_dummy.rb"])
|
105
|
+
|
106
|
+
allow(dangerfile.git).to receive(:added_files)
|
107
|
+
.and_return(["new_dummy.rb"])
|
108
|
+
end
|
109
|
+
|
110
|
+
# Comment table fixture
|
111
|
+
def comment_table
|
112
|
+
File.read(File.expand_path("../fixtures/comment_table.html", __FILE__)).delete("\n")
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danger-favro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frederik Wallner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: danger-plugin-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.1.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.1.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.21
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.8.21
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.41'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.41'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.8'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: guard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.14'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '2.14'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: guard-rspec
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '4.7'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '4.7'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: listen
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 3.0.7
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 3.0.7
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: pry
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
description: Detect Favro cards in PRs
|
210
|
+
email:
|
211
|
+
- frederik.wallner@gmail.com
|
212
|
+
executables: []
|
213
|
+
extensions: []
|
214
|
+
extra_rdoc_files: []
|
215
|
+
files:
|
216
|
+
- ".gitignore"
|
217
|
+
- ".rubocop.yml"
|
218
|
+
- ".travis.yml"
|
219
|
+
- Gemfile
|
220
|
+
- Guardfile
|
221
|
+
- LICENSE.txt
|
222
|
+
- README.md
|
223
|
+
- Rakefile
|
224
|
+
- danger-favro.gemspec
|
225
|
+
- docs/comment-example.png
|
226
|
+
- lib/danger_favro.rb
|
227
|
+
- lib/danger_plugin.rb
|
228
|
+
- lib/favro/api_client.rb
|
229
|
+
- lib/favro/card.rb
|
230
|
+
- lib/favro/gem_version.rb
|
231
|
+
- lib/favro/plugin.rb
|
232
|
+
- spec/favro_spec.rb
|
233
|
+
- spec/fixtures/api_response.json
|
234
|
+
- spec/fixtures/comment_table.html
|
235
|
+
- spec/spec_helper.rb
|
236
|
+
homepage: https://github.com/fwal/danger-favro
|
237
|
+
licenses:
|
238
|
+
- MIT
|
239
|
+
metadata: {}
|
240
|
+
post_install_message:
|
241
|
+
rdoc_options: []
|
242
|
+
require_paths:
|
243
|
+
- lib
|
244
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
245
|
+
requirements:
|
246
|
+
- - ">="
|
247
|
+
- !ruby/object:Gem::Version
|
248
|
+
version: '0'
|
249
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
|
+
requirements:
|
251
|
+
- - ">="
|
252
|
+
- !ruby/object:Gem::Version
|
253
|
+
version: '0'
|
254
|
+
requirements: []
|
255
|
+
rubyforge_project:
|
256
|
+
rubygems_version: 2.6.14
|
257
|
+
signing_key:
|
258
|
+
specification_version: 4
|
259
|
+
summary: A Danger plugin that detect Favro cards referenced in code or PR title and
|
260
|
+
displays basic information about them.
|
261
|
+
test_files:
|
262
|
+
- spec/favro_spec.rb
|
263
|
+
- spec/fixtures/api_response.json
|
264
|
+
- spec/fixtures/comment_table.html
|
265
|
+
- spec/spec_helper.rb
|