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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Rakefile +5 -0
- data/lib/fetch_util/assets/extract.js +1 -1
- data/lib/fetch_util/browser/site_stabilization/gitlab_repo.rb +32 -0
- data/lib/fetch_util/browser/site_stabilization.rb +2 -0
- data/lib/fetch_util/browser/stabilization/page_flow.rb +1 -0
- data/lib/fetch_util/cli.rb +1 -0
- data/lib/fetch_util/fetcher.rb +545 -42
- data/lib/fetch_util/raw_docs_fallback.rb +40 -3
- data/lib/fetch_util/result.rb +100 -3
- data/lib/fetch_util/version.rb +1 -1
- metadata +2 -1
|
@@ -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)
|