-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor dev.to sync script * Update workflow file * Prepare classes for http adapters * Added tests. Changed code to use http adapters * Update coderabbit ignore rules * fix coderabbit warnings * Update bin/sync/images_downloader.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update bin/sync/sync.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update test/integration/sync_with_devto_test.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update test/integration/sync_with_devto_test.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Move retries to module * chore: fix code style * sync posts * run sync * run sync * run sync * run sync * fix tests * Skip canonical URL update on dev.to for articles with matching local slug and up-to-date canonical URL * synced dev.to --------- Co-authored-by: Dmitry Gorodnichy <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Paul Keen <[email protected]>
- Loading branch information
1 parent
c93b8a5
commit d182950
Showing
240 changed files
with
4,258 additions
and
1,999 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,49 @@ | ||
require "fileutils" | ||
require "yaml" | ||
|
||
module ArticleCleaner | ||
SYNC_STATUS_FILE = "sync_status.yml".freeze | ||
ARTICLE_FILE = "index.md".freeze | ||
|
||
def cleanup_renamed_articles | ||
raise ArgumentError, "Working directory doesn't exist" unless Dir.exist?(working_dir) | ||
|
||
deleted_folders = [] | ||
slugs = load_slugs_from_yaml | ||
|
||
Dir.glob("#{working_dir}/*").each do |folder_path| | ||
next unless File.directory?(folder_path) && File.exist?("#{folder_path}/#{ARTICLE_FILE}") | ||
|
||
folder_name = File.basename(folder_path) | ||
unless slugs.include?(folder_name) | ||
begin | ||
FileUtils.rm_rf(folder_path) | ||
deleted_folders << folder_name | ||
puts "Deleted folder: #{folder_name}" | ||
rescue => e | ||
puts "Failed to delete folder #{folder_name}: #{e.message}" | ||
end | ||
end | ||
end | ||
deleted_folders | ||
end | ||
|
||
private | ||
|
||
def load_slugs_from_yaml | ||
yaml_path = File.join(working_dir, SYNC_STATUS_FILE) | ||
|
||
begin | ||
yaml_data = YAML.load_file(yaml_path) | ||
raise "Invalid YAML structure" unless yaml_data.is_a?(Hash) | ||
|
||
yaml_data.values.map do |article| | ||
raise "Invalid article data structure" unless article.is_a?(Hash) && article[:slug] | ||
article[:slug] | ||
end | ||
rescue => e | ||
logger.error "Failed to load slugs from YAML: #{e.message}" | ||
[] | ||
end | ||
end | ||
end |
This file contains 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,59 @@ | ||
require "json" | ||
|
||
module ArticleSyncChecker | ||
USERNAME = "jetthoughts".freeze | ||
SYNC_STATUS_FILE = "sync_status.yml".freeze | ||
USELESS_WORDS = %w[and the a but to is so].freeze | ||
|
||
def update_sync_status | ||
ensure_sync_status_file_exists | ||
@sync_status = sync_status | ||
update_status(fetch_articles) | ||
save_sync_status | ||
end | ||
|
||
private | ||
|
||
def ensure_sync_status_file_exists | ||
sync_file_path = File.join(working_dir, SYNC_STATUS_FILE) | ||
|
||
unless File.exist?(sync_file_path) | ||
File.write(sync_file_path, {}.to_yaml) | ||
end | ||
end | ||
|
||
def save_sync_status | ||
File.write(File.join(working_dir, SYNC_STATUS_FILE), @sync_status.to_yaml) | ||
end | ||
|
||
def fetch_articles | ||
response = http_client.get_articles(USERNAME, 0) | ||
JSON.parse(response.body) | ||
end | ||
|
||
def slug(article) | ||
slug_parts = article["slug"].split("-")[0..-2] | ||
tags = article["tags"] ? article["tags"].split(", ") : [] | ||
selected_tags = tags.first(2) | ||
[slug_parts, selected_tags] | ||
.flatten | ||
.uniq | ||
.reject { |segment| USELESS_WORDS.include?(segment) } | ||
.compact | ||
.join("-") | ||
end | ||
|
||
def update_status(articles) | ||
articles.each do |article| | ||
id = article["id"] | ||
edited_at = article["edited_at"] || article["created_at"] | ||
|
||
@sync_status[id] ||= {edited_at: edited_at, slug: slug(article), synced: false} | ||
|
||
if @sync_status[id][:edited_at] != edited_at | ||
@sync_status[id][:edited_at] = edited_at | ||
@sync_status[id][:synced] = false | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.