Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Repository < ApplicationRecord
has_many :releases

has_many :repository_usages, dependent: :delete_all
has_many :_package_usages, through: :repository_usages, source: :package_usage

scope :owner, ->(owner) { where(owner: owner) }
scope :subgroup, ->(owner, subgroup) { where(owner: owner).where("lower(full_name) ilike ?", "#{owner}/#{subgroup}/%") }
Expand Down
13 changes: 8 additions & 5 deletions app/views/api/v1/repositories/_repository.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
json.extract! repository, :id, :uuid, :full_name, :owner, :description, :archived, :fork, :pushed_at, :size, :stargazers_count, :open_issues_count,
:forks_count, :subscribers_count, :default_branch, :last_synced_at, :etag, :topics, :latest_commit_sha, :homepage, :language, :has_issues,
:has_wiki, :has_pages, :mirror_url, :source_name, :license, :status, :scm, :pull_requests_enabled, :icon_url, :metadata, :created_at, :updated_at,
:dependencies_parsed_at, :dependency_job_id, :html_url, :commit_stats, :previous_names, :tags_count, :template, :template_full_name
json.extract! repository, :id, :uuid, :full_name, :owner, :description, :archived, :fork, :pushed_at, :size, :stargazers_count, :open_issues_count,
:forks_count, :subscribers_count, :default_branch, :last_synced_at, :etag, :topics, :latest_commit_sha, :homepage, :language, :has_issues,
:has_wiki, :has_pages, :mirror_url, :source_name, :license, :status, :scm, :pull_requests_enabled, :icon_url, :metadata, :created_at, :updated_at,
:dependencies_parsed_at, :dependency_job_id, :html_url, :commit_stats, :previous_names, :tags_count, :template, :template_full_name

json.repository_url api_v1_host_repository_url(repository.host, repository)
json.tags_url api_v1_host_repository_tags_url(repository.host, repository)
json.releases_url api_v1_host_repository_releases_url(repository.host, repository)
json.manifests_url api_v1_host_repository_manifests_url(repository.host, repository)
json.owner_url api_v1_host_owner_url(repository.host, repository.owner)
json.download_url repository.download_url
json.download_url repository.download_url
json.package_usages repository._package_usages do |package_usage|
json.extract! package_usage, :id, :name, :ecosystem, :key
end
1 change: 0 additions & 1 deletion config/credentials.yml.enc

This file was deleted.

31 changes: 30 additions & 1 deletion lib/tasks/dinum.rake
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ namespace :dinum do
Dinum.hosts_list_sync_problem
end

desc "Cleanup old data"
task cleanup: [:destroy_old_hosts, :destroy_old_owners] do
end


desc "Destroy no longer used hosts"
task destroy_old_hosts: :environment do
urls = Dinum.accounts_data.map { |host_domain, data| "https://#{host_domain}" }
Expand All @@ -273,7 +278,31 @@ namespace :dinum do
puts "No hosts to destroy"
end
end

desc "Destroy no longer used owners"
task destroy_old_owners: :environment do
Dinum.general_purpose_hosts.each do |host_domain, host_data|
host = Host.find_by(url: "https://#{host_domain}")
next unless host
logins = host_data["owners"].keys
owners = host.owners.where(Owner.arel_table.lower(Owner.arel_table[:login]).not_in(logins.map(&:downcase)))
if owners.any?
puts "!! Destroying #{owners.count}/#{host.owners.count} owners for #{host.name} (enter to continue) !!"
STDIN.gets
owners.destroy_all
end
repositories = host.repositories.where(Repository.arel_table.lower(Repository.arel_table[:owner]).not_in(logins.map(&:downcase)))
if repositories.any?
puts "!! Destroying #{repositories.count}/#{host.repositories.count} repositories for #{host.name} (enter to continue) !!"
STDIN.gets
while repositories.any?
puts repositories.count
repositories.limit(500).destroy_all
end
end
end
end
end

# To load in console :
# To load in console :
# require 'rake'; Rails.application.load_tasks