@@ -23,34 +23,38 @@ def younger_than?(version, days_old)
2323 'Hello, world!'
2424end
2525
26- get '/prunables' do
26+ # Returns all container packages along with their pruning status, i.e. whether they can/can't be pruned and why
27+ get '/images' do
2728 packages = github . get ( 'orgs/BerkeleyLibrary/packages' , { package_type : :container } )
2829 logger . info "Scanning #{ packages . size } packages for prunable images: #{ packages . collect ( &:name ) . sort } "
2930
30- packages . each do |pkg |
31- logger . info "Determining prunable images for #{ pkg . name } "
32-
33- next unless pkg . repository
34-
35- permatags = %w( latest edge )
36- permatags += github . branches ( pkg . repository . full_name ) . collect ( &:name )
37- permatags += github . tags ( pkg . repository . full_name ) . collect ( &:name )
38-
39- images = github . get ( "orgs/#{ pkg . owner . login } /packages/#{ pkg . package_type } /#{ pkg . name } /versions" ) . collect do |image |
40- if has_permatag? image , permatags
41- verdict = :permatagged
42- elsif younger_than? image , 7
43- verdict = :recent
44- else
45- verdict = :prunable
31+ prunables = [ ] . tap do |sofar |
32+ packages . each do |pkg |
33+ logger . info "Determining prunable images for #{ pkg . name } "
34+
35+ next unless pkg . repository
36+
37+ permatags = %w( latest edge )
38+ permatags += github . branches ( pkg . repository . full_name ) . collect ( &:name )
39+ permatags += github . tags ( pkg . repository . full_name ) . collect ( &:name )
40+
41+ github . get ( "orgs/#{ pkg . owner . login } /packages/#{ pkg . package_type } /#{ pkg . name } /versions" ) . each do |image |
42+ if has_permatag? image , permatags
43+ pruning_status = :permatagged
44+ elsif younger_than? image , 7
45+ pruning_status = :recent
46+ else
47+ pruning_status = :prunable
48+ end
49+
50+ sofar << {
51+ image : image . to_attrs ,
52+ pruning_status : pruning_status ,
53+ can_be_pruned : pruning_status == :prunable ,
54+ }
4655 end
47- # { image:, verdict: }
4856 end
49-
50- json ( {
51- repo : pkg . repository . full_name ,
52- package : pkg . name ,
53- images :,
54- } )
5557 end
58+
59+ json prunables
5660end
0 commit comments