Skip to content

Commit

Permalink
Avoid creating duplicate projects
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Nov 6, 2023
1 parent 2b19fb8 commit bb245ce
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def to_s

def sync
check_url
return unless self.persisted?
fetch_repository
fetch_owner
fetch_dependencies
Expand All @@ -51,8 +52,15 @@ def check_url

response = conn.get
return unless response.success?
update(url: response.env.url.to_s)
# TODO avoid duplicates

new_name = response.env.url.to_s
return if new_name == url
existing_projects = Project.where(url: new_name)
if existing_projects.present?
self.destroy
else
update(url: response.env.url.to_s)
end
rescue
# failed to load
end
Expand Down

0 comments on commit bb245ce

Please sign in to comment.