fetch_util 0.3.0 → 0.3.1

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.
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FetchUtil
4
+ class Browser
5
+ module SiteStabilization
6
+ module GitlabRepo
7
+ private
8
+
9
+ def gitlab_repo_url?(url)
10
+ uri = URI.parse(url)
11
+ host = uri.host.to_s.downcase
12
+ (host == "gitlab.com" || host.end_with?(".gitlab.com")) && uri.path.split("/").reject(&:empty?).length == 2
13
+ rescue URI::InvalidURIError
14
+ false
15
+ end
16
+
17
+ def stabilize_gitlab_repo(page)
18
+ retry_until_timeout(capped_timeout(8.0), interval: 0.2) do
19
+ safe_evaluate(page, <<~JS, default: 0).to_i >= 300
20
+ (() => {
21
+ const readme = document.querySelector('[data-testid="blob-viewer-content"] .blob-viewer[data-path="README.md"] .file-content.md, .blob-viewer[data-path="README.md"] .file-content.md');
22
+ return readme ? (readme.innerText || readme.textContent || '').replace(/\s+/g, ' ').trim().length : 0;
23
+ })()
24
+ JS
25
+ end
26
+
27
+ settle_after_stabilization(0.25)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -4,9 +4,11 @@ module FetchUtil
4
4
  class Browser
5
5
  module SiteStabilization
6
6
  autoload :CommunityAndMarketplace, "fetch_util/browser/site_stabilization/community_and_marketplace"
7
+ autoload :GitlabRepo, "fetch_util/browser/site_stabilization/gitlab_repo"
7
8
  autoload :SocialPlatforms, "fetch_util/browser/site_stabilization/social_platforms"
8
9
 
9
10
  include CommunityAndMarketplace
11
+ include GitlabRepo
10
12
  include SocialPlatforms
11
13
  end
12
14
  end
@@ -11,6 +11,7 @@ module FetchUtil
11
11
  return stabilize_instagram(page) if instagram_url?(url)
12
12
  return stabilize_facebook(page) if facebook_url?(url)
13
13
  return stabilize_ebay_search(page) if ebay_search_url?(url)
14
+ return stabilize_gitlab_repo(page) if gitlab_repo_url?(url)
14
15
 
15
16
  reached_idle = !@wait_for_idle || wait_for_idle_or_content(page)
16
17
  preserve_consent = preserve_consent_wall?(page, url)
@@ -17,6 +17,7 @@ module FetchUtil
17
17
  content_type
18
18
  suspect
19
19
  warnings
20
+ error_message
20
21
  ].freeze
21
22
 
22
23
  class_option :log_path, type: :string, desc: "Append-only request log path"