danger-lock_dependency_versions 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b24a4bf332b8de852ecf82478cadaa429be7fe9
4
+ data.tar.gz: 1df81ff4e91846d5b1c27f14e79683c5a61ef62e
5
+ SHA512:
6
+ metadata.gz: e329973e06fafb5be71bc5e5b36513cff6c719607c46f19d820c7399fa24b7c76c308a2c1e10e1654395c0daccf92299e98fc9cf86b292b61eebbbf2ebf1e732
7
+ data.tar.gz: 43ceded3ba02150392f1ea52c4b01804f2614a5a0f76cd3c72846c696411b9ecb9e819644437e28145447ce333550fb3d61ef056c62065ce7683e53ad2844a2b
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
5
+ vendor/
6
+ .bundle/
7
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.4.2
8
+
9
+ script:
10
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-lock_dependency_versions.gemspec
4
+ gemspec
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 Takuma Homma <nagomimatcha@gmail.com>
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,40 @@
1
+ [![Build Status](https://travis-ci.org/mataku/danger-lock_dependency_versions.svg?branch=master)](https://travis-ci.org/mataku/danger-lock_dependency_versions)
2
+
3
+ # danger-lock_dependency_versions
4
+
5
+ A [Danger](http://danger.systems/ruby/) plugin for managing dependency files.
6
+
7
+ Check files which should be committed to version control (e.g., `Gemfile` and `Gemfile.lock`, `Cartfile` and `Cartfile.resolved`).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your Gemfile:
12
+
13
+ ```
14
+ $ gem danger-lock_dependency_versions
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ First, create `.lock_list.yml` and add key-value pair to check.
20
+
21
+ ```yaml
22
+ Gemfile: Gemfile.lock
23
+ Cartfile: Cartfile.resolved
24
+ ```
25
+
26
+ Add to Dangerfile.
27
+
28
+ ```
29
+ lock_dependency_versions.check
30
+ ```
31
+
32
+ If lockfile has not committed to version control, post a failure comment by Danger.
33
+
34
+ ### Methods
35
+
36
+ ```
37
+ check(warning: boolean)
38
+ ```
39
+
40
+ if specify `warning: true`, set comment status to warning. (default: false)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:specs)
5
+
6
+ task default: :specs
7
+
8
+ task :spec do
9
+ Rake::Task['specs'].invoke
10
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lock_dependency_versions/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-lock_dependency_versions'
8
+ spec.version = LockDependencyVersions::VERSION
9
+ spec.authors = ['mataku']
10
+ spec.email = ['nagomimatcha@gmail.com']
11
+ spec.description = %q{A Danger plugin to check files which should be committed.}
12
+ spec.summary = %q{A Danger plugin to check files which should be committed.}
13
+ spec.homepage = 'https://github.com/mataku/danger-lock_dependency_versions'
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
+
23
+ # General ruby development
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+
27
+ # Testing support
28
+ spec.add_development_dependency 'rspec', '~> 3.4'
29
+
30
+ spec.add_development_dependency 'pry'
31
+ end
@@ -0,0 +1 @@
1
+ require "lock_dependency_versions/gem_version"
@@ -0,0 +1 @@
1
+ require "lock_dependency_versions/plugin"
@@ -0,0 +1,3 @@
1
+ module LockDependencyVersions
2
+ VERSION = "0.0.2".freeze
3
+ end
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+
3
+ module Danger
4
+ class DangerLockDependencyVersions < Plugin
5
+ def check(config = nil)
6
+ config = config.is_a?(Hash) ? config : { }
7
+ warning_mode = config[:warning] || false
8
+ files = git.modified_files
9
+ lock_list.keys.each do |file|
10
+ if files.include?(file) && !(files.include?(lock_list[file]))
11
+ comment(warning_mode, file)
12
+ end
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def comment(warning_mode, file)
19
+ if warning_mode
20
+ warn(error_message(file))
21
+ else
22
+ fail(error_message(file))
23
+ end
24
+ end
25
+
26
+ def error_message(file)
27
+ "`#{file}` has changed. `#{lock_list[file]}` should be committed."
28
+ end
29
+
30
+ def lock_list
31
+ YAML.load_file('.lock_list.yml')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,89 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+ require 'yaml'
3
+
4
+ module Danger
5
+ describe Danger::DangerLockDependencyVersions do
6
+ let(:git_plugin) { Danger::DangerfileGitPlugin }
7
+ let(:dangerfile) { testing_dangerfile }
8
+ let(:plugin) { dangerfile.lock_dependency_versions }
9
+ let(:load_data) do
10
+ {
11
+ "Gemfile" => "Gemfile.lock",
12
+ "Cartfile" => "Cartfile.resolved"
13
+ }
14
+ end
15
+
16
+
17
+ it "should be a plugin" do
18
+ expect(Danger::DangerLockDependencyVersions < Danger::Plugin).to be_truthy
19
+ end
20
+
21
+ describe "#check" do
22
+ let(:modified_files) { [] }
23
+
24
+ shared_examples 'no errors' do
25
+ it do
26
+ plugin.check
27
+ expect(dangerfile.status_report[:errors].length).to be == 0
28
+ end
29
+ end
30
+
31
+ before do
32
+ allow(YAML).to receive(:load_file).with('.lock_list.yml').and_return(load_data)
33
+ allow_any_instance_of(git_plugin).to receive(:modified_files).and_return(modified_files)
34
+ end
35
+
36
+ it_behaves_like 'no errors'
37
+
38
+ context 'files which managed library versions are not included' do
39
+ let(:modified_files) { ['README.md'] }
40
+
41
+ it_behaves_like 'no errors'
42
+ end
43
+
44
+ context 'file which managed library versions are included' do
45
+ let(:modified_files) { ['README.md', 'Gemfile'] }
46
+
47
+ it 'an error has occurred' do
48
+ plugin.check
49
+ expect(dangerfile.status_report[:errors].length).to be == 1
50
+ expect(dangerfile.status_report[:errors][0]).to eq '`Gemfile` has changed. `Gemfile.lock` should be committed.'
51
+ end
52
+ end
53
+
54
+ context 'files which managed library versions are included' do
55
+ let(:modified_files) { ['Cartfile', 'Gemfile'] }
56
+
57
+ it 'multiple errors have occurred' do
58
+ plugin.check
59
+ expect(dangerfile.status_report[:errors].length).to be == 2
60
+ expect(dangerfile.status_report[:errors]).to include '`Gemfile` has changed. `Gemfile.lock` should be committed.'
61
+ expect(dangerfile.status_report[:errors]).to include '`Cartfile` has changed. `Cartfile.resolved` should be committed.'
62
+ end
63
+ end
64
+
65
+ context 'with lock file' do
66
+ let(:modified_files) { ['Gemfile', 'Gemfile.lock'] }
67
+
68
+ it_behaves_like 'no errors'
69
+ end
70
+
71
+ context 'only lock file has committed' do
72
+ let(:modified_files) { ['Gemfile.lock'] }
73
+
74
+ it_behaves_like 'no errors'
75
+ end
76
+
77
+ context 'warning: true' do
78
+ let(:modified_files) { ['Gemfile'] }
79
+
80
+ it 'should warning, not error' do
81
+ plugin.check(warning: true)
82
+ expect(dangerfile.status_report[:warnings].length).to be == 1
83
+ expect(dangerfile.status_report[:errors].length).to be == 0
84
+ expect(dangerfile.status_report[:warnings][0]).to eq '`Gemfile` has changed. `Gemfile.lock` should be committed.'
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,65 @@
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
+ if `git remote -v` == ''
13
+ puts "You cannot run tests without setting a local git remote on this repo"
14
+ puts "It's a weird side-effect of Danger's internals."
15
+ exit(0)
16
+ end
17
+
18
+ # Use coloured output, it's the best.
19
+ RSpec.configure do |config|
20
+ config.filter_gems_from_backtrace "bundler"
21
+ config.color = true
22
+ config.tty = true
23
+ end
24
+
25
+ require "danger_plugin"
26
+
27
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
28
+ # If you are expanding these files, see if it's already been done ^.
29
+
30
+ # A silent version of the user interface,
31
+ # it comes with an extra function `.string` which will
32
+ # strip all ANSI colours from the string.
33
+
34
+ # rubocop:disable Lint/NestedMethodDefinition
35
+ def testing_ui
36
+ @output = StringIO.new
37
+ def @output.winsize
38
+ [20, 9999]
39
+ end
40
+
41
+ cork = Cork::Board.new(out: @output)
42
+ def cork.string
43
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
44
+ end
45
+ cork
46
+ end
47
+ # rubocop:enable Lint/NestedMethodDefinition
48
+
49
+ # Example environment (ENV) that would come from
50
+ # running a PR on TravisCI
51
+ def testing_env
52
+ {
53
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
54
+ "TRAVIS_PULL_REQUEST" => "800",
55
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
56
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
57
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
58
+ }
59
+ end
60
+
61
+ # A stubbed out Dangerfile for use in tests
62
+ def testing_dangerfile
63
+ env = Danger::EnvironmentManager.new(testing_env)
64
+ Danger::Dangerfile.new(env, testing_ui)
65
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-lock_dependency_versions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - mataku
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-19 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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A Danger plugin to check files which should be committed.
84
+ email:
85
+ - nagomimatcha@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - Guardfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - danger-lock_dependency_versions.gemspec
98
+ - lib/danger_lock_dependency_versions.rb
99
+ - lib/danger_plugin.rb
100
+ - lib/lock_dependency_versions/gem_version.rb
101
+ - lib/lock_dependency_versions/plugin.rb
102
+ - spec/lock_dependency_versions_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/mataku/danger-lock_dependency_versions
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.6.13
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A Danger plugin to check files which should be committed.
128
+ test_files:
129
+ - spec/lock_dependency_versions_spec.rb
130
+ - spec/spec_helper.rb