gemometer 0.1.0

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: def3e23f8440476ada7e8f8870a0a952b6b410db
4
+ data.tar.gz: f8ee17c3379d684ae314f001261d34ca20c713bf
5
+ SHA512:
6
+ metadata.gz: 143950f73f4ce7a1063074eb64def80fd5b02ac6455fe8d59229e7274b1b22ac4a6e29911904edb9c26ed74d9e6e4d46ac5ca797992f271cd767e9f2cad2745a
7
+ data.tar.gz: f9a044d39692da7ada18eae45c7a7a455137be0fc4f3d8cec022e44e09fb4c7695b581edb82e4264493347308f3abfafc5e8779d561d7b3c018aa8b41cb60359
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gemometer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Hugo Maia Vieira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Gemometer
2
+
3
+ Gemometer is intended to be used on your continuous integration server to notify when there are new versions of the gems used on your project. It is a primitive and free [Gemnasium](https://gemnasium.com).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gemometer', group: :test
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gemometer
20
+
21
+ ## Usage
22
+
23
+ ### Hipchat
24
+
25
+ Log into hipchat.com, go to **Rooms**, select the room and go to **Integrations**, then click on "Build Your Own integration".
26
+
27
+ $ gemometer --notifier hipchat --url https://url-from-hipchat
28
+
29
+ ### Slack
30
+
31
+ Log into slack.com, go to **Integrations** (or Configure Integrations) and add a "Incoming WebHooks"
32
+
33
+ $ gemometer --notifier slack --url https://url-from-slack
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hugomaiavieira/gemometer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gemometer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/gemometer ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'gemometer/cli'
6
+
7
+ Gemometer::CLI.start(ARGV)
data/gemometer.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gemometer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gemometer"
8
+ spec.version = Gemometer::VERSION
9
+ spec.authors = ["Hugo Maia Vieira"]
10
+ spec.email = ["hugomaiavieira@gmail.com"]
11
+
12
+ spec.summary = %q{Verify and notify about outdated dependencies based on project's Gemfile}
13
+ spec.description = %q{Gemometer is intended to be used on your continuous integration server to notify when there are new versions of the gems used on your project.}
14
+ spec.homepage = "https://github.com/hugomaiavieira/gemometer"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "vcr", "~> 2.9"
25
+ spec.add_development_dependency "webmock", "~> 1.22"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,76 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ require 'gemometer'
5
+
6
+ module Gemometer
7
+ class CLI
8
+ NOTIFIERS = Gemometer.notifiers
9
+ MANDATORY = %w[notifier url]
10
+
11
+ def self.start(args)
12
+ @options = parse_args(args)
13
+ notify
14
+ end
15
+
16
+ def self.parse_args(args)
17
+ options = OpenStruct.new
18
+
19
+ opt_parser = OptionParser.new do |opts|
20
+ opts.banner = 'Usage: gemometer [options]'
21
+
22
+ opts.separator ''
23
+ opts.separator 'Specific options:'
24
+
25
+ opts.on('-n', '--notifier NOTIFIER', NOTIFIERS, {},
26
+ 'Specify the notifier app', " (#{NOTIFIERS.join(', ')})") do |notifier|
27
+ options.notifier = notifier
28
+ end
29
+
30
+ opts.on('-u', '--url URL',
31
+ 'Specify the app notification url') do |url|
32
+ options.url = url
33
+ end
34
+
35
+ opts.separator ''
36
+ opts.separator 'Common options:'
37
+
38
+ opts.on_tail('-h', '--help', 'Show this message') do
39
+ puts opts
40
+ exit
41
+ end
42
+
43
+ opts.on_tail('--version', 'Show version') do
44
+ puts Gemometer::VERSION
45
+ exit
46
+ end
47
+ end
48
+
49
+ begin
50
+ opt_parser.parse!(args)
51
+ missing = MANDATORY.select{ |param| options.send(param).nil? }
52
+ if missing.any?
53
+ abort("\nMissing options: #{missing.join(', ')}\n\n\n#{opt_parser}")
54
+ end
55
+ rescue OptionParser::InvalidArgument, OptionParser::MissingArgument, OptionParser::InvalidOption
56
+ # Friendly output when parsing fails
57
+ abort("\n#{$!}\n\n\n#{opt_parser}")
58
+ end
59
+
60
+ options
61
+ end
62
+
63
+ def self.notify
64
+ begin
65
+ gems = Gemometer::Parser.new(Gemometer::System.bundle_outdated).parse
66
+
67
+ Gemometer::Notifiers.const_get(@options.notifier.capitalize).new(
68
+ gems: gems,
69
+ url: @options.url
70
+ ).notify
71
+ rescue Gemometer::NotifyError => e
72
+ abort(e.message)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ module Gemometer
2
+ class Error < RuntimeError
3
+ end
4
+
5
+ class NotifyError < Error
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'gemometer/errors'
5
+
6
+ module Gemometer
7
+ module Notifiers
8
+ class Base
9
+ attr_reader :gems, :url
10
+
11
+ def initialize(opts)
12
+ @gems = opts[:gems]
13
+ @url = opts[:url]
14
+ end
15
+
16
+ def notify
17
+ return false if gems.empty?
18
+
19
+ uri = URI(url)
20
+
21
+ http = Net::HTTP.new(uri.host, uri.port)
22
+ http.use_ssl = (uri.scheme == "https")
23
+
24
+ req = Net::HTTP::Post.new(uri)
25
+ req.content_type = 'application/json'
26
+
27
+ res = http.request(req, JSON.generate(data))
28
+
29
+ %w(204 200).include?(res.code) ||
30
+ raise(Gemometer::NotifyError.new("#{res.code}: #{res.message}"))
31
+ end
32
+
33
+ private
34
+
35
+ def data
36
+ raise NotImplementedError
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ # https://www.hipchat.com/docs/apiv2/method/send_room_notification
2
+ module Gemometer
3
+ module Notifiers
4
+ class Hipchat < Base
5
+ def message
6
+ html = '<p>Outdated gems:</p><ul>'
7
+ gems.each do |g|
8
+ html += "<li><a href='https://rubygems.org/gems/#{g[:name]}'>#{g[:name]}</a> (newest #{g[:newest]}, installed #{g[:installed]})</li>"
9
+ end
10
+ html += '</ul>'
11
+ end
12
+
13
+ private
14
+
15
+ def data
16
+ { message: message }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ # https://api.slack.com/incoming-webhooks
2
+ module Gemometer
3
+ module Notifiers
4
+ class Slack < Base
5
+ attr_accessor :channel
6
+
7
+ def initialize(opts)
8
+ @channel = opts.delete(:channel)
9
+ super(opts)
10
+ end
11
+
12
+ def message
13
+ html = "Outdated gems:\n"
14
+ gems.each do |g|
15
+ html += "\n <https://rubygems.org/gems/#{g[:name]}|#{g[:name]}> (newest #{g[:newest]}, installed #{g[:installed]})"
16
+ end
17
+ html += "\n-"
18
+ end
19
+
20
+ private
21
+
22
+ def data
23
+ {
24
+ text: message,
25
+ channel: channel,
26
+ username: 'Gemometer'
27
+ # icon_url: "https://TODO:add-icon.png"
28
+ }.reject{ |k,v| v.nil? }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module Gemometer
2
+ class Parser
3
+ REGEX=%r(\* ([^\s]+) \(newest ([0-9|\.]+), installed ([0-9|\.]+)\))
4
+
5
+ def initialize(str)
6
+ @str = str
7
+ @gems = []
8
+ end
9
+
10
+ def parse
11
+ @str.scan(REGEX){ |a, b, c| @gems << { name: a, newest: b, installed: c } } if @gems.empty?
12
+ @gems
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Gemometer
2
+ class System
3
+ def self.bundle_outdated
4
+ `bundle outdated`
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Gemometer
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gemometer.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "gemometer/version"
2
+
3
+ require 'gemometer/errors'
4
+
5
+ require "gemometer/system"
6
+ require "gemometer/parser"
7
+
8
+ require "gemometer/notifiers/base"
9
+ require "gemometer/notifiers/hipchat"
10
+ require "gemometer/notifiers/slack"
11
+
12
+ module Gemometer
13
+ def self.notifiers
14
+ (Notifiers.constants - [:Base]).map(&:downcase)
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemometer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hugo Maia Vieira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.22'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.22'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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: Gemometer is intended to be used on your continuous integration server
84
+ to notify when there are new versions of the gems used on your project.
85
+ email:
86
+ - hugomaiavieira@gmail.com
87
+ executables:
88
+ - gemometer
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - exe/gemometer
103
+ - gemometer.gemspec
104
+ - lib/gemometer.rb
105
+ - lib/gemometer/cli.rb
106
+ - lib/gemometer/errors.rb
107
+ - lib/gemometer/notifiers/base.rb
108
+ - lib/gemometer/notifiers/hipchat.rb
109
+ - lib/gemometer/notifiers/slack.rb
110
+ - lib/gemometer/parser.rb
111
+ - lib/gemometer/system.rb
112
+ - lib/gemometer/version.rb
113
+ homepage: https://github.com/hugomaiavieira/gemometer
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.4.5.1
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Verify and notify about outdated dependencies based on project's Gemfile
137
+ test_files: []