Skip to content
Open
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
26 changes: 26 additions & 0 deletions lib/quarantine/databases/google_sheets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ def write_items(table_name, items)
raise Quarantine::DatabaseError
end

sig do
params(
table_name: String,
items: T::Array[Item]
).void
end
def append_items(table_name, items)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit tests for this method

worksheet = spreadsheet.worksheet_by_title(table_name)
first_row = worksheet.rows.first
headers = first_row ? first_row.reject { |cell| cell.nil? || cell.empty? } : []

current_row_count = worksheet.num_rows

new_rows = items.map do |item|
headers.map do |header|
item[header].to_s
end
end

# Always insert all items at the end without checking for existing IDs
worksheet.insert_rows(current_row_count + 1, new_rows)
worksheet.save
rescue GoogleDrive::Error, Google::Apis::Error
raise Quarantine::DatabaseError
end

private

sig { returns(GoogleDrive::Session) }
Expand Down