sla 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -11
- data/lib/sla/checker.rb +14 -5
- data/lib/sla/formatters/base.rb +2 -3
- data/lib/sla/formatters/simple.rb +6 -1
- data/lib/sla/formatters/tty.rb +13 -9
- data/lib/sla/formatters/verbose.rb +23 -16
- data/lib/sla/page.rb +67 -65
- data/lib/sla/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7ab0a2c8232984458067a9d9a501011c50c4e6e3c500631a516b2f495b02fa6
|
4
|
+
data.tar.gz: 3d1af9be056a2cabc8dbf39dc37d14795b549f4f4e19803be82663d761eb7e5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10d4a3dd2bcffcba10b4866ab5200dd9ded805c73bc196666efbe827005ea10620180d61667d02e9aa28c809dba07e4ca6d6dd7f2f6fd8668d3c741d526c332f
|
7
|
+
data.tar.gz: 9998c057a56599449bb8077c1fdfba755d70a4877d83a6cbe9d25b243248d6b588d08bdc2c8cb9db87b6ecbf90852a8efde1eb31871e13ed7705d220bbc2484c
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
Site Link Analyzer
|
2
|
-
==================================================
|
1
|
+
# Site Link Analyzer
|
3
2
|
|
4
3
|
[![Gem Version](https://badge.fury.io/rb/sla.svg)](https://badge.fury.io/rb/sla)
|
5
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/DannyBen/sla/workflows/Test/badge.svg)](https://github.com/DannyBen/sla/actions?query=workflow%3ATest)
|
6
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/f78192aead8a74535a24/maintainability)](https://codeclimate.com/github/DannyBen/sla/maintainability)
|
7
6
|
|
8
7
|
---
|
@@ -11,25 +10,30 @@ SLA is a simple broken links checker, with built in caching.
|
|
11
10
|
|
12
11
|
![SLA Demo](demo/cast.svg "SLA Demo")
|
13
12
|
|
14
|
-
Install
|
15
|
-
--------------------------------------------------
|
13
|
+
## Install
|
16
14
|
|
17
|
-
|
15
|
+
### Install using Ruby
|
16
|
+
|
17
|
+
```shell
|
18
18
|
$ gem install sla
|
19
19
|
```
|
20
20
|
|
21
|
+
### Install using Docker
|
22
|
+
|
23
|
+
```shell
|
24
|
+
alias sla='docker run --rm -it --network host -v /tmp/sla_cache:/app/cache dannyben/sla'
|
25
|
+
```
|
26
|
+
|
27
|
+
The `--network host` flag is only necessary if you intend to check links on `localhost`.
|
21
28
|
|
22
|
-
Features
|
23
|
-
--------------------------------------------------
|
29
|
+
## Features
|
24
30
|
|
25
31
|
- Easy to use command line interface.
|
26
32
|
- Built in caching, to avoid overtaxing the server.
|
27
33
|
- Show and save list of broken links to a log file.
|
28
34
|
- Exits with non zero code on failure, for CI integration.
|
29
35
|
|
30
|
-
|
31
|
-
Usage
|
32
|
-
--------------------------------------------------
|
36
|
+
## Usage
|
33
37
|
|
34
38
|
```
|
35
39
|
$ sla --help
|
@@ -91,3 +95,12 @@ Examples:
|
|
91
95
|
sla example.com --ignore "/admin /customer/login"
|
92
96
|
|
93
97
|
```
|
98
|
+
|
99
|
+
## Contributing / Support
|
100
|
+
|
101
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
102
|
+
to contribute, feel free to [open an issue][issues].
|
103
|
+
|
104
|
+
---
|
105
|
+
|
106
|
+
[issues]: https://github.com/DannyBen/sla/issues
|
data/lib/sla/checker.rb
CHANGED
@@ -9,14 +9,11 @@ module SLA
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def check(page, &block)
|
12
|
-
return if
|
13
|
-
return if page.depth >= max_depth
|
14
|
-
return unless page.valid?
|
12
|
+
return if skip? page
|
15
13
|
|
16
14
|
yield [:source, page] if block_given?
|
17
15
|
|
18
|
-
pages = page
|
19
|
-
pages.reject! { |page| page.external? } if !check_external
|
16
|
+
pages = page_list page
|
20
17
|
|
21
18
|
pages.each do |page|
|
22
19
|
if checked.has_key? page.url or ignore? page
|
@@ -37,6 +34,18 @@ module SLA
|
|
37
34
|
|
38
35
|
private
|
39
36
|
|
37
|
+
def page_list(page)
|
38
|
+
if check_external
|
39
|
+
page.pages
|
40
|
+
else
|
41
|
+
page.pages.reject { |page| page.external? }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def skip?(page)
|
46
|
+
ignore?(page) or page.depth >= max_depth or !page.valid?
|
47
|
+
end
|
48
|
+
|
40
49
|
def ignore?(page)
|
41
50
|
return false unless ignore
|
42
51
|
|
data/lib/sla/formatters/base.rb
CHANGED
data/lib/sla/formatters/tty.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
module SLA
|
2
2
|
module Formatters
|
3
3
|
class TTY < Base
|
4
|
-
attr_reader :last_source
|
4
|
+
attr_reader :last_source, :screen_width
|
5
5
|
|
6
6
|
def handle(action, page)
|
7
|
-
screen_width = terminal_width
|
8
|
-
|
7
|
+
@screen_width = terminal_width
|
9
8
|
@last_source = page.url if action == :source
|
10
9
|
|
11
10
|
return unless action == :check
|
12
11
|
@count += 1
|
13
12
|
|
13
|
+
show_status page
|
14
|
+
end
|
15
|
+
|
16
|
+
def footer_prefix
|
17
|
+
terminal? ? "\033[2K\n" : "\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def show_status(page)
|
14
23
|
if page.valid?
|
15
24
|
status = "PASS"
|
16
25
|
color = "!txtgrn!"
|
@@ -34,11 +43,6 @@ module SLA
|
|
34
43
|
resay "[#{failed}/#{count} @ #{page.depth}] #{color}#{status}!txtrst! #{url} "
|
35
44
|
end
|
36
45
|
|
37
|
-
def footer_prefix
|
38
|
-
terminal? ? "\033[2K\n" : "\n"
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
46
|
end
|
43
47
|
end
|
44
|
-
end
|
48
|
+
end
|
@@ -5,30 +5,37 @@ module SLA
|
|
5
5
|
case action
|
6
6
|
when :source
|
7
7
|
say "\n!txtpur!SOURCE #{page.url}"
|
8
|
-
|
8
|
+
|
9
9
|
when :check
|
10
|
-
|
10
|
+
show_check_status page
|
11
11
|
|
12
|
-
|
12
|
+
when :skip
|
13
|
+
say " !txtblu!SKIP!txtrst! #{page.depth} #{page.url}"
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
color = "!txtgrn!"
|
17
|
-
else
|
18
|
-
@failed += 1
|
19
|
-
status = "FAIL"
|
20
|
-
color = "!txtred!"
|
21
|
-
show_error = page.code != 404
|
22
|
-
end
|
15
|
+
end
|
16
|
+
end
|
23
17
|
|
24
|
-
|
25
|
-
say " !txtred!#{page.code}!txtrst! #{page.error}" if show_error
|
18
|
+
private
|
26
19
|
|
27
|
-
|
28
|
-
|
20
|
+
def show_check_status(page)
|
21
|
+
@count += 1
|
22
|
+
|
23
|
+
show_error = false
|
29
24
|
|
25
|
+
if page.valid?
|
26
|
+
status = "PASS"
|
27
|
+
color = "!txtgrn!"
|
28
|
+
else
|
29
|
+
@failed += 1
|
30
|
+
status = "FAIL"
|
31
|
+
color = "!txtred!"
|
32
|
+
show_error = page.code != 404
|
30
33
|
end
|
34
|
+
|
35
|
+
say " #{color}#{status}!txtrst! #{page.depth} #{page.url}"
|
36
|
+
say " !txtred!#{page.code}!txtrst! #{page.error}" if show_error
|
31
37
|
end
|
38
|
+
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
data/lib/sla/page.rb
CHANGED
@@ -1,86 +1,88 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module SLA
|
2
|
+
class Page
|
3
|
+
attr_reader :uri, :parent, :depth
|
4
|
+
|
5
|
+
def initialize(uri, parent: nil, depth: 0)
|
6
|
+
if uri.is_a? String
|
7
|
+
uri = "http://#{uri}" unless uri.start_with? 'http'
|
8
|
+
uri = URI.parse uri
|
9
|
+
uri.fragment = false
|
10
|
+
end
|
11
|
+
|
12
|
+
@uri, @parent, @depth = uri, parent, depth
|
9
13
|
end
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
def error
|
16
|
+
response.error
|
17
|
+
end
|
13
18
|
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
def code
|
20
|
+
response.code || 'ERR'
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
def external?
|
24
|
+
parent ? (uri.host != parent.uri.host) : false
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
def inspect
|
28
|
+
"#<Page url: #{url}, depth: #{depth}>"
|
29
|
+
end
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
def pages
|
32
|
+
@pages ||= pages!
|
33
|
+
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
def url
|
36
|
+
uri.to_s
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
def valid?
|
40
|
+
!response.error
|
41
|
+
end
|
37
42
|
|
38
|
-
|
39
|
-
!response.error
|
40
|
-
end
|
43
|
+
private
|
41
44
|
|
42
|
-
|
45
|
+
def anchors
|
46
|
+
@anchors ||= dom.css('a[href]')
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
def content
|
50
|
+
@content ||= response.content
|
51
|
+
end
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
53
|
+
def dom
|
54
|
+
@dom ||= Nokogiri::HTML content
|
55
|
+
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
57
|
+
def normalize_url(new_url)
|
58
|
+
new_url = URI.parse new_url
|
59
|
+
new_url.fragment = false
|
55
60
|
|
56
|
-
|
57
|
-
new_url = URI.parse new_url
|
58
|
-
new_url.fragment = false
|
61
|
+
result = new_url.absolute? ? new_url : URI.join(url, new_url)
|
59
62
|
|
60
|
-
|
63
|
+
result.scheme =~ /^http/ ? result.to_s : nil
|
64
|
+
end
|
61
65
|
|
62
|
-
|
63
|
-
|
66
|
+
def pages!
|
67
|
+
result = {}
|
68
|
+
anchors.each do |a|
|
69
|
+
url = normalize_url a['href']
|
70
|
+
next unless url
|
71
|
+
page = Page.new url, parent: self, depth: depth+1
|
72
|
+
result[url] = page
|
73
|
+
end
|
74
|
+
result.values
|
75
|
+
end
|
64
76
|
|
65
|
-
|
66
|
-
|
67
|
-
anchors.each do |a|
|
68
|
-
url = normalize_url a['href']
|
69
|
-
next unless url
|
70
|
-
page = Page.new url, parent: self, depth: depth+1
|
71
|
-
result[url] = page
|
77
|
+
def response
|
78
|
+
@response ||= response!
|
72
79
|
end
|
73
|
-
result.values
|
74
|
-
end
|
75
80
|
|
76
|
-
|
77
|
-
|
78
|
-
|
81
|
+
def response!
|
82
|
+
response = WebCache.get url
|
83
|
+
@uri = response.base_uri
|
84
|
+
response
|
85
|
+
end
|
79
86
|
|
80
|
-
def response!
|
81
|
-
response = WebCache.get url
|
82
|
-
@uri = response.base_uri
|
83
|
-
response
|
84
87
|
end
|
85
|
-
|
86
|
-
end
|
88
|
+
end
|
data/lib/sla/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.2.16
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Command Line Site Link Analyzer
|