awesome_bot 1.8.5 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f195dc3e6ffcad817c7d912b22f7bb8d8b8e947d
4
- data.tar.gz: 291f0250d6f81cffa3b5361aed805c3646797886
3
+ metadata.gz: 9f0cbdb5d7a7e2db7fb90d76ce2c444cee6456b1
4
+ data.tar.gz: 6dee220ffd70eb6b7f8fe37302faf51f1b9e7d9e
5
5
  SHA512:
6
- metadata.gz: 77e634ea2d1a908496765ef33335e95a11c34137049c5d4f4b1b946daefa728bf8dc9110e3a55c25aeaa9c7e2ebc3bf7b08824182ab23358998696ee139395f0
7
- data.tar.gz: 39394dd0a2db5b3dd8225e74e51dc32d77f1f31bb0fa2e37bb43ad0c87b7cb9d65925aea6f16fd3d85826ebbede5f35a1810af6f21079ad4bbec9862f6910743
6
+ metadata.gz: 894ee0128f3b177805182a6c6e74fac43c150182383647e27e8a3b021302937752377c836c88654aaba51b0e983159af3a49e4ebd724ab3eccb15a9c773e08af
7
+ data.tar.gz: 7694fe013d9a93af945cceaffee1cf045eabf22258a59d52b69fbffeac20ea5cae8679ea1486b7f6ad29c342b3721eee19f62b5dd52dc1964b5b61378eb8fa3b
data/.travis.yml CHANGED
@@ -14,5 +14,8 @@ script:
14
14
  - awesome_bot bin/assets/test-redirect --allow-redirect
15
15
  - awesome_bot bin/assets/test-statuses --white-list bot,bad,super
16
16
  - awesome_bot bin/assets/test-errors
17
+ - awesome_bot -f bin/assets/test-no-issues,bin/assets/test-no-links
18
+ - awesome_bot -f bin/assets/test-no-issues,bin/assets/test-redirect --allow-redirect
19
+ - awesome_bot bin/assets/test-no-* --allow-redirect
17
20
  - awesome_bot README.md --allow-dupe --white-list gph.is,giphy,travis-ci.org,codeload,badge,rubydoc,rubygems,circleci
18
21
  - gem install awesome_bot
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Changes by [Daniel Khamsing][] unless otherwise noted.
4
4
 
5
+ # 1.9.0
6
+
7
+ - [cli] support checking multiple files (comma separated or `*` pattern i.e. `docs/*.md`), suggested by [Sota Yamashita](https://github.com/sotayamashita)
8
+ - [cli] use `optparse`
9
+
5
10
  # 1.8.5
6
11
 
7
12
  - [fix] request errors (make `get` requests), reported by [Richard Littauer](https://github.com/RichardLitt)
data/README.md CHANGED
@@ -18,19 +18,24 @@ Verify links in [awesome](https://github.com/sindresorhus/awesome) projects
18
18
 
19
19
  ### Command Line
20
20
 
21
- awesome_bot <file> [--allow-dupe] [--allow-redirect] [--allow-timeout] [--set-timeout d] [--white-list item1,item2,..]
22
- file Path to file, required as first argument
23
- --allow-dupe Duplicate URLs are allowed
24
- --allow-redirect Redirected URLs are allowed
25
- --allow-timeout URLs that time out are allowed
26
- --set-timeout Set connection timeout (seconds)
27
- --white-list Comma separated URLs/domains to white list
21
+ ```
22
+ Usage: awesome_bot [file or files]
23
+ awesome_bot [options]
24
+ -f, --files [files] Comma separated files to check
25
+ --allow-dupe Duplicate URLs are allowed
26
+ --allow-redirect Redirected URLs are allowed
27
+ --allow-timeout URLs that time out are allowed
28
+ -t, --set-timeout [seconds] Set connection timeout
29
+ -w, --white-list [urls] Comma separated URLs to white list
30
+ ```
28
31
 
29
- By default, `awesome_bot` flags duplicates and URL redirects.
32
+ - You can check multiple files (comma separated or `*` pattern, look below for details).
30
33
 
31
- - Use option `--allow-dupe` to allow duplicates.
32
- - Use option `--allow-redirect` to all redirects.
33
- - You can also white list specific links that will not be flagged (for dupe or redirect). `--white-list domain1.com/post/article,domain2.com` white lists `domain1.com/post/article` and all links matching `domain2.com`.
34
+ - By default, `awesome_bot` flags duplicates and URL redirects.
35
+
36
+ - Use option `--allow-dupe` to allow duplicates.
37
+ - Use option `--allow-redirect` to all redirects.
38
+ - You can white list links so that they won't be flagged. `-w domain1.com/post/article,domain2.com` white lists `domain1.com/post/article` and all links matching `domain2.com`.
34
39
 
35
40
  ### Examples
36
41
 
@@ -57,22 +62,17 @@ Issues :-(
57
62
  ```
58
63
 
59
64
  ```shell
60
- $ awesome_bot README.md --allow-dupe --allow-redirect --white-list rubydoc,giphy
61
- > Checking links in README.md
62
- > Will allow redirects
63
- > Will allow duplicate links
64
- > White list links matching: rubydoc, giphy
65
- Links to check: 41, 5 white listed, 29 unique
66
- 01. https://github.com/sindresorhus/awesome
67
- 02. https://travis-ci.org/dkhamsing/awesome_bot.svg
68
- # ...
69
- Checking URLs: ✓✓→✓✓→→→✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓→✓✓✓→✓
70
- Checking white listed URLs: ?✓
65
+ $ awesome_bot README.md --allow-dupe --allow-redirect --w rubydoc,giphy
66
+ # allow redirects, dupes and white list all links matching rubydoc and giphy
67
+
68
+ $ awesome_bot README.md,README-zh.md
69
+ # check links in 2 files
70
+
71
+ $ awesome_bot docs/*.md
72
+ # check all markdown files in docs/ directory
71
73
 
72
- > White listed:
73
- 1. [L005] 200 http://i.giphy.com/urvsFBDfR6N32.gif
74
- 2. [L093] 202 http://www.rubydoc.info/gems/awesome_bot
75
- No issues :-)
74
+ $ awesome_bot README.md --allow-timeout --t 5
75
+ # speed up validation by setting a timeout of 5s per link request and allowing timeouts
76
76
  ```
77
77
 
78
78
  ### Library
@@ -96,15 +96,15 @@ More information at [rubydoc](http://www.rubydoc.info/gems/awesome_bot).
96
96
  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:
97
97
 
98
98
  - https://github.com/tiimgreen/github-cheat-sheet
99
- - https://github.com/vinta/awesome-python
100
99
  - https://github.com/enaqx/awesome-react
100
+ - https://github.com/ziadoz/awesome-php
101
101
  - https://github.com/vsouza/awesome-ios
102
102
  - https://github.com/alebcay/awesome-shell
103
103
  - https://github.com/matteocrippa/awesome-swift
104
104
 
105
105
  and [more](status/status.md).
106
106
 
107
- Tip: Use the keyword `[ci skip]` in your commit title/message to selectively skip verification (if you are let's say working on a bunch of changes).
107
+ Tip: Use the keyword `[ci skip]` in your commit title/message to skip verification.
108
108
 
109
109
  ### Travis CI
110
110
 
@@ -182,7 +182,7 @@ As it happens, the default code snippet provided contain a redirect so adding a
182
182
  - awesome_bot README.md --white-list travis-ci
183
183
  ```
184
184
 
185
- You can also add a badge for other CI tools, I recommend checking out [shields.io](http://shields.io/).
185
+ You can also add a badge for other CI tools, check out [shields.io](http://shields.io/).
186
186
 
187
187
  ## Contact
188
188
 
@@ -5,101 +5,86 @@ require 'awesome_bot/version'
5
5
 
6
6
  # Command line interface
7
7
  module AwesomeBot
8
- OPTION_DUPE = 'allow-dupe'
9
- OPTION_REDIRECT = 'allow-redirect'
10
- OPTION_TIMEOUT_ALLOW = 'allow-timeout'
11
- OPTION_TIMEOUT_SET = 'set-timeout'
12
- OPTION_WHITE_LIST = 'white-list'
8
+ RESULTS_PREFIX = 'ab-results'
13
9
 
14
- RESULTS_FILE = 'ab-results.json'
10
+ class << self
11
+ def cli
12
+ require 'optparse'
15
13
 
16
- USAGE = "\t"
14
+ ARGV << '-h' if ARGV.empty?
17
15
 
18
- class << self
19
- def make_option(o)
20
- "--#{o}"
21
- end
16
+ options = {}
17
+ ARGV.options do |opts|
18
+ opts.banner = "Usage: #{PROJECT} [file or files] \n"\
19
+ " #{PROJECT} [options]"
22
20
 
23
- def cli
24
- option_d = make_option OPTION_DUPE
25
- option_r = make_option OPTION_REDIRECT
26
- option_t = make_option OPTION_TIMEOUT_SET
27
- option_t_a = make_option OPTION_TIMEOUT_ALLOW
28
- option_w = make_option OPTION_WHITE_LIST
29
-
30
- options = [
31
- option_d,
32
- option_r,
33
- option_t,
34
- option_t_a,
35
- option_w
36
- ]
37
-
38
- if ARGV.count == 0
39
- puts "Usage: #{PROJECT} <file> [#{option_d}] [#{option_r}] "\
40
- "[#{option_t_a}] [#{option_t} d] "\
41
- "[#{option_w} item1,item2,..]\n"\
42
- "#{USAGE} file Path to file, required as first argument\n"\
43
- "#{USAGE} #{option_d} Duplicate URLs are allowed \n"\
44
- "#{USAGE} #{option_r} Redirected URLs are allowed \n"\
45
- "#{USAGE} #{option_t_a} URLs that time out are allowed \n"\
46
- "#{USAGE} #{option_t} Set connection timeout (seconds) \n"\
47
- "#{USAGE} #{option_w} Comma separated URLs to white list \n"\
48
- "\nVersion #{VERSION}, see #{PROJECT_URL} for more information"
49
- exit
21
+ opts.on("-f", "--files [files]", Array, 'Comma separated files to check') { |val| options['files'] = val }
22
+ opts.on("--allow-dupe", TrueClass, 'Duplicate URLs are allowed') { |val| options['allow_dupe'] = val }
23
+ opts.on("--allow-redirect", TrueClass, 'Redirected URLs are allowed') { |val| options['allow_redirect'] = val }
24
+ opts.on("--allow-timeout", TrueClass, 'URLs that time out are allowed') { |val| options['allow_timeout'] = val }
25
+ opts.on("-t", "--set-timeout [seconds]", Integer, 'Set connection timeout') { |val| options['timeout'] = val }
26
+ opts.on("-w", "--white-list [urls]", Array, 'Comma separated URLs to white list') { |val| options['white_list'] = val }
27
+
28
+ opts.on_tail("--help") do
29
+ puts opts
30
+ exit
31
+ end
32
+ opts.parse!
50
33
  end
51
34
 
52
- filename = ARGV[0]
35
+ files = options['files']
36
+ if files.nil?
37
+ files = []
38
+ ARGV.each do |a|
39
+ files.push a if a !~ /^--.*/
40
+ end
41
+ end
53
42
 
54
- if options.include? filename
55
- puts "Usage: #{PROJECT} <file> [options] \n"\
56
- ' Path to file, requried as first argument'
57
- exit 1
43
+ summary = {}
44
+ files.each do |f|
45
+ summary[f] = cli_process(f, options)
58
46
  end
59
47
 
60
- # Check options
61
- user_options = ARGV.select { |o| o.include? '--' }
62
- options_diff = user_options - options
63
- if options_diff.count > 0
64
- puts "Error, invalid options: #{options_diff.join ', '} \n"
65
- puts "Valid options are #{options.join ', '}"
66
- exit 1
48
+ if summary.count>1
49
+ puts "\nSummary"
50
+
51
+ largest = 0
52
+ summary.each do |k, v|
53
+ s = k.size
54
+ largest = s if s>largest
55
+ end
56
+
57
+ summary.each do |k, v|
58
+ k_display = "%#{largest}.#{largest}s" % k
59
+ puts "#{k_display}: #{v}"
60
+ end
67
61
  end
68
62
 
63
+ summary.each { |k, v| exit 1 unless v==STATUS_OK }
64
+ end
65
+
66
+ def cli_process(filename, options)
69
67
  begin
70
68
  content = File.read filename
71
69
  rescue => error
72
70
  puts "File open error: #{error}"
73
- exit 1
71
+ return error
74
72
  end
75
73
 
76
74
  puts "> Checking links in #{filename}"
77
75
 
78
- if ARGV.count > 1
79
- options = ARGV.drop 1
76
+ skip_dupe = options['allow_dupe']
80
77
 
81
- skip_dupe = options.include? option_d
78
+ allow_redirects = options['allow_redirect']
79
+ puts '> Will allow redirects' if allow_redirects == true
82
80
 
83
- allow_redirects = options.include? option_r
84
- puts '> Will allow redirects' if allow_redirects == true
81
+ allow_timeouts = options['allow_timeout']
82
+ puts '> Will allow network timeouts' if allow_timeouts == true
85
83
 
86
- allow_timeouts = options.include? option_t_a
87
- puts '> Will allow network timeouts' if allow_timeouts == true
84
+ white_listed = options['white_list']
88
85
 
89
- if options.include? option_w
90
- i = options.find_index(option_w) + 1
91
- white_listed = options[i].split ','
92
- end
93
-
94
- if options.include? option_t
95
- i = options.find_index(option_t) + 1
96
- timeout = options[i].to_i
97
- puts "> Connection timeout = #{timeout}s"
98
- end
99
- else
100
- allow_redirects = false
101
- allow_timeouts = false
102
- end
86
+ timeout = options['timeout']
87
+ puts "> Connection timeout = #{timeout}s" unless timeout.nil?
103
88
 
104
89
  options = {
105
90
  'whitelist' => white_listed,
@@ -119,9 +104,13 @@ module AwesomeBot
119
104
  end
120
105
  end
121
106
 
107
+ allow_redirects = false if allow_redirects.nil?
108
+ allow_timeouts = false if allow_timeouts.nil?
109
+
122
110
  if r.success(allow_redirects, allow_timeouts) == true
123
111
  puts 'No issues :-)'
124
- r.write RESULTS_FILE
112
+ cli_write_results(filename, r)
113
+ return STATUS_OK
125
114
  else
126
115
  puts "\nIssues :-("
127
116
 
@@ -156,12 +145,16 @@ module AwesomeBot
156
145
  end
157
146
  end
158
147
 
159
- # write results json
160
- r.write RESULTS_FILE
161
- puts "\nWrote results to #{RESULTS_FILE}"
162
-
163
- exit 1
148
+ cli_write_results(filename, r)
149
+ return 'Issues'
164
150
  end
165
151
  end
152
+
153
+ def cli_write_results(f, r)
154
+ results_file_filter = f.gsub('/','-')
155
+ results_file = "#{RESULTS_PREFIX}-#{results_file_filter}.json"
156
+ r.write results_file
157
+ puts "\nWrote results to #{results_file}"
158
+ end
166
159
  end # class
167
160
  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.8.5'
8
+ VERSION = '1.9.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.8.5
4
+ version: 1.9.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: 2016-05-13 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel