sla 0.3.3 → 0.3.5

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
  SHA256:
3
- metadata.gz: 9490644ba70e3da7f217f5293b85aaa203f57a51d01988a128be223f4334b5a4
4
- data.tar.gz: 2c4dceedf37fa8ed810453fd87711db3b3cd085261152793dd68f6275e3d6c57
3
+ metadata.gz: d0a57c3ece35437abab2fb3737be5b85568b1154a65716b7442fac76f93aace9
4
+ data.tar.gz: e9a05c9cab3a639800ec43a0502c9f75eece89e1cf24b86085f6df416c38a031
5
5
  SHA512:
6
- metadata.gz: 94c5c9bf6f91cefab617dfdb2bf50719fcbbeece4f6e2df1b1528ebcc647652ed25ced8f31bbfdd202dc7858bcb13e4e86ed7c0b5c9ca670b053008fdf7b761b
7
- data.tar.gz: 882b2031c63f1d33282245a3ac1258585a67f98fb95d8b7822fd0ead0c01cdc88e5eed1804a68bc3bbefd50e2a5a526afb5ae27244de806852b53cc46abfe363
6
+ metadata.gz: fdd577b6843dc52f92cd99835e84df4eab460c45191fc592de35b64a41c706772b27e6371c2872e1fe353e0289d6e6d26455970ea0edb4d07c8c08cdc91b910d
7
+ data.tar.gz: 96b768f6bd64d1b6f8c4e280af5c6983ff079f60a0103de0f037bc45421377395bc1dc93e30461d2aa36c1d3075cc865473410bd89bf6ba5aaf1e167ca2a16a1
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://travis-ci.com/DannyBen/sla.svg?branch=master)](https://travis-ci.com/DannyBen/sla)
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 ignore? page
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.pages
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/command.rb CHANGED
@@ -50,10 +50,10 @@ module SLA
50
50
  Formatters::TTY.new
51
51
  end
52
52
 
53
- execute url, checker, formatter
53
+ run! url, checker, formatter
54
54
  end
55
55
 
56
- def execute(url, checker, formatter)
56
+ def run!(url, checker, formatter)
57
57
  page = Page.new url
58
58
  checker.check page do |action, page|
59
59
  success = formatter.handle action, page
@@ -6,12 +6,11 @@ module SLA
6
6
  attr_accessor :count, :failed
7
7
 
8
8
  def initialize
9
- @count = 0
10
- @failed = 0
9
+ @count, @failed = 0, 0
11
10
  end
12
11
 
13
12
  def success?
14
- failed == 0
13
+ count > 0 and failed == 0
15
14
  end
16
15
 
17
16
  def handle(action, page)
@@ -10,9 +10,14 @@ module SLA
10
10
  @count += 1
11
11
 
12
12
  return if page.valid?
13
-
14
13
  @failed += 1
15
14
 
15
+ show_status page
16
+ end
17
+
18
+ private
19
+
20
+ def show_status(page)
16
21
  if last_source
17
22
  say "!txtpur!SOURCE #{last_source}"
18
23
  @last_source = nil
@@ -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
- @count += 1
10
+ show_check_status page
11
11
 
12
- show_error = false
12
+ when :skip
13
+ say " !txtblu!SKIP!txtrst! #{page.depth} #{page.url}"
13
14
 
14
- if page.valid?
15
- status = "PASS"
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
- say " #{color}#{status}!txtrst! #{page.depth} #{page.url}"
25
- say " !txtred!#{page.code}!txtrst! #{page.error}" if show_error
18
+ private
26
19
 
27
- when :skip
28
- say " !txtblu!SKIP!txtrst! #{page.depth} #{page.url}"
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
- class Page
2
- attr_reader :uri, :parent, :depth
3
-
4
- def initialize(uri, parent: nil, depth: 0)
5
- if uri.is_a? String
6
- uri = "http://#{uri}" unless uri.start_with? 'http'
7
- uri = URI.parse uri
8
- uri.fragment = false
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
- @uri, @parent, @depth = uri, parent, depth
12
- end
15
+ def error
16
+ response.error
17
+ end
13
18
 
14
- def error
15
- response.error
16
- end
19
+ def code
20
+ response.code || 'ERR'
21
+ end
17
22
 
18
- def code
19
- response.code || 'ERR'
20
- end
23
+ def external?
24
+ parent ? (uri.host != parent.uri.host) : false
25
+ end
21
26
 
22
- def external?
23
- parent ? (uri.host != parent.uri.host) : false
24
- end
27
+ def inspect
28
+ "#<Page url: #{url}, depth: #{depth}>"
29
+ end
25
30
 
26
- def inspect
27
- "#<Page url: #{url}, depth: #{depth}>"
28
- end
31
+ def pages
32
+ @pages ||= pages!
33
+ end
29
34
 
30
- def pages
31
- @pages ||= pages!
32
- end
35
+ def url
36
+ uri.to_s
37
+ end
33
38
 
34
- def url
35
- uri.to_s
36
- end
39
+ def valid?
40
+ !response.error
41
+ end
37
42
 
38
- def valid?
39
- !response.error
40
- end
43
+ private
41
44
 
42
- private
45
+ def anchors
46
+ @anchors ||= dom.css('a[href]')
47
+ end
43
48
 
44
- def anchors
45
- @anchors ||= dom.css('a[href]')
46
- end
49
+ def content
50
+ @content ||= response.content
51
+ end
47
52
 
48
- def content
49
- @content ||= response.content
50
- end
53
+ def dom
54
+ @dom ||= Nokogiri::HTML content
55
+ end
51
56
 
52
- def dom
53
- @dom ||= Nokogiri::HTML content
54
- end
57
+ def normalize_url(new_url)
58
+ new_url = URI.parse new_url
59
+ new_url.fragment = false
55
60
 
56
- def normalize_url(new_url)
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
- result = new_url.absolute? ? new_url : URI.join(url, new_url)
63
+ result.scheme =~ /^http/ ? result.to_s : nil
64
+ end
61
65
 
62
- result.scheme =~ /^http/ ? result.to_s : nil
63
- end
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
- def pages!
66
- result = {}
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
- def response
77
- @response ||= response!
78
- end
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
@@ -1,3 +1,3 @@
1
1
  module SLA
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.5"
3
3
  end
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.3
4
+ version: 0.3.5
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: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -16,48 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.7.1
19
+ version: 0.7.2
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.7'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.7.1
26
+ version: 0.7.2
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: mister_bin
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '0.7'
33
+ version: 0.7.3
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '0.7'
40
+ version: 0.7.3
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: webcache
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0.7'
47
+ version: 0.8.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '0.7'
54
+ version: 0.8.0
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: nokogiri
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -103,14 +97,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
97
  requirements:
104
98
  - - ">="
105
99
  - !ruby/object:Gem::Version
106
- version: 2.4.0
100
+ version: 2.7.0
107
101
  required_rubygems_version: !ruby/object:Gem::Requirement
108
102
  requirements:
109
103
  - - ">="
110
104
  - !ruby/object:Gem::Version
111
105
  version: '0'
112
106
  requirements: []
113
- rubygems_version: 3.0.3
107
+ rubygems_version: 3.4.3
114
108
  signing_key:
115
109
  specification_version: 4
116
110
  summary: Command Line Site Link Analyzer