-
Notifications
You must be signed in to change notification settings - Fork 0
wip #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pftg
wants to merge
1
commit into
master
Choose a base branch
from
multiple-sources-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
wip #222
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) | |
|
||
require "sync/app" | ||
require "sync/sync_script" | ||
require "sync/fetchers/dev_to_article_fetcher" | ||
|
||
App.configure do |config| | ||
config.logger = Logger.new(STDOUT, level: :warn) | ||
config.fetcher_class = Sync::Fetchers::DevToArticleFetcher | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainEnsure namespace consistency. The configuration uses 🏁 Script executed: #!/bin/bash
# Check for declarations with both namespaces
rg "class DevToArticleFetcher" --type ruby -B 2 -A 1
# Look for files that might be moving the class to the new namespace
rg "Sync::Fetchers::DevToArticleFetcher" --type ruby Length of output: 308 Fix Namespace Consistency
|
||
end | ||
|
||
App.new(args: ARGV).run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "sync/logging" | ||
require "sync/retryable" | ||
|
||
module Sync | ||
class Fetcher | ||
include Logging | ||
include Retryable | ||
|
||
def fetch_articles | ||
raise NotImplementedError, "Subclasses must implement #fetch_articles" | ||
end | ||
|
||
def fetch(id) | ||
raise NotImplementedError, "Subclasses must implement #fetch" | ||
end | ||
|
||
def fetch_image(url) | ||
raise NotImplementedError, "Subclasses must implement #fetch_image" | ||
end | ||
|
||
def need_to_update_remote?(article_data, article_sync_data) | ||
raise NotImplementedError, "Subclasses must implement #need_to_update_remote?" | ||
end | ||
|
||
def update_meta_on_dev_to(id, data) | ||
raise NotImplementedError, "Subclasses must implement #update_meta_on_dev_to" | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
require "yaml" | ||
require "sync/fetcher" | ||
require "sync/logging" | ||
|
||
module Sync | ||
module LocalFolderFetcher | ||
include Fetcher | ||
include Logging | ||
|
||
def fetch_articles | ||
articles = [] | ||
Dir.glob(File.join(folder_path, "*")).select { |f| File.directory?(f) }.each do |dir| | ||
article_id = File.basename(dir) | ||
article = fetch(article_id) | ||
articles << article if article | ||
end | ||
articles | ||
end | ||
|
||
def fetch(id) | ||
path = File.join(folder_path, id.to_s) | ||
return nil unless Dir.exist?(path) | ||
|
||
content_file = File.join(path, "content.md") | ||
return nil unless File.exist?(content_file) | ||
|
||
content = File.read(content_file) | ||
metadata = extract_metadata(content) | ||
|
||
process_article({ | ||
"id" => id, | ||
"title" => metadata["title"] || id, | ||
"description" => metadata["description"], | ||
"body_markdown" => strip_frontmatter(content), | ||
"cover_image" => find_cover_image(path), | ||
"slug" => id, | ||
"canonical_url" => metadata["canonical_url"] | ||
}) | ||
end | ||
|
||
def fetch_image(path) | ||
return nil unless File.exist?(path) | ||
File.binread(path) | ||
end | ||
|
||
def need_to_update_remote?(article_data, article_sync_data) | ||
# Local folders don't need remote updates | ||
false | ||
end | ||
|
||
def update_meta_on_dev_to(id, data) | ||
# No-op for local folders | ||
nil | ||
end | ||
|
||
private | ||
|
||
def folder_path | ||
raise NotImplementedError, "Implementers must define #folder_path" | ||
end | ||
|
||
def find_cover_image(dir) | ||
%w[thumbnail.jpeg cover.jpg cover.jpeg thumbnail.jpg].each do |name| | ||
path = File.join(dir, name) | ||
return path if File.exist?(path) | ||
end | ||
nil | ||
end | ||
|
||
def extract_metadata(content) | ||
frontmatter = content.match(/\A---\n(.*?)\n---/m) | ||
return {} unless frontmatter | ||
|
||
begin | ||
YAML.safe_load(frontmatter[1]) || {} | ||
rescue | ||
{} | ||
end | ||
end | ||
|
||
def strip_frontmatter(content) | ||
content.sub(/\A---\n.*?\n---\n/m, '') | ||
end | ||
|
||
def process_article(article) | ||
article["devto_slug"] = article["slug"] | ||
article["slug"] = article["slug"] | ||
article | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
require "zip" | ||
require "yaml" | ||
require "sync/fetcher" | ||
require "sync/logging" | ||
|
||
module Sync | ||
module ZipFolderFetcher | ||
include Fetcher | ||
include Logging | ||
|
||
def fetch_articles | ||
articles = [] | ||
|
||
Zip::File.open(zip_path) do |zip_file| | ||
folder_entries = zip_file.entries.select { |e| e.ftype == :directory } | ||
|
||
folder_entries.each do |folder_entry| | ||
article_id = folder_entry.name.chomp('/') | ||
article = fetch_from_zip(zip_file, article_id) | ||
articles << article if article | ||
end | ||
end | ||
|
||
articles | ||
end | ||
|
||
def fetch(id) | ||
Zip::File.open(zip_path) do |zip_file| | ||
fetch_from_zip(zip_file, id) | ||
end | ||
rescue => e | ||
logger.error("Error fetching article from zip: #{e.message}") | ||
nil | ||
end | ||
|
||
def fetch_image(path) | ||
return nil unless path && path.start_with?("zip://") | ||
|
||
path = path.gsub("zip://", "") | ||
|
||
Zip::File.open(zip_path) do |zip_file| | ||
entry = zip_file.find_entry(path) | ||
return nil unless entry | ||
|
||
entry.get_input_stream.read | ||
end | ||
rescue => e | ||
logger.error("Error fetching image from zip: #{e.message}") | ||
nil | ||
end | ||
|
||
def need_to_update_remote?(article_data, article_sync_data) | ||
# Zip archives don't need remote updates | ||
false | ||
end | ||
|
||
def update_meta_on_dev_to(id, data) | ||
# No-op for zip archives | ||
nil | ||
end | ||
|
||
private | ||
|
||
def zip_path | ||
raise NotImplementedError, "Implementers must define #zip_path" | ||
end | ||
|
||
def fetch_from_zip(zip_file, id) | ||
folder_name = "#{id}/" | ||
content_entry = zip_file.find_entry("#{folder_name}content.md") | ||
return nil unless content_entry | ||
|
||
content = content_entry.get_input_stream.read | ||
metadata = extract_metadata(content) | ||
|
||
cover_image = find_cover_image_in_zip(zip_file, folder_name) | ||
|
||
process_article({ | ||
"id" => id, | ||
"title" => metadata["title"] || id, | ||
"description" => metadata["description"], | ||
"body_markdown" => strip_frontmatter(content), | ||
"cover_image" => cover_image ? "zip://#{cover_image.name}" : nil, | ||
"slug" => id, | ||
"canonical_url" => metadata["canonical_url"] | ||
}) | ||
end | ||
|
||
def find_cover_image_in_zip(zip_file, folder_name) | ||
%w[thumbnail.jpeg cover.jpg cover.jpeg thumbnail.jpg].each do |name| | ||
path = "#{folder_name}#{name}" | ||
entry = zip_file.find_entry(path) | ||
return entry if entry | ||
end | ||
nil | ||
end | ||
|
||
def extract_metadata(content) | ||
frontmatter = content.match(/\A---\n(.*?)\n---/m) | ||
return {} unless frontmatter | ||
|
||
begin | ||
YAML.safe_load(frontmatter[1]) || {} | ||
rescue | ||
{} | ||
end | ||
end | ||
|
||
def strip_frontmatter(content) | ||
content.sub(/\A---\n.*?\n---\n/m, '') | ||
end | ||
|
||
def process_article(article) | ||
article["devto_slug"] = article["slug"] | ||
article["slug"] = article["slug"] | ||
article | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify path consistency.
The require path
sync/fetchers/dev_to_article_fetcher
suggests a different file structure than what's shown in the reviewed files. The DevToArticleFetcher we reviewed is atlib/sync/dev_to_article_fetcher.rb
, not in afetchers
subdirectory.🏁 Script executed:
Length of output: 309
Action Required: Update Require Statement to Reflect Actual File Location
lib/sync/dev_to_article_fetcher.rb
exists, but no file is present in afetchers
subdirectory.bin/sync_with_devto
(line 9) from: