mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
error handling on third party repo hosts (#622)
This commit is contained in:
@@ -3,7 +3,6 @@ class SyncRepoMetadataJob < ApplicationJob
|
||||
|
||||
retry_on HTTP::TimeoutError, HTTP::ConnectionError, wait: :exponentially_longer, attempts: 3
|
||||
retry_on JSON::ParserError, wait: 10.seconds, attempts: 2
|
||||
discard_on ArgumentError # Invalid repository URLs
|
||||
|
||||
def perform(repository_id)
|
||||
repository = Repository.find_by(id: repository_id)
|
||||
@@ -17,6 +16,11 @@ class SyncRepoMetadataJob < ApplicationJob
|
||||
return unless user
|
||||
|
||||
service = RepoHost::ServiceFactory.for_url(user, repository.url)
|
||||
unless service
|
||||
Rails.logger.info "[SyncRepoMetadataJob] Unsupported repository host for #{repository.url}"
|
||||
return
|
||||
end
|
||||
|
||||
metadata = service.fetch_repo_metadata
|
||||
|
||||
if metadata
|
||||
@@ -25,9 +29,6 @@ class SyncRepoMetadataJob < ApplicationJob
|
||||
else
|
||||
Rails.logger.warn "[SyncRepoMetadataJob] No metadata returned for #{repository.url}"
|
||||
end
|
||||
rescue ArgumentError => e
|
||||
Rails.logger.error "[SyncRepoMetadataJob] #{e.message} for repository #{repository.id}"
|
||||
raise # Discard job for unsupported hosts
|
||||
rescue => e
|
||||
Rails.logger.error "[SyncRepoMetadataJob] Unexpected error: #{e.message}"
|
||||
raise # Retry for other errors
|
||||
|
||||
@@ -13,6 +13,7 @@ class ProjectRepoMapping < ApplicationRecord
|
||||
message: "must be a valid repository URL"
|
||||
}
|
||||
|
||||
validate :repo_host_supported
|
||||
validate :repo_url_exists
|
||||
|
||||
IGNORED_PROJECTS = [
|
||||
@@ -26,6 +27,13 @@ class ProjectRepoMapping < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def repo_host_supported
|
||||
host = RepoHost::ServiceFactory.host_for_url(repo_url)
|
||||
unless host && RepoHost::ServiceFactory.supported_hosts.include?(host)
|
||||
errors.add(:repo_url, "We only support GitHub repositories")
|
||||
end
|
||||
end
|
||||
|
||||
def repo_url_exists
|
||||
unless GitRemote.check_remote_exists(repo_url)
|
||||
errors.add(:repo_url, "is not cloneable")
|
||||
|
||||
Reference in New Issue
Block a user