Skip to content

Commit 88b1f5c

Browse files
authored
Merge pull request #703 from fartem/ci-32
2024-08-08 v. 6.4.2.1: added duplicates checker for links
2 parents bf1ebfe + 05a5156 commit 88b1f5c

File tree

9 files changed

+64
-4
lines changed

9 files changed

+64
-4
lines changed

.github/workflows/checks.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ jobs:
7070
continue-on-error: true
7171
run: ruby -r "./ci/last_reachable_checker.rb" -e "::CI::LastReachableChecker.new.process"
7272

73+
duplicate_links_checker:
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v2
77+
- name: Set up Ruby
78+
uses: ruby/setup-ruby@v1
79+
with:
80+
ruby-version: ${{ env.RUBY_VERSION }}
81+
- name: Run duplicate links checker
82+
run: ruby -r "./ci/duplicate_links_checker.rb" -e "::CI::DuplicateLinksChecker.new.process"
83+
7384
rubocop:
7485
runs-on: ubuntu-latest
7586
steps:

ci/ci_job.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CIJob
1010
private_constant :PROCESS_NO_IMPL_ERROR
1111

1212
# Main entry of job class that runs your check.
13+
# @return {Void}
1314
def run
1415
puts("#{self.class.name} started...")
1516

@@ -19,6 +20,8 @@ def run
1920
end
2021

2122
# Use this method in your realization when task completed with error.
23+
# @param {String} details
24+
# @return {Void}
2225
def end_with_error(details)
2326
details.call
2427

@@ -29,6 +32,7 @@ def end_with_error(details)
2932

3033
# Job realization.
3134
# You should override this method in your realization.
35+
# @return {Void}
3236
def process
3337
raise(::PROCESS_NO_IMPL_ERROR)
3438
end

ci/duplicate_links_checker.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
require_relative './ci_job'
4+
5+
module CI
6+
# CI job that checks last link in README reachable status.
7+
class DuplicateLinksChecker < CIJob
8+
# Process LastReachableChecker
9+
# @return {Void}
10+
def process
11+
check
12+
end
13+
14+
private
15+
16+
# @return {Void}
17+
def check
18+
links = []
19+
20+
regex = %r{https://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))}
21+
22+
::File.readlines('README.md').each do |line|
23+
link = line.match(regex)
24+
25+
next unless link
26+
27+
links << link[0]
28+
end
29+
30+
return if links.size == links.uniq.size
31+
32+
error = "DuplicateLinksChecker ends with an error from. You have #{links.size - links.uniq.size} duplicates."
33+
end_with_error(-> { puts(error) })
34+
end
35+
end
36+
end

ci/last_reachable_checker.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ module CI
88
# CI job that checks last link in README reachable status.
99
class LastReachableChecker < CIJob
1010
# Process LastReachableChecker
11+
# @return {Void}
1112
def process
1213
check
1314
end
1415

1516
private
1617

18+
# @return {Void}
1719
def check
1820
readme = ::File.readlines('README.md')
1921
last_solution = readme.last
2022

21-
uri = ::URI.extract(last_solution)
22-
parsed_uri = uri.first[0, uri.first.length - 1]
23+
regex = %r{https://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))}
2324

24-
url = ::URI.parse(parsed_uri)
25+
url = ::URI.parse(last_solution.match(regex)[0])
2526
req = ::Net::HTTP.new(url.host, url.port)
2627
req.use_ssl = true if url.scheme == 'https'
2728
res = req.request_head(url.path)

ci/links_checker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ module CI
66
# CI job that checks links in solutions.
77
class LinksChecker < ::CI::CIJob
88
# Process LinksChecker.
9+
# @return {Void}
910
def process
1011
check('easy')
1112
end
1213

1314
private
1415

1516
# @param {String} difficulty
17+
# @return {Void}
1618
def check(difficulty)
1719
path = "./lib/#{difficulty}"
1820
solutions = ::Dir.entries(path).reject { |file_name| file_name.start_with?('.') }

ci/readme_checker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ module CI
66
# CI job that checks links in README.
77
class ReadmeChecker < ::CI::CIJob
88
# Process ReadmeChecker.
9+
# @return {Void}
910
def process
1011
check('easy')
1112
end
1213

1314
private
1415

1516
# @param {String} difficulty
17+
# @return {Void}
1618
def check(difficulty)
1719
path = "./lib/#{difficulty}"
1820
solutions = ::Dir.entries(path).reject { |file_name| file_name.start_with?('.') }

ci/tests_checker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ module CI
66
# CI job that checks tests for solutions.
77
class TestsChecker < ::CI::CIJob
88
# Process TestsChecker.
9+
# @return {Void}
910
def process
1011
check('easy')
1112
end
1213

1314
private
1415

1516
# @param {String} difficulty
17+
# @return {Void}
1618
def check(difficulty)
1719
path = "./lib/#{difficulty}"
1820
solutions = ::Dir.entries(path).reject { |file_name| file_name.start_with?('.') }

ci/version_checker.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ module CI
99
# CI job that checks project version.
1010
class VersionChecker < ::CI::CIJob
1111
# Process VersionChecker.
12+
# @return {Void}
1213
def process
1314
check
1415
end
1516

1617
private
1718

19+
# @return {Void}
1820
def check
1921
local_spec = ::Gem::Specification.load('leetcode-ruby.gemspec')
2022

leetcode-ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'English'
55
::Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 3.0'
77
s.name = 'leetcode-ruby'
8-
s.version = '6.4.2'
8+
s.version = '6.4.2.1'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'

0 commit comments

Comments
 (0)