Skip to content

Commit d780667

Browse files
committed
Include created_at in compact index /info endpoint
Pass the version's created_at timestamp to CompactIndex::GemVersion so it is included in the /info response. The timestamp is formatted as ISO 8601 UTC. This enables Bundler clients to read publication dates from the compact index directly, avoiding separate V1 API calls per gem when implementing supply chain security features like min_age checks. Depends on rubygems/compact_index adding created_at as an optional 8th field to the GemVersion struct.
1 parent 2f7a39b commit d780667

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

app/models/gem_info.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ def compute_compact_index_info
108108
end
109109
end
110110

111-
name, platform, checksum, info_checksum, ruby_version, rubygems_version, = r
112-
CompactIndex::GemVersion.new(name, platform, Version._sha256_hex(checksum), info_checksum, deps, ruby_version, rubygems_version)
111+
name, platform, checksum, info_checksum, ruby_version, rubygems_version, created_at, = r
112+
CompactIndex::GemVersion.new(name, platform, Version._sha256_hex(checksum), info_checksum, deps, ruby_version, rubygems_version,
113+
created_at&.utc&.iso8601)
113114
end
114115
end
115116

test/models/gem_info_test.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class GemInfoTest < ActiveSupport::TestCase
1616
context "#compact_index_info" do
1717
setup do
1818
rubygem = create(:rubygem, name: "example")
19-
version = create(:version, rubygem: rubygem, number: "1.0.0", info_checksum: "qw2dwe")
19+
@version = create(:version, rubygem: rubygem, number: "1.0.0", info_checksum: "qw2dwe")
2020
dep = create(:rubygem, name: "exmaple_dep")
21-
create(:dependency, rubygem: dep, version: version)
21+
create(:dependency, rubygem: dep, version: @version)
2222

2323
@expected_info = [CompactIndex::GemVersion.new(
2424
"1.0.0",
@@ -27,7 +27,8 @@ class GemInfoTest < ActiveSupport::TestCase
2727
"qw2dwe",
2828
[CompactIndex::Dependency.new("exmaple_dep", "= 1.0.0")],
2929
">= 2.0.0",
30-
">= 2.6.3"
30+
">= 2.6.3",
31+
@version.created_at.utc.iso8601
3132
)]
3233
end
3334

@@ -37,6 +38,12 @@ class GemInfoTest < ActiveSupport::TestCase
3738
assert_equal @expected_info, info
3839
end
3940

41+
should "include created_at timestamp in gem version" do
42+
info = GemInfo.new("example").compact_index_info
43+
44+
assert_equal @version.created_at.utc.iso8601, info.first.created_at
45+
end
46+
4047
should "write cache" do
4148
Rails.cache.expects(:write).with("info/example", @expected_info)
4249

0 commit comments

Comments
 (0)