lib/hoe/travis.rb in hoe-travis-1.2 vs lib/hoe/travis.rb in hoe-travis-1.3
- old
+ new
@@ -46,20 +46,20 @@
# travis:before::
# Runs as the before_script on travis-ci. Defaults to installing your
# development dependencies.
#
# travis:check::
-# Runs travis-lint against your .travis.yml.
+# Lints your .travis.yml.
#
# travis:edit::
-# Pulls up your .travis.yml in your EDITOR and runs travis-lint upon saving.
-# Does not allow you to save a bad .travis.yml.
+# Pulls up your .travis.yml in your EDITOR and lints your configuration upon
+# saving. Does not allow you to save a bad .travis.yml.
#
# travis:generate::
# Generates a .travis.yml based on your Hoe spec and .hoerc then brings it
-# up in your EDITOR and runs travis-lint upon saving. Does not allow you to
-# save a bad .travis.yml.
+# up in your EDITOR and lints upon saving. Does not allow you to save a bad
+# .travis.yml.
#
# travis:enable::
# Enables the travis hook on github.com. Requires further setup as
# described below.
#
@@ -93,11 +93,11 @@
# Your travis-ci token. See @Setup above
#
# versions::
# The versions of ruby used to run your tests. Note that if you have
# multiruby installed, your installed versions will be preferred over the
-# defaults of ruby 1.8.7, 1.9.2 and 1.9.3.
+# defaults that come with hoe-travis.
#
# In your .hoerc you may provide a "notifications" key such as:
#
# travis:
# notifications:
@@ -109,11 +109,11 @@
module Hoe::Travis
##
# This version of Hoe::Travis
- VERSION = '1.2'
+ VERSION = '1.3'
YAML_EXCEPTIONS = if defined?(Psych) then # :nodoc:
if Psych.const_defined? :Exception then
[Psych::SyntaxError] # Ruby 1.9.2
else
@@ -134,13 +134,13 @@
'rake travis:after -t',
],
'script' => 'rake travis',
'token' => 'FIX - See: ri Hoe::Travis',
'versions' => %w[
- 1.8.7
- 1.9.2
- 1.9.3
+ 2.1.0
+ 2.2.0
+ 2.3.0
],
}
def initialize_travis # :nodoc:
@github_api = URI 'https://api.github.com'
@@ -149,28 +149,27 @@
##
# Adds travis tasks to rake
def define_travis_tasks
desc "Runs your tests for travis"
- task :travis => %w[test]
+ task :travis => %w[test check_manifest]
namespace :travis do
desc "Run by travis-ci after running the default checks"
task :after => %w[
travis:fake_config
- check_manifest
]
desc "Run by travis-ci before running the default checks"
task :before => %w[
install_plugins
check_extra_deps
]
- desc "Runs travis-lint on your .travis.yml"
+ desc "Lint your .travis.yml"
task :check do
- abort unless check_travis_yml '.travis.yml'
+ abort unless travis_yml_check '.travis.yml'
end
desc "Disables the travis-ci hook"
task :disable do
travis_disable
@@ -469,39 +468,72 @@
end
end.sort
end
##
- # Runs travis-lint against the travis.yml in +path+. If the file is OK true
- # is returned, otherwise the issues are displayed on $stderr and false is
- # returned.
+ # Submits the travis.yml in +path+ to travis-ci.org for linting. If the
+ # file is OK true is returned, otherwise the issues are displayed on $stderr
+ # and false is returned.
def travis_yml_check path
- require 'travis/lint'
+ require 'net/http'
- travis_yml = YAML.load_file path
+ post_body = {
+ 'content' => File.read(path),
+ }
- issues = Travis::Lint::Linter.validate travis_yml
+ req = Net::HTTP::Post.new '/lint'
+ req.set_form post_body, 'multipart/form-data'
- return true if issues.empty?
+ cert_store = OpenSSL::X509::Store.new
+ cert_store.set_default_paths
- issues.each do |issue|
- warn "There is an issue with the key #{issue[:key].inspect}:"
- warn "\t#{issue[:issue]}"
+ http = Net::HTTP.new 'api.travis-ci.org', 443
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ http.cert_store = cert_store
+
+ res = http.request req
+
+ unless Net::HTTPOK === res then
+ warn "Unable to lint #{path}: #{res.body}"
+
+ return false
end
- false
- rescue *YAML_EXCEPTIONS => e
- warn "invalid YAML in travis.yml file at #{path}: #{e.message}"
+ require 'json'
+ response = JSON.parse res.body
+
+ lint = response.fetch 'lint'
+ warnings = lint.fetch 'warnings'
+
+ return true if warnings.empty?
+
+ warnings.each do |warning|
+ keys = warning.fetch 'key'
+ message = warning.fetch 'message'
+
+ if keys.empty? then
+ warn message
+ else
+ warn "For #{keys.join ', '}: #{message}"
+ end
+ end
+
return false
+
+ rescue Net::HTTPError => e
+ warn "Unable to lint #{path}: #{e.message}"
+
+ return false
end
##
# Loads the travis.yml in +path+ in your EDITOR (or vi if unset). Upon
- # saving the travis.yml is checked with travis-lint. If any problems are
- # found you will be asked to retry the edit.
+ # saving the travis.yml is checked by linting. If any problems are found
+ # you will be asked to retry the edit.
#
# If the edited travis.yml is OK true is returned, otherwise false.
def travis_yml_edit path
loop do
@@ -552,6 +584,5 @@
end
end
end
end
-