awesome_bot 1.15.0 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 267de098db4924f5dd57029da3bcd2691d1247d7
4
- data.tar.gz: 57258f1286e74ccb3428e8f2050882f1517e7639
3
+ metadata.gz: 9af72ee336b052bf87a013c876f0a9bdafc25c70
4
+ data.tar.gz: 756eb8577b75cdb81e284a862ec3db91b52f246a
5
5
  SHA512:
6
- metadata.gz: 74c8ff9149f12fade95db78224a1bd2d7a865186bbbaefcb8eac8256002dd3daf9fdc386fcd4891cab55795739764e0ae68e5737a1658964a9e9fed6eb3b4222
7
- data.tar.gz: deadc29f548283b8a2e7065b70cb89734f520de48a8f55b9222418e13781cde045f814e0cee02c71f69efac28bec0b326464836036d4855d236c48d21787238a
6
+ metadata.gz: 48ed0e912d2bb3f92f00f7cc712065c249763e4f5e8e33c5ff7e4cd72d8744d26eb028278d17dbe27f391bb91fcf5c05e2139f2b48171df1a4d8fba518c0d01b
7
+ data.tar.gz: 189249162e3449417fcf5c408bf68f2d8fcf11f86f30b1da6a812fc4f3cb265368df15144ae824383b6c812839432762a17d6c78e2acc2449dc58742e5c35d49
@@ -21,5 +21,5 @@ script:
21
21
  - awesome_bot bin/assets/test-ssl --allow-ssl
22
22
  - awesome_bot bin/assets/test-invalid.md --allow-redirect --allow-dupe
23
23
  - awesome_bot bin/assets/test-request-delay -d 1
24
- - awesome_bot README.md --allow-dupe --white-list gph.is,giphy,travis-ci.org,codeload,badge,rubydoc,rubygems,circleci,codeship
24
+ - awesome_bot README.md --allow-dupe --white-list gph.is,giphy,travis-ci.org,codeload,badge,rubydoc,rubygems,circleci,codeship,blob/master
25
25
  - gem install awesome_bot
@@ -2,6 +2,10 @@
2
2
 
3
3
  Changes by [Daniel Khamsing][] unless otherwise noted.
4
4
 
5
+ # 1.16.0
6
+
7
+ - add `--base-url` option (check markdown relative links)
8
+
5
9
  # 1.15.0
6
10
 
7
11
  - add `--skip-save-results` option
data/README.md CHANGED
@@ -27,6 +27,7 @@ Usage: awesome_bot [file or files]
27
27
  --allow-ssl SSL errors are allowed
28
28
  --allow-redirect Redirected URLs are allowed
29
29
  --allow-timeout URLs that time out are allowed
30
+ --base-url [base url] Base URL to use for relative links
30
31
  -d, --request-delay [seconds] Set request delay
31
32
  -t, --set-timeout [seconds] Set connection timeout
32
33
  --skip-save-results Skip saving results
@@ -82,6 +83,9 @@ $ awesome_bot README.md --allow-timeout -t 5
82
83
  $ awesome_bot README.md --allow 403,429
83
84
  # allow status code errors 403 and 429
84
85
  # --allow 301 would be similar to --allow-redirect
86
+
87
+ $ awesome_bot README.md --base-url https://github.com/IDR/idr-notebooks/blob/master/
88
+ # will check relative links using the base url provided
85
89
  ```
86
90
 
87
91
  ```shell
@@ -1,7 +1,6 @@
1
1
 
2
2
  3. [L056] 405 https://www.google.com/events/io
3
3
  5. [L130] 500 http://decentralizecamp.com/
4
- 6. [L138] 405 https://emberfest.eu/
5
4
  02. [L0138] 401 https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/
6
5
  03. [L0145] 401 https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html
7
6
  04. [L0146] 401 https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/OOP_ObjC/Introduction/Introduction.html
@@ -12,15 +12,17 @@ module AwesomeBot
12
12
  skip_dupe = false
13
13
  timeout = nil
14
14
  delay = 0
15
+ base = nil
15
16
  else
16
17
  white_listed = options['whitelist']
17
18
  skip_dupe = options['allowdupe']
18
19
  timeout = options['timeout']
19
20
  delay = options['delay']
20
21
  delay = 0 if delay.nil?
22
+ base = options['baseurl']
21
23
  end
22
24
 
23
- links = links_filter(links_find(content))
25
+ links = links_filter(links_find(content, base))
24
26
 
25
27
  r = Result.new(links, white_listed)
26
28
  r.skip_dupe = skip_dupe
@@ -23,6 +23,7 @@ module AwesomeBot
23
23
  opts.on('--allow-ssl', TrueClass, 'SSL errors are allowed') { |val| options['allow_ssl'] = val }
24
24
  opts.on('--allow-redirect', TrueClass, 'Redirected URLs are allowed') { |val| options['allow_redirect'] = val }
25
25
  opts.on('--allow-timeout', TrueClass, 'URLs that time out are allowed') { |val| options['allow_timeout'] = val }
26
+ opts.on('--base-url [base url]', String, 'Base URL to use for relative links') { |val| options['base_url'] = val }
26
27
  opts.on('-d', '--request-delay [seconds]', Integer, 'Set request delay') { |val| options['delay'] = val }
27
28
  opts.on('-t', '--set-timeout [seconds]', Integer, 'Set connection timeout') { |val| options['timeout'] = val }
28
29
  opts.on('--skip-save-results', TrueClass, 'Skip saving results') { |val| options['no_results'] = val }
@@ -77,6 +78,9 @@ module AwesomeBot
77
78
 
78
79
  puts "> Checking links in #{filename}"
79
80
 
81
+ base = options['base_url']
82
+ puts "> Will check relative links with base URL #{base}" unless base.nil?
83
+
80
84
  errors = options['errors']
81
85
  puts "> Will allow errors: #{errors.join ','}" unless errors.nil?
82
86
 
@@ -113,7 +117,8 @@ module AwesomeBot
113
117
  'allowdupe' => skip_dupe,
114
118
  'delay' => delay,
115
119
  'timeout' => timeout,
116
- 'whitelist' => white_listed
120
+ 'whitelist' => white_listed,
121
+ 'baseurl' => base
117
122
  }
118
123
 
119
124
  threads = delay == nil ? 10 : 1
@@ -35,9 +35,21 @@ module AwesomeBot
35
35
  end
36
36
  end
37
37
 
38
- def links_find(content)
38
+ def links_find(content, url_base=nil)
39
39
  require 'uri'
40
- URI.extract(content, /http()s?/)
40
+ ext = URI.extract(content, /http()s?/)
41
+ return ext if url_base.nil?
42
+
43
+ rel = get_relative_links content, url_base
44
+ return rel + ext
45
+ end
46
+
47
+ def get_relative_links(content, base)
48
+ links = content.scan /\].*?\)/
49
+ links.reject { |x| x.include?('http') || x.include?('#') }
50
+ .map { |x| x.sub '](', ''}
51
+ .map { |x| x =~ /\S/ ? x.match(/^\S*/) : x }
52
+ .map { |x| "#{base}#{x}"}
41
53
  end
42
54
  end # class
43
55
  end
@@ -5,5 +5,5 @@ module AwesomeBot
5
5
  'Great for "awesome" projects.'
6
6
  PROJECT_URL = 'https://github.com/dkhamsing/awesome_bot'
7
7
 
8
- VERSION = '1.15.0'
8
+ VERSION = '1.16.0'
9
9
  end
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.15.0
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Khamsing
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel