awesome_bot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd7f4c9d4a4ef27387f5be98562f0f639678e8ff
4
+ data.tar.gz: 490ef9bdb314344c878e2eb0954c7182db6eb0be
5
+ SHA512:
6
+ metadata.gz: d78425a7f1b3b074532c45962ff28f75a321d9e38cc2c018b62765243b883cd8f7bd329af6ab83a1439a720cf819365fdaf8b2a494519660828f2cb4ab0d3375
7
+ data.tar.gz: af9d27a79f04c2b457335cff51fba1454eb16d744d8ea05ce75c63beb926512390a74f803eab61b6b9cbb9f69f204783daded626e0a1093f14d57daac214f02e
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ before_script:
5
+ - export PATH=$PATH:$PWD/bin/
6
+ - bundle install
7
+ script:
8
+ - awesome_bot
9
+ - awesome_bot bin/assets/test-no-issues
10
+ - awesome_bot bin/assets/test-no-links
11
+ - awesome_bot bin/assets/test-dupe --allow-dupe
12
+ - awesome_bot README.md --allow-dupe --white-list gph.is,bot.svg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in awesome_bot.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # awesome_bot
2
+
3
+ :rocket: Check for links in [awesome](https://github.com/sindresorhus/awesome) projects
4
+
5
+ ![](http://i.giphy.com/12qq4Em3MVuwJW.gif)
6
+
7
+ `awesome_bot` checks for valid URLs in a file, it can be used to verify pull requests to update a README with [Travis](#travis).
8
+
9
+ [![Build Status](https://travis-ci.org/dkhamsing/awesome_bot.svg)](https://travis-ci.org/dkhamsing/awesome_bot)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'awesome_bot'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install awesome_bot
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ awesome_bot <file> [--allow-dupe] [--white-list item1,item2,..]
31
+ ```
32
+
33
+ ```shell
34
+ $ awesome_bot README.md
35
+ Checking links in ../README.md
36
+ Links found: 35, 11 unique
37
+ 1. https://github.com/sindresorhus/awesome
38
+ 2. http://i.giphy.com/12qq4Em3MVuwJW.gif
39
+ 3. https://travis-ci.org/dkhamsing/awesome_bot.svg
40
+ 4. https://travis-ci.org/dkhamsing/awesome_bot
41
+ 5. https://travis-ci.org/
42
+ 6. http://gph.is/1gU5itl
43
+ 7. https://github.com/dkhamsing
44
+ 8. https://twitter.com/dkhamsing
45
+ 9. https://github.com/dkhamsing/open-source-ios-apps/pull/159
46
+ 10. https://github.com/dkhamsing/open-source-ios-apps/blob/master/.travis.yml
47
+ 11. https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/wip
48
+ Checking URLs: x✓✓✓x✓✓✓✓✓✓
49
+
50
+ Issues :-(
51
+ > Links
52
+ 1. 301 http://gph.is/1gU5itl
53
+ 2. 301 https://travis-ci.org/dkhamsing/awesome_bot.svg
54
+ > Dupes
55
+ 1. https://github.com/sindresorhus/awesome
56
+ 2. http://i.giphy.com/12qq4Em3MVuwJW.gif
57
+ 3. https://travis-ci.org/dkhamsing/awesome_bot.svg
58
+ 4. https://travis-ci.org/dkhamsing/awesome_bot
59
+ 5. https://travis-ci.org/
60
+ 6. http://gph.is/1gU5itl
61
+ 7. https://github.com/dkhamsing
62
+ 8. https://twitter.com/dkhamsing
63
+ 9. https://github.com/dkhamsing/open-source-ios-apps/pull/159
64
+ 10. https://github.com/dkhamsing/open-source-ios-apps/blob/master/.travis.yml
65
+ 11. https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/wip
66
+ ```
67
+
68
+ ```shell
69
+ $ awesome_bot README.md --allow-dupe --white-list gph.is,bot.svg
70
+ > Checking links in README.md
71
+ > Will not check for duplicate links
72
+ > White list: gph.is, bot.svg
73
+ Links found: 27, 8 white listed, 9 unique
74
+ 1. https://github.com/sindresorhus/awesome
75
+ 2. http://i.giphy.com/12qq4Em3MVuwJW.gif
76
+ 3. https://travis-ci.org/dkhamsing/awesome_bot
77
+ 4. https://travis-ci.org/
78
+ 5. https://github.com/dkhamsing
79
+ 6. https://twitter.com/dkhamsing
80
+ 7. https://github.com/dkhamsing/open-source-ios-apps/pull/159
81
+ 8. https://github.com/dkhamsing/open-source-ios-apps/blob/master/.travis.yml
82
+ 9. https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/wip
83
+ Checking URLs: ✓✓✓✓✓✓✓✓✓
84
+ No issues :-)
85
+ ```
86
+
87
+ ## Travis
88
+
89
+ Use `awesome_bot` with [Travis](https://travis-ci.org/) to validate GitHub [pull requests](https://github.com/dkhamsing/open-source-ios-apps/pull/159).
90
+
91
+ Example [`.travis.yml` file](https://github.com/dkhamsing/open-source-ios-apps/blob/master/.travis.yml)
92
+
93
+ ```
94
+ language: ruby
95
+ rvm:
96
+ - 2.2
97
+ before_script:
98
+ - wget https://codeload.github.com/dkhamsing/awesome_bot/tar.gz/wip -O /tmp/temp.tar.gz
99
+ - tar -xvf /tmp/temp.tar.gz
100
+ - export PATH=$PATH:$PWD/awesome_bot-wip/bin/
101
+ - cd awesome_bot-wip
102
+ - bundle install
103
+ script:
104
+ - awesome_bot ../README.md
105
+ ```
106
+
107
+ ## Credits
108
+
109
+ - `faraday`, `parallel` and [more](awesome_bot.gemspec)
110
+ - [giphy](http://gph.is/1gU5itl)
111
+
112
+ ## Contact
113
+
114
+ - [github.com/dkhamsing](https://github.com/dkhamsing)
115
+ - [twitter.com/dkhamsing](https://twitter.com/dkhamsing)
116
+
117
+ ## License
118
+
119
+ This project is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -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 'awesome_bot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = AwesomeBot::PROJECT
8
+ spec.version = AwesomeBot::VERSION
9
+ spec.authors = ['Daniel Khamsing']
10
+ spec.email = ['dkhamsing8@gmail.com']
11
+
12
+ spec.summary = 'Validate awesome project URLs.'
13
+ spec.description = AwesomeBot::PROJECT_DESCRIPTION
14
+ spec.homepage = AwesomeBot::PROJECT_URL
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_runtime_dependency 'faraday', '~> 0.9.2' # validate urls
23
+ spec.add_runtime_dependency 'uri', '~> 4.4.29' # get urls
24
+ spec.add_runtime_dependency 'parallel', '~> 1.6.1' # threading
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.7' # travis version
27
+ end
@@ -0,0 +1,5 @@
1
+ https://twitter.com
2
+ https://twitter.com
3
+ https://github.com/dkhamsing
4
+ https://github.com
5
+ https://github.com
@@ -0,0 +1 @@
1
+ http://google.com
@@ -0,0 +1,2 @@
1
+ https://twitter.com
2
+ http://github.com
@@ -0,0 +1,2 @@
1
+ https://twitter.com
2
+ https://github.com
@@ -0,0 +1 @@
1
+ blah blah
data/bin/awesome_bot ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'awesome_bot'
5
+
6
+ AwesomeBot.cli
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'awesome_bot'
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
@@ -0,0 +1,5 @@
1
+ require 'awesome_bot/command'
2
+
3
+ # Validate awesome project URLs
4
+ module AwesomeBot
5
+ end
@@ -0,0 +1,126 @@
1
+ require 'awesome_bot/links'
2
+ require 'awesome_bot/statuses'
3
+ require 'awesome_bot/version'
4
+ require 'awesome_bot/white_list'
5
+
6
+ # Command
7
+ module AwesomeBot
8
+ NUMBER_OF_THREADS = 10
9
+
10
+ OPTION_DUPE = 'allow-dupe'
11
+ OPTION_WHITE_LIST = 'white-list'
12
+
13
+ STATUS_OK = '✓'
14
+ STATUS_OTHER = 'x'
15
+
16
+ USAGE = "\t"
17
+
18
+ class << self
19
+ def cli
20
+ option_d = "--#{OPTION_DUPE}"
21
+ option_w = "--#{OPTION_WHITE_LIST}"
22
+
23
+ if ARGV.count == 0
24
+ puts "#{PROJECT_DESCRIPTION} \n"\
25
+ "Usage: #{PROJECT} <file> [#{option_d}] "\
26
+ "[#{option_w} item1,item2,..]\n"\
27
+ "#{USAGE} file \t\t Path to file \n"\
28
+ "#{USAGE} #{option_d} \t Skip checking for duplicate URLs \n"\
29
+ "#{USAGE} #{option_w} \t Comma separated URLs to white list \n"\
30
+ "\nSee #{PROJECT_URL} for more information"
31
+
32
+ exit
33
+ end
34
+
35
+ filename = ARGV[0]
36
+ puts "> Checking links in #{filename}"
37
+
38
+ if ARGV.count > 1
39
+ options = ARGV.drop 1
40
+
41
+ skip_dupe = options.include? option_d
42
+
43
+ if options.include? option_w
44
+ i = options.find_index(option_w) + 1
45
+ white_listed = options[i].split ','
46
+ end
47
+ end
48
+
49
+ begin
50
+ content = File.read filename
51
+ rescue => error
52
+ puts "File open error: #{error}"
53
+ exit 1
54
+ end
55
+
56
+ exit 1 if run(content, white_listed, skip_dupe, true) == false
57
+
58
+ exit
59
+ end
60
+
61
+ def run(content, white_listed = nil, skip_dupe = false, verbose = false)
62
+ dupe_success = skip_dupe
63
+
64
+ puts '> Will not check for duplicate links' if skip_dupe && verbose
65
+
66
+ white_listing = !white_listed.nil?
67
+ puts "> White list: #{white_listed.join ', '}" if white_listing && verbose
68
+
69
+ links = links_filter(links_find(content))
70
+
71
+ if white_listing
72
+ rejected, links = links.partition { |u| white_list white_listed, u }
73
+ end
74
+
75
+ if verbose
76
+ print "Links found: #{links.count}"
77
+ print ", #{rejected.count} white listed" if white_listing
78
+ print ", #{links.uniq.count} unique" if links.count != links.uniq.count
79
+ puts ''
80
+ links.uniq.each_with_index { |u, j| puts " #{j + 1}. #{u}" }
81
+ end
82
+
83
+ print 'Checking URLs: ' if verbose && (links.count > 0)
84
+ statuses =
85
+ statuses links.uniq, NUMBER_OF_THREADS, verbose, STATUS_OK, STATUS_OTHER
86
+ puts '' if verbose
87
+
88
+ statuses_issues = statuses.select { |x| x['status'] != 200 }
89
+ links_success = statuses_issues.count == 0
90
+
91
+ unless skip_dupe
92
+ dupe_success = links.uniq.count == links.count
93
+ dupes = links.select { |e| links.count(e) > 1 }
94
+ end
95
+
96
+ if links_success && dupe_success
97
+ puts 'No issues :-)' if verbose
98
+ return true
99
+ end
100
+
101
+ if verbose
102
+ puts "\nIssues :-("
103
+
104
+ print "> Links \n"
105
+ if links_success
106
+ puts " All OK #{STATUS_OK}"
107
+ else
108
+ statuses_issues.each_with_index do |x, k|
109
+ puts " #{k + 1}. #{x['status']} #{x['url']} "
110
+ end
111
+ end
112
+
113
+ unless skip_dupe
114
+ print "> Dupes \n"
115
+ if dupe_success
116
+ puts " None #{STATUS_OK}"
117
+ else
118
+ dupes.uniq.each_with_index { |d, m| puts " #{m + 1}. #{d}" }
119
+ end
120
+ end
121
+ end # if verbose
122
+
123
+ [false, statuses, dupes]
124
+ end # run
125
+ end # class
126
+ end
@@ -0,0 +1,17 @@
1
+ # Get and filter links
2
+ module AwesomeBot
3
+ require 'uri'
4
+
5
+ class << self
6
+ def links_filter(list)
7
+ list.reject { |x| x.length < 9 }
8
+ .map do |x|
9
+ x.gsub(/\).*/, '').gsub(/'.*/, '').gsub(/,.*/, '').gsub('/:', '/')
10
+ end
11
+ end
12
+
13
+ def links_find(content)
14
+ URI.extract(content, /http()s?/)
15
+ end
16
+ end # class
17
+ end
@@ -0,0 +1,24 @@
1
+ # Get link status
2
+ module AwesomeBot
3
+ require 'faraday'
4
+ require 'parallel'
5
+
6
+ class << self
7
+ def net_status(url)
8
+ Faraday.get(url).status
9
+ end
10
+
11
+ def statuses(links, threads, verbose, status_ok, status_other)
12
+ statuses = []
13
+ Parallel.each(links, in_threads: threads) do |u|
14
+ status = net_status u
15
+
16
+ print(status == 200 ? status_ok : status_other) if verbose
17
+
18
+ statuses.push('url' => u, 'status' => status)
19
+ end # Parallel
20
+
21
+ statuses
22
+ end
23
+ end # class
24
+ end
@@ -0,0 +1,8 @@
1
+ # Project version and constants
2
+ module AwesomeBot
3
+ PROJECT = 'awesome_bot'
4
+ PROJECT_DESCRIPTION = 'Check for valid and duplicate URLs in a file'
5
+ PROJECT_URL = 'https://github.com/dkhamsing/awesome_bot'
6
+
7
+ VERSION = '0.1.0'
8
+ end
@@ -0,0 +1,9 @@
1
+ # Process white list
2
+ module AwesomeBot
3
+ class << self
4
+ def white_list(list, item)
5
+ list.each { |x| return true if item.include? x }
6
+ false
7
+ end
8
+ end # class
9
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awesome_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Khamsing
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: uri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.4.29
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.4.29
41
+ - !ruby/object:Gem::Dependency
42
+ name: parallel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.1
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.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ description: Check for valid and duplicate URLs in a file
70
+ email:
71
+ - dkhamsing8@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - awesome_bot.gemspec
83
+ - bin/assets/test-dupe
84
+ - bin/assets/test-link-issue
85
+ - bin/assets/test-no-dupes
86
+ - bin/assets/test-no-issues
87
+ - bin/assets/test-no-links
88
+ - bin/awesome_bot
89
+ - bin/console
90
+ - bin/setup
91
+ - lib/awesome_bot.rb
92
+ - lib/awesome_bot/command.rb
93
+ - lib/awesome_bot/links.rb
94
+ - lib/awesome_bot/statuses.rb
95
+ - lib/awesome_bot/version.rb
96
+ - lib/awesome_bot/white_list.rb
97
+ homepage: https://github.com/dkhamsing/awesome_bot
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.0.14
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Validate awesome project URLs.
121
+ test_files: []