forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement dependency update checking.
- Loading branch information
Showing
9 changed files
with
252 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_size = 2 | ||
translate_tabs_to_spaces = true | ||
indent_style = spaces | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# require "gem/version" | ||
require "net/http" | ||
require "json" | ||
|
||
module UpdateChecker | ||
|
||
# checks for dependencies that are out of date | ||
# | ||
# usage: | ||
# UpdateChecker::RubyUpdateChecker.new(initial_dependencies).run | ||
# | ||
# dependencies, Array | ||
# return an Array of dependencies that are out of date | ||
class RubyUpdateChecker | ||
def initialize(dependencies) | ||
@dependencies = dependencies | ||
end | ||
|
||
def run | ||
@dependencies.select do |dependency| | ||
latest_version = get_latest(dependency)["version"] | ||
Gem::Version.new(latest_version) > Gem::Version.new(dependency.version) | ||
end | ||
end | ||
|
||
private | ||
|
||
def get_latest(dependency) | ||
JSON.parse(Net::HTTP.get(URI("https://rubygems.org/api/v1/gems/#{dependency.name}.json"))) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require "spec_helper" | ||
require "bumper/dependency" | ||
require "bumper/update_checker/update_checker" | ||
|
||
RSpec.describe UpdateChecker::RubyUpdateChecker do | ||
let(:outdated_dependency) { | ||
File.read("spec/fixtures/out_of_date_dependency_response.json") | ||
} | ||
|
||
let(:outdated_dependency_json) { | ||
JSON.parse(outdated_dependency) | ||
} | ||
|
||
let(:latest_dependency) { | ||
File.read("spec/fixtures/up_to_date_dependency_response.json") | ||
} | ||
|
||
let(:latest_dependency_json) { | ||
JSON.parse(latest_dependency) | ||
} | ||
|
||
before do | ||
stub_request( | ||
:get, | ||
"https://rubygems.org/api/v1/gems/#{outdated_dependency_json["name"]}.json" | ||
). | ||
to_return(:status => 200, :body => outdated_dependency, :headers => {}) | ||
|
||
stub_request( | ||
:get, | ||
"https://rubygems.org/api/v1/gems/#{latest_dependency_json["name"]}.json" | ||
). | ||
to_return(:status => 200, :body => latest_dependency, :headers => {}) | ||
end | ||
|
||
# TODO: tests need mocking | ||
let(:initial_dependencies) do | ||
[ | ||
Dependency.new( | ||
name: latest_dependency_json["name"], | ||
version: latest_dependency_json["version"] | ||
), | ||
Dependency.new( | ||
name: outdated_dependency_json["name"], | ||
version: "1.2.0" | ||
) | ||
] | ||
end | ||
|
||
let(:checker) { UpdateChecker::RubyUpdateChecker.new(initial_dependencies) } | ||
subject(:dependencies) { checker.run } | ||
|
||
its(:length) { is_expected.to eq(1) } | ||
|
||
describe "the first dependency" do | ||
subject { dependencies.first } | ||
|
||
it { is_expected.to be_a(Dependency) } | ||
its(:name) { is_expected.to eq(outdated_dependency_json["name"]) } | ||
its(:version) { is_expected.to eq("1.2.0") } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "outdated", | ||
"downloads": 54431629, | ||
"version": "1.2.3", | ||
"version_downloads": 341108, | ||
"platform": "ruby", | ||
"authors": "David Heinemeier Hansson", | ||
"info": "Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.", | ||
"licenses": [ | ||
"MIT" | ||
], | ||
"metadata": {}, | ||
"sha": "1c33dd7c280d1c5dc4235509f774d673bac1d3f2e8c53b1353f677e7578ffc5a", | ||
"project_uri": "https://rubygems.org/gems/rails", | ||
"gem_uri": "https://rubygems.org/gems/rails-4.2.4.gem", | ||
"homepage_uri": "http://www.rubyonrails.org", | ||
"wiki_uri": "http://wiki.rubyonrails.org", | ||
"documentation_uri": "http://api.rubyonrails.org", | ||
"mailing_list_uri": "http://groups.google.com/group/rubyonrails-talk", | ||
"source_code_uri": "http://github.com/rails/rails", | ||
"bug_tracker_uri": "http://github.com/rails/rails/issues", | ||
"dependencies": { | ||
"development": [], | ||
"runtime": [ | ||
{ | ||
"name": "actionmailer", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "actionpack", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "actionview", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activejob", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activemodel", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activerecord", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activesupport", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "bundler", | ||
"requirements": "< 2.0, >= 1.3.0" | ||
}, | ||
{ | ||
"name": "railties", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "sprockets-rails", | ||
"requirements": ">= 0" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "latest", | ||
"downloads": 54431629, | ||
"version": "4.2.4", | ||
"version_downloads": 341108, | ||
"platform": "ruby", | ||
"authors": "David Heinemeier Hansson", | ||
"info": "Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.", | ||
"licenses": [ | ||
"MIT" | ||
], | ||
"metadata": {}, | ||
"sha": "1c33dd7c280d1c5dc4235509f774d673bac1d3f2e8c53b1353f677e7578ffc5a", | ||
"project_uri": "https://rubygems.org/gems/rails", | ||
"gem_uri": "https://rubygems.org/gems/rails-4.2.4.gem", | ||
"homepage_uri": "http://www.rubyonrails.org", | ||
"wiki_uri": "http://wiki.rubyonrails.org", | ||
"documentation_uri": "http://api.rubyonrails.org", | ||
"mailing_list_uri": "http://groups.google.com/group/rubyonrails-talk", | ||
"source_code_uri": "http://github.com/rails/rails", | ||
"bug_tracker_uri": "http://github.com/rails/rails/issues", | ||
"dependencies": { | ||
"development": [], | ||
"runtime": [ | ||
{ | ||
"name": "actionmailer", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "actionpack", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "actionview", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activejob", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activemodel", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activerecord", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "activesupport", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "bundler", | ||
"requirements": "< 2.0, >= 1.3.0" | ||
}, | ||
{ | ||
"name": "railties", | ||
"requirements": "= 4.2.4" | ||
}, | ||
{ | ||
"name": "sprockets-rails", | ||
"requirements": ">= 0" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require "rspec/its" | ||
require "webmock/rspec" |