Skip to content

Fix-project-importer #495

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

Merged
merged 2 commits into from
Feb 13, 2025
Merged
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
33 changes: 25 additions & 8 deletions app/jobs/upload_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,33 @@ def load_projects_data(locale, repository, owner)
variables: { repository:, owner:, expression: "#{ENV.fetch('GITHUB_WEBHOOK_REF')}:#{locale}/code" }
)

if response.data.errors.any?
error_messages = response.data.errors.messages.map { |error| error }
error_details = response.data.errors.details.map { |error| error }
error_type = error_details.dig(0, 1, 0, 'type')
handle_graphql_errors(response)
response
end

# Handle NOT_FOUND errors as a special case, as this can happen when the repo is first created
raise GraphQL::Client::Error, "GraphQL query failed with errors: #{error_messages}. Details: #{error_details}" unless error_type == 'NOT_FOUND'
end
def handle_graphql_errors(response)
errors = response&.errors.presence || response&.data&.errors
return if errors.blank?

response
error_messages, error_details, error_type = extract_error_info(errors)

# Handle NOT_FOUND errors as a special case, as this can happen when the repo is first created
raise GraphQL::Client::Error, "GraphQL query failed with errors: #{error_messages}. Details: #{error_details}" unless error_type == 'NOT_FOUND'
end

def extract_error_info(errors)
error_type = nil
if errors.is_a?(Array) && errors.first.is_a?(Hash)
# Query level error
error_messages = errors.map { |error| error }
error_details = errors.map { |error| error }
error_type = error_details.dig(0, 1, 0, 'type')
else
# Top level error
error_messages = errors.messages['data'].first
error_details = errors.details['data'].first['message']
end
[error_messages, error_details, error_type]
end

def format_project(project_dir, locale, repository, owner)
Expand Down
2 changes: 1 addition & 1 deletion lib/project_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def attach_media_if_needed
if existing_media_file
next if existing_media_file.blob.checksum == media_checksum(media_file[:io])

existing_media.purge
existing_media_file.purge
end
if images.include?(media_file)
project.images.attach(**media_file)
Expand Down