awesome_bot 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +45 -49
- data/bin/assets/test-timeout-and-redirect +1 -2
- data/lib/awesome_bot/check.rb +4 -1
- data/lib/awesome_bot/cli.rb +41 -10
- data/lib/awesome_bot/statuses.rb +2 -4
- data/lib/awesome_bot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ade84e7c925224c447476c2dff8ca5a1c9a70b
|
4
|
+
data.tar.gz: 3bfaeb0385871cc68c077bdda4b400bd9cabc368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 221cfd97f2fb670eee8ff712a129192a020a094bf2d67f9bb15c217de50b7f0aec8e1f5b1097bdca480f9315b49229f2eef1a1707abd149f803177a3034772a7
|
7
|
+
data.tar.gz: 9d1d26c95e0aeaa8f4f4c8b8ffc1c15b9678372c605dc4429a13b46c80ed70404b7ceafe19e54d31057d2222d9f1316a753383d21595d09a0e0f2414e727bafd
|
data/CHANGELOG.md
CHANGED
@@ -2,10 +2,16 @@
|
|
2
2
|
|
3
3
|
Changes by [Daniel Khamsing][] unless otherwise noted.
|
4
4
|
|
5
|
+
# 1.8.1
|
6
|
+
|
7
|
+
- [output] show link line number, suggested by [Daniel Gomez Rico](https://github.com/danielgomezrico)
|
8
|
+
- [output] improve enumeration with padding
|
9
|
+
- set default open link timeout to 30 seconds
|
10
|
+
|
5
11
|
# 1.8.0
|
6
12
|
|
7
13
|
- remove `faraday`
|
8
|
-
- [fix] parse links with commas (url encode)
|
14
|
+
- [fix] parse links with commas (url encode), reported by [Kishan Bagaria](https://github.com/KishanBagaria)
|
9
15
|
|
10
16
|
# 1.7.1
|
11
17
|
|
data/README.md
CHANGED
@@ -16,22 +16,6 @@ Verify links in [awesome](https://github.com/sindresorhus/awesome) projects
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
### Library
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
irb(main):001:0> require 'awesome_bot'
|
23
|
-
=> true
|
24
|
-
irb(main):002:0> content = File.read 'README.md'
|
25
|
-
=> "..."
|
26
|
-
irb(main):003:0> result = AwesomeBot.check content
|
27
|
-
=> #<AwesomeBot::Result:0x007fdde39f4408 @links=...>
|
28
|
-
# AwesomeBot Result with success, statuses_issues, dupes and more
|
29
|
-
irb(main):004:0> puts result.success ? 'No errors' : ':-('
|
30
|
-
:-(
|
31
|
-
```
|
32
|
-
|
33
|
-
More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot).
|
34
|
-
|
35
19
|
### Command Line
|
36
20
|
|
37
21
|
awesome_bot <file> [--allow-dupe] [--allow-redirect] [--allow-timeout] [--set-timeout d] [--white-list item1,item2,..]
|
@@ -53,49 +37,61 @@ By default, `awesome_bot` flags duplicates and URL redirects.
|
|
53
37
|
```shell
|
54
38
|
$ awesome_bot README.md
|
55
39
|
> Checking links in README.md
|
56
|
-
Links found: 56,
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Checking URLs:
|
63
|
-
|
64
|
-
Issues :-(
|
65
|
-
> Links
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
1. https://github.com/sindresorhus/awesome
|
74
|
-
2. https://github.com/veggiemonk/awesome-docker
|
75
|
-
3. https://github.com/dotfiles/dotfiles.github.com
|
40
|
+
Links found: 56, 37 unique
|
41
|
+
01. https://github.com/sindresorhus/awesome
|
42
|
+
02. http://i.giphy.com/urvsFBDfR6N32.gif
|
43
|
+
03. https://travis-ci.org/dkhamsing/awesome_bot.svg
|
44
|
+
# ...
|
45
|
+
37. https://github.com/dkhamsing
|
46
|
+
Checking URLs: ✓✓✓→?✓→✓→→✓✓→✓✓✓→✓✓✓✓✓✓✓✓✓✓✓→✓✓✓✓✓→✓✓
|
47
|
+
|
48
|
+
Issues :-(
|
49
|
+
> Links
|
50
|
+
1. [L007] 301 https://travis-ci.org/dkhamsing/awesome_bot.svg → https://api.travis-ci.org/dkhamsing/awesome_bot.svg
|
51
|
+
2. [L008] 302 https://badge.fury.io/rb/awesome_bot → http://rubygems.org/gems/awesome_bot
|
52
|
+
# ...
|
53
|
+
> Dupes
|
54
|
+
1. https://github.com/sindresorhus/awesome
|
55
|
+
2. http://i.giphy.com/urvsFBDfR6N32.gif
|
56
|
+
# ...
|
76
57
|
```
|
77
58
|
|
78
59
|
```shell
|
79
|
-
$ awesome_bot README.md --allow-dupe --white-list
|
60
|
+
$ awesome_bot README.md --allow-dupe --white-list travis,badge,rubydoc,rubygems,giphy,gph
|
80
61
|
> Checking links in README.md
|
81
62
|
> Will allow duplicate links
|
82
|
-
> White list links matching:
|
83
|
-
Links
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
Checking
|
63
|
+
> White list links matching: travis, badge, rubydoc, rubygems, giphy, gph
|
64
|
+
Links to check: 21, 27 white listed, 16 unique
|
65
|
+
01. https://github.com/sindresorhus/awesome
|
66
|
+
02. https://circleci.com/gh/dkhamsing/awesome_bot
|
67
|
+
03. https://github.com/dkhamsing
|
68
|
+
# ...
|
69
|
+
Checking URLs: ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓
|
70
|
+
Checking white listed URLs: ✓✓✓→→?✓→→✓→✓→✓→✓→✓
|
89
71
|
|
90
72
|
> White listed:
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
...
|
95
|
-
|
73
|
+
01. [L005] 200 http://i.giphy.com/urvsFBDfR6N32.gif
|
74
|
+
02. [L007] 200 https://img.shields.io/badge/tests-circle%20ci-brightgreen.svg
|
75
|
+
# ...
|
96
76
|
No issues :-)
|
97
77
|
```
|
98
78
|
|
79
|
+
### Library
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
irb(main):001:0> require 'awesome_bot'
|
83
|
+
=> true
|
84
|
+
irb(main):002:0> content = File.read 'README.md'
|
85
|
+
=> "..."
|
86
|
+
irb(main):003:0> result = AwesomeBot.check content
|
87
|
+
=> #<AwesomeBot::Result:0x007fdde39f4408 @links=...>
|
88
|
+
# AwesomeBot Result with success, statuses_issues, dupes and more
|
89
|
+
irb(main):004:0> puts result.success ? 'No errors' : ':-('
|
90
|
+
:-(
|
91
|
+
```
|
92
|
+
|
93
|
+
More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot).
|
94
|
+
|
99
95
|
## Validate Pull Requests
|
100
96
|
|
101
97
|
Does your GitHub README contain a lot of links? `awesome_bot` can help you validate them when a [pull request](https://github.com/dkhamsing/open-source-ios-apps/pull/159) is created (or a commit is pushed). It is used by:
|
data/lib/awesome_bot/check.rb
CHANGED
@@ -52,7 +52,10 @@ module AwesomeBot
|
|
52
52
|
uniq = r.links.uniq.count
|
53
53
|
log.addp ", #{uniq} unique" if uniq != r.links.count
|
54
54
|
log.add ''
|
55
|
-
r.links.uniq.each_with_index
|
55
|
+
r.links.uniq.each_with_index do |u, j|
|
56
|
+
format = "%0#{r.links.uniq.count.to_s.size}d"
|
57
|
+
log.add " #{sprintf format, j + 1}. #{u}"
|
58
|
+
end
|
56
59
|
|
57
60
|
log.addp 'Checking URLs: ' if r.links.count > 0
|
58
61
|
r.status =
|
data/lib/awesome_bot/cli.rb
CHANGED
@@ -19,10 +19,41 @@ module AwesomeBot
|
|
19
19
|
"--#{o}"
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def loc_formatted(loc, largest=3)
|
23
|
+
format = "%0#{largest}d"
|
24
|
+
line = "#{sprintf format, loc}"
|
25
|
+
"[L#{line}] "
|
26
|
+
end
|
27
|
+
|
28
|
+
def loc(x, content)
|
29
|
+
count = 0
|
30
|
+
lines = content.split "\n"
|
31
|
+
lines.each do |l|
|
32
|
+
count += 1
|
33
|
+
return count if l.include? x
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def number_of_digits(content)
|
38
|
+
lines = content.split "\n"
|
39
|
+
return lines.count.to_s.size
|
40
|
+
end
|
41
|
+
|
42
|
+
def order_by_loc(list, content)
|
43
|
+
list.each do |x|
|
44
|
+
x['loc'] = loc x['url'], content
|
45
|
+
end
|
46
|
+
|
47
|
+
s = list.sort_by { |h| h['loc'] }
|
48
|
+
return s
|
49
|
+
end
|
50
|
+
|
51
|
+
def output(x, k, total, largest)
|
52
|
+
format = "%0#{total}d"
|
53
|
+
print " #{sprintf format, k + 1}. "
|
23
54
|
s = x['status']
|
24
|
-
print
|
25
|
-
print "#{s} " unless s
|
55
|
+
print loc_formatted x['loc'], largest
|
56
|
+
print "#{s} " unless s== STATUS_ERROR
|
26
57
|
print "#{x['url']}"
|
27
58
|
print " #{x['error']}" if s == STATUS_ERROR
|
28
59
|
print " #{STATUS_REDIRECT} #{x['headers']['location']}" if status_is_redirected? s
|
@@ -110,8 +141,6 @@ module AwesomeBot
|
|
110
141
|
allow_timeouts = false
|
111
142
|
end
|
112
143
|
|
113
|
-
# Faraday.options.timeout = timeout unless timeout.nil?
|
114
|
-
|
115
144
|
log = Log.new(true)
|
116
145
|
|
117
146
|
options = {
|
@@ -121,10 +150,12 @@ module AwesomeBot
|
|
121
150
|
}
|
122
151
|
r = check(content, options, log)
|
123
152
|
|
153
|
+
digits = number_of_digits content
|
124
154
|
unless r.white_listed.nil?
|
125
155
|
puts "\n> White listed:"
|
126
|
-
r.white_listed
|
127
|
-
|
156
|
+
o = order_by_loc r.white_listed, content
|
157
|
+
o.each_with_index do |x, k|
|
158
|
+
output x, k, o.count.to_s.size, digits
|
128
159
|
end
|
129
160
|
end
|
130
161
|
|
@@ -138,9 +169,9 @@ module AwesomeBot
|
|
138
169
|
if r.success_links(allow_redirects, allow_timeouts)
|
139
170
|
puts " All OK #{STATUS_OK}"
|
140
171
|
else
|
141
|
-
r.statuses_issues(allow_redirects, allow_timeouts)
|
142
|
-
|
143
|
-
output x, k
|
172
|
+
o = order_by_loc r.statuses_issues(allow_redirects, allow_timeouts), content
|
173
|
+
o.each_with_index do |x, k|
|
174
|
+
output x, k, o.count.to_s.size, digits
|
144
175
|
end
|
145
176
|
end
|
146
177
|
|
data/lib/awesome_bot/statuses.rb
CHANGED
@@ -9,9 +9,8 @@ module AwesomeBot
|
|
9
9
|
STATUS_ERROR = -1
|
10
10
|
|
11
11
|
class << self
|
12
|
-
def net_status(url, head, timeout)
|
12
|
+
def net_status(url, head, timeout=30)
|
13
13
|
uri = URI.parse url
|
14
|
-
timeout = 60 if timeout.nil?
|
15
14
|
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :open_timeout => timeout) do |http|
|
16
15
|
request = Net::HTTP::Get.new uri
|
17
16
|
response = http.request request
|
@@ -28,8 +27,7 @@ module AwesomeBot
|
|
28
27
|
Parallel.each(links, in_threads: threads) do |u|
|
29
28
|
begin
|
30
29
|
response = net_status u, head, timeout
|
31
|
-
status = response.code.to_i
|
32
|
-
status = 200 if status.nil?
|
30
|
+
status = response.code==nil ? 200 : response.code.to_i
|
33
31
|
headers = {}
|
34
32
|
response.each { |k, v| headers[k] = v }
|
35
33
|
error = nil # nil (success)
|
data/lib/awesome_bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awesome_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Khamsing
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel
|