diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index a63a74ab7978cdbc0f120082bfe20268e8a2c1d3..ee934d3ae093299d404cb61bd3a01ad1f0d0ce5c 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -43,6 +43,7 @@ # updated_at :datetime not null # about_id :uuid indexed => [about_type] # default_language_id :uuid not null, indexed +# locked_by_job_id :uuid # university_id :uuid not null, indexed # # Indexes diff --git a/app/services/git/providers/github.rb b/app/services/git/providers/github.rb index 3a3ee2d9d1f68f460f18c5ab3a13dba7b4791a65..1f94ba5565de9d4d2b23b0cc56285992cad021f7 100644 --- a/app/services/git/providers/github.rb +++ b/app/services/git/providers/github.rb @@ -1,5 +1,6 @@ class Git::Providers::Github < Git::Providers::Abstract BASE_URL = "https://github.com".freeze + COMMIT_BATCH_SIZE = 250 def url "#{BASE_URL}/#{repository}" @@ -67,8 +68,7 @@ class Git::Providers::Github < Git::Providers::Abstract def push(commit_message) return if !valid? || batch.empty? - new_tree = client.create_tree repository, batch, base_tree: tree[:sha] - commit = client.create_commit repository, commit_message, new_tree[:sha], branch_sha + commit = create_commit_from_batch(batch, commit_message) client.update_branch repository, default_branch, commit[:sha] # The repo changed, invalidate the tree @tree = nil @@ -77,6 +77,20 @@ class Git::Providers::Github < Git::Providers::Abstract true end + def create_commit_from_batch(batch, commit_message) + base_tree_sha = tree[:sha] + base_commit_sha = branch_sha + commit = nil + batch.each_slice(COMMIT_BATCH_SIZE) do |sub_batch| + puts "Creating commit with #{sub_batch.size} files." + new_tree = client.create_tree repository, sub_batch, base_tree: base_tree_sha + commit = client.create_commit repository, commit_message, new_tree[:sha], base_commit_sha + base_tree_sha = new_tree[:sha] + base_commit_sha = commit[:sha] + end + commit + end + def computed_sha(string) # Git SHA-1 is calculated from the String "blob <length>\x00<contents>" # Source: https://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html diff --git a/db/schema.rb b/db/schema.rb index c7cb717841e9a914771bd84880ffcb3ea08da853..f0a3a045c2aa3ae1465170573d4be95fb32d19e2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -148,8 +148,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_05_31_065216) do t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "heading_id" t.uuid "communication_website_id" + t.uuid "heading_id" t.string "migration_identifier" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id"