@@ -23,7 +23,7 @@ class GithubIngestor < Ingestor # rubocop:disable Metrics/ClassLength
2323
2424 GITHUB_API_BASE = 'https://api.github.com/repos'
2525 CACHE_PREFIX = 'github_ingestor_'
26- TTL = 1 . week # time to live after the cache is deleted
26+ TTL = 1 . week # cache expiration time (time to live before cache expires)
2727
2828 def self . config
2929 {
@@ -57,7 +57,7 @@ def read(source_url)
5757 add_material to_material ( repo_data )
5858 end
5959 rescue StandardError => e
60- @messages << "#{ self . class . name } read failed, #{ e . message } "
60+ Rails . logger . error ( "#{ e . class } : read() failed, #{ e . message } " )
6161 end
6262
6363 private
@@ -94,13 +94,9 @@ def github_api_from_io(uri, parts)
9494 # url: url to open
9595 # ttl: time-to-live in seconds (default 7 days)
9696 def cache_fetch ( key , url )
97- Rails . cache . fetch ( key , expires_in : TTL ) do
97+ Rails . cache . fetch ( key , expires_in : TTL , skip_nil : true ) do
9898 JSON . parse ( open_url ( url ) . read )
9999 end
100- rescue StandardError => e
101- @messages << "#{ self . class . name } cache_fetch failed for #{ url } , #{ e . message } "
102- yield if block_given?
103- nil
104100 end
105101
106102 # Sets material hash keys and values and add them to material
@@ -137,15 +133,15 @@ def fetch_homepage_doc(url)
137133 Nokogiri ::HTML ( response . body )
138134 end
139135
140- # DEFINITION – Opens the GitHub homepage, fetches the 3 first >25 char <p> tags'text
136+ # DEFINITION – Opens the GitHub homepage, fetches the 3 first >50 char <p> tags'text
141137 # and joins them with a 'Read more...' link at the end of the description
142138 # Some of the first <p> tags were not descriptive, thus skipping them
143139 def fetch_definition ( doc , url )
144140 desc = ''
145141 round = 3
146142 doc . css ( 'p' ) . each do |p |
147- p_txt = p &.text &.strip &.gsub ( /\s +/ , ' ' )
148- next if ( p_txt . length < 50 ) || round . zero?
143+ p_txt = p &.text &.strip &.gsub ( /\s +/ , ' ' ) || ''
144+ next if p_txt . length < 50 || round . zero?
149145
150146 desc = "#{ desc } \n #{ p_txt } "
151147 round -= 1
@@ -187,6 +183,8 @@ def fetch_latest_release(full_name)
187183 # CONTRIBUTORS – Opens contributors API address and returns list of contributors
188184 def fetch_contributors ( contributors_url , full_name )
189185 contributors = cache_fetch ( "#{ CACHE_PREFIX } contributors_#{ full_name . gsub ( '/' , '_' ) } " , contributors_url )
186+ return [ ] unless contributors
187+
190188 contributors . map { |c | ( c [ 'login' ] ) }
191189 end
192190
@@ -200,7 +198,7 @@ def fetch_prerequisites(doc)
200198 # ... any tag with id containing "prereq" (EN) or "prerreq" (ES)
201199 prereq_paragraphs = fetch_prerequisites_from_id_or_class ( doc , prereq_paragraphs ) if prereq_paragraphs . empty?
202200
203- prereq_paragraphs &.join ( "\n " ) &.gsub ( /\n \n +/ , "\n " ) &.to_s &. strip
201+ prereq_paragraphs &.join ( "\n " ) &.gsub ( /\n \n +/ , "\n " ) &.strip || ''
204202 end
205203
206204 def fetch_prerequisites_from_h ( doc , prereq_paragraphs )
0 commit comments