diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-25 21:14:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-25 21:14:53 +0300 |
commit | 14d02affb4c147873993d8fa065ad16d7c91482d (patch) | |
tree | ef6a884b218f4e9958a15cd4784e0f9591e8f489 | |
parent | 6eceaa36d1e565e7ab8f5d1d082200f18cddfb12 (diff) |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | app/graphql/types/container_repository_tag_type.rb | 1 | ||||
-rw-r--r-- | app/models/container_repository.rb | 1 | ||||
-rw-r--r-- | doc/api/graphql/reference/index.md | 1 | ||||
-rw-r--r-- | lib/container_registry/tag.rb | 30 | ||||
-rw-r--r-- | locale/gitlab.pot | 2 | ||||
-rw-r--r-- | spec/graphql/types/container_repository_tag_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/container_registry/tag_spec.rb | 25 | ||||
-rw-r--r-- | spec/models/container_repository_spec.rb | 17 |
8 files changed, 59 insertions, 20 deletions
diff --git a/app/graphql/types/container_repository_tag_type.rb b/app/graphql/types/container_repository_tag_type.rb index ce58694d237..7691844645a 100644 --- a/app/graphql/types/container_repository_tag_type.rb +++ b/app/graphql/types/container_repository_tag_type.rb @@ -22,6 +22,7 @@ module Types field :location, GraphQL::Types::String, null: false, description: 'URL of the tag.' field :name, GraphQL::Types::String, null: false, description: 'Name of the tag.' field :path, GraphQL::Types::String, null: false, description: 'Path of the tag.' + field :published_at, Types::TimeType, null: true, description: 'Timestamp when the tag was published.' field :referrers, [Types::ContainerRepositoryReferrerType], null: true, description: 'Referrers for this tag.' field :revision, GraphQL::Types::String, null: true, description: 'Revision of the tag.' field :short_revision, GraphQL::Types::String, null: true, description: 'Short revision of the tag.' diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 0257848af37..3b1c10c0259 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -658,6 +658,7 @@ class ContainerRepository < ApplicationRecord tag.manifest_digest = raw_tag['digest'] tag.revision = raw_tag['config_digest'].to_s.split(':')[1] || '' tag.referrers = raw_tag['referrers'] + tag.published_at = raw_tag['published_at'] tag end end diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index cc021811b06..8a7da91a296 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -16734,6 +16734,7 @@ A tag from a container repository. | <a id="containerrepositorytaglocation"></a>`location` | [`String!`](#string) | URL of the tag. | | <a id="containerrepositorytagname"></a>`name` | [`String!`](#string) | Name of the tag. | | <a id="containerrepositorytagpath"></a>`path` | [`String!`](#string) | Path of the tag. | +| <a id="containerrepositorytagpublishedat"></a>`publishedAt` | [`Time`](#time) | Timestamp when the tag was published. | | <a id="containerrepositorytagreferrers"></a>`referrers` | [`[ContainerRepositoryReferrer!]`](#containerrepositoryreferrer) | Referrers for this tag. | | <a id="containerrepositorytagrevision"></a>`revision` | [`String`](#string) | Revision of the tag. | | <a id="containerrepositorytagshortrevision"></a>`shortRevision` | [`String`](#string) | Short revision of the tag. | diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb index 0000a0641be..4cf4cd71f86 100644 --- a/lib/container_registry/tag.rb +++ b/lib/container_registry/tag.rb @@ -4,7 +4,7 @@ module ContainerRegistry class Tag include Gitlab::Utils::StrongMemoize - attr_reader :repository, :name, :updated_at, :referrers + attr_reader :repository, :name, :updated_at, :referrers, :published_at attr_writer :created_at, :manifest_digest, :revision, :total_size delegate :registry, :client, to: :repository @@ -101,24 +101,20 @@ module ContainerRegistry # this function will set and memoize a created_at # to avoid a #config_blob call. def force_created_at_from_iso8601(string_value) - date = - begin - DateTime.iso8601(string_value) - rescue ArgumentError - nil - end + date = parse_iso8601_string(string_value) instance_variable_set(ivar(:memoized_created_at), date) end def updated_at=(string_value) return unless string_value - @updated_at = - begin - DateTime.iso8601(string_value) - rescue ArgumentError - nil - end + @updated_at = parse_iso8601_string(string_value) + end + + def published_at=(string_value) + return unless string_value + + @published_at = parse_iso8601_string(string_value) end def layers @@ -155,5 +151,13 @@ module ContainerRegistry client.delete_repository_tag_by_digest(repository.path, digest) end + + private + + def parse_iso8601_string(string_value) + DateTime.iso8601(string_value) + rescue ArgumentError + nil + end end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 04b9a1c15c7..0d8d9fdba93 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -1935,7 +1935,7 @@ msgstr "" msgid "AIPoweredSM|AI-powered features" msgstr "" -msgid "AIPoweredSM|By enabling this feature, you agree to the %{terms_link_start}GitLab Testing Agreement%{link_end}." +msgid "AIPoweredSM|By enabling this feature, you agree to the %{link_start}GitLab Testing Agreement%{link_end}." msgstr "" msgid "AIPoweredSM|Enable %{link_start}AI-powered features%{link_end} for this instance." diff --git a/spec/graphql/types/container_repository_tag_type_spec.rb b/spec/graphql/types/container_repository_tag_type_spec.rb index 28bfb2b46de..4c91c39fcd6 100644 --- a/spec/graphql/types/container_repository_tag_type_spec.rb +++ b/spec/graphql/types/container_repository_tag_type_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['ContainerRepositoryTag'], feature_category: :container_registry do fields = %i[name path location digest revision short_revision - total_size created_at can_delete user_permissions referrers] + total_size created_at can_delete user_permissions referrers published_at] it { expect(described_class.graphql_name).to eq('ContainerRepositoryTag') } diff --git a/spec/lib/container_registry/tag_spec.rb b/spec/lib/container_registry/tag_spec.rb index 8f9308f2127..42191cb121c 100644 --- a/spec/lib/container_registry/tag_spec.rb +++ b/spec/lib/container_registry/tag_spec.rb @@ -336,6 +336,31 @@ RSpec.describe ContainerRegistry::Tag, feature_category: :container_registry do it { is_expected.to eq(nil) } end end + + describe 'published_at=' do + subject do + tag.published_at = input + tag.published_at + end + + context 'with a valid input' do + let(:input) { 2.days.ago.iso8601 } + + it { is_expected.to eq(DateTime.iso8601(input)) } + end + + context 'with a nil input' do + let(:input) { nil } + + it { is_expected.to eq(nil) } + end + + context 'with an invalid input' do + let(:input) { 'not a timestamp' } + + it { is_expected.to eq(nil) } + end + end end end end diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index 25c28399abc..084e2dd7bd5 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -699,6 +699,10 @@ RSpec.describe ContainerRepository, :aggregate_failures, feature_category: :cont end context 'with a call to tags' do + let_it_be(:created_at) { 15.minutes.ago } + let_it_be(:updated_at) { 10.minutes.ago } + let_it_be(:published_at) { 5.minutes.ago } + let_it_be(:tags_response) do [ { @@ -707,8 +711,9 @@ RSpec.describe ContainerRepository, :aggregate_failures, feature_category: :cont config_digest: 'sha256:66b1132a0173910b01ee69583bbf2f7f1e4462c99efbe1b9ab5bf', media_type: 'application/vnd.oci.image.manifest.v1+json', size_bytes: 1234567890, - created_at: 5.minutes.ago, - updated_at: 5.minutes.ago, + created_at: created_at, + updated_at: updated_at, + published_at: published_at, referrers: [ { artifactType: 'application/vnd.example+type', @@ -722,8 +727,9 @@ RSpec.describe ContainerRepository, :aggregate_failures, feature_category: :cont config_digest: nil, media_type: 'application/vnd.oci.image.manifest.v1+json', size_bytes: 1234567892, - created_at: 10.minutes.ago, - updated_at: 10.minutes.ago + created_at: created_at, + updated_at: updated_at, + published_at: published_at } ] end @@ -759,7 +765,8 @@ RSpec.describe ContainerRepository, :aggregate_failures, feature_category: :cont revision: expected_revision, short_revision: expected_revision[0..8], created_at: DateTime.rfc3339(tags_response[index][:created_at].rfc3339), - updated_at: DateTime.rfc3339(tags_response[index][:updated_at].rfc3339) + updated_at: DateTime.rfc3339(tags_response[index][:updated_at].rfc3339), + published_at: DateTime.rfc3339(tags_response[index][:published_at].rfc3339) ) Array(tag.referrers).each_with_index do |ref, ref_index| |