Commit e38dc069 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '276432-refactor-container-registry-frontend-to-graphql-2' into 'master'

Add containerRepositoriesCount to project and group queries

See merge request gitlab-org/gitlab!48685
parents 5afdf7f6 e474d17d
...@@ -88,10 +88,13 @@ module Types ...@@ -88,10 +88,13 @@ module Types
field :container_repositories, field :container_repositories,
Types::ContainerRepositoryType.connection_type, Types::ContainerRepositoryType.connection_type,
null: true, null: true,
description: 'Container repositories of the project', description: 'Container repositories of the group',
resolver: Resolvers::ContainerRepositoriesResolver, resolver: Resolvers::ContainerRepositoriesResolver,
authorize: :read_container_image authorize: :read_container_image
field :container_repositories_count, GraphQL::INT_TYPE, null: false,
description: 'Number of container repositories in the group'
def label(title:) def label(title:)
BatchLoader::GraphQL.for(title).batch(key: group) do |titles, loader, args| BatchLoader::GraphQL.for(title).batch(key: group) do |titles, loader, args|
LabelsFinder LabelsFinder
...@@ -124,6 +127,10 @@ module Types ...@@ -124,6 +127,10 @@ module Types
Gitlab::Graphql::Loaders::BatchModelLoader.new(Group, object.parent_id).find Gitlab::Graphql::Loaders::BatchModelLoader.new(Group, object.parent_id).find
end end
def container_repositories_count
group.container_repositories.size
end
private private
def group def group
......
...@@ -286,6 +286,9 @@ module Types ...@@ -286,6 +286,9 @@ module Types
description: 'Container repositories of the project', description: 'Container repositories of the project',
resolver: Resolvers::ContainerRepositoriesResolver resolver: Resolvers::ContainerRepositoriesResolver
field :container_repositories_count, GraphQL::INT_TYPE, null: false,
description: 'Number of container repositories in the project'
field :label, field :label,
Types::LabelType, Types::LabelType,
null: true, null: true,
...@@ -341,6 +344,10 @@ module Types ...@@ -341,6 +344,10 @@ module Types
Gitlab::Graphql::Loaders::BatchProjectStatisticsLoader.new(object.id).find Gitlab::Graphql::Loaders::BatchProjectStatisticsLoader.new(object.id).find
end end
def container_repositories_count
project.container_repositories.size
end
private private
def project def project
......
---
title: Add containerRepositoriesCount to project and group queries
merge_request: 48685
author:
type: changed
...@@ -8819,7 +8819,7 @@ type Group { ...@@ -8819,7 +8819,7 @@ type Group {
): CodeCoverageActivityConnection ): CodeCoverageActivityConnection
""" """
Container repositories of the project Container repositories of the group
""" """
containerRepositories( containerRepositories(
""" """
...@@ -8848,6 +8848,11 @@ type Group { ...@@ -8848,6 +8848,11 @@ type Group {
name: String name: String
): ContainerRepositoryConnection ): ContainerRepositoryConnection
"""
Number of container repositories in the group
"""
containerRepositoriesCount: Int!
""" """
Includes at least one project where the repository size exceeds the limit Includes at least one project where the repository size exceeds the limit
""" """
...@@ -15622,6 +15627,11 @@ type Project { ...@@ -15622,6 +15627,11 @@ type Project {
name: String name: String
): ContainerRepositoryConnection ): ContainerRepositoryConnection
"""
Number of container repositories in the project
"""
containerRepositoriesCount: Int!
""" """
Timestamp of the project creation Timestamp of the project creation
""" """
......
...@@ -24514,7 +24514,7 @@ ...@@ -24514,7 +24514,7 @@
}, },
{ {
"name": "containerRepositories", "name": "containerRepositories",
"description": "Container repositories of the project", "description": "Container repositories of the group",
"args": [ "args": [
{ {
"name": "name", "name": "name",
...@@ -24575,6 +24575,24 @@ ...@@ -24575,6 +24575,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "containerRepositoriesCount",
"description": "Number of container repositories in the group",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "containsLockedProjects", "name": "containsLockedProjects",
"description": "Includes at least one project where the repository size exceeds the limit", "description": "Includes at least one project where the repository size exceeds the limit",
...@@ -46301,6 +46319,24 @@ ...@@ -46301,6 +46319,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "containerRepositoriesCount",
"description": "Number of container repositories in the project",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "createdAt", "name": "createdAt",
"description": "Timestamp of the project creation", "description": "Timestamp of the project creation",
...@@ -1459,7 +1459,8 @@ Autogenerated return type of EpicTreeReorder. ...@@ -1459,7 +1459,8 @@ Autogenerated return type of EpicTreeReorder.
| `board` | Board | A single board of the group | | `board` | Board | A single board of the group |
| `boards` | BoardConnection | Boards of the group | | `boards` | BoardConnection | Boards of the group |
| `codeCoverageActivities` | CodeCoverageActivityConnection | Represents the code coverage activity for this group | | `codeCoverageActivities` | CodeCoverageActivityConnection | Represents the code coverage activity for this group |
| `containerRepositories` | ContainerRepositoryConnection | Container repositories of the project | | `containerRepositories` | ContainerRepositoryConnection | Container repositories of the group |
| `containerRepositoriesCount` | Int! | Number of container repositories in the group |
| `containsLockedProjects` | Boolean! | Includes at least one project where the repository size exceeds the limit | | `containsLockedProjects` | Boolean! | Includes at least one project where the repository size exceeds the limit |
| `customEmoji` | CustomEmojiConnection | Custom emoji within this namespace. Available only when feature flag `custom_emoji` is enabled | | `customEmoji` | CustomEmojiConnection | Custom emoji within this namespace. Available only when feature flag `custom_emoji` is enabled |
| `description` | String | Description of the namespace | | `description` | String | Description of the namespace |
...@@ -2393,6 +2394,7 @@ Autogenerated return type of PipelineRetry. ...@@ -2393,6 +2394,7 @@ Autogenerated return type of PipelineRetry.
| `containerExpirationPolicy` | ContainerExpirationPolicy | The container expiration policy of the project | | `containerExpirationPolicy` | ContainerExpirationPolicy | The container expiration policy of the project |
| `containerRegistryEnabled` | Boolean | Indicates if the project stores Docker container images in a container registry | | `containerRegistryEnabled` | Boolean | Indicates if the project stores Docker container images in a container registry |
| `containerRepositories` | ContainerRepositoryConnection | Container repositories of the project | | `containerRepositories` | ContainerRepositoryConnection | Container repositories of the project |
| `containerRepositoriesCount` | Int! | Number of container repositories in the project |
| `createdAt` | Time | Timestamp of the project creation | | `createdAt` | Time | Timestamp of the project creation |
| `dastScannerProfiles` | DastScannerProfileConnection | The DAST scanner profiles associated with the project | | `dastScannerProfiles` | DastScannerProfileConnection | The DAST scanner profiles associated with the project |
| `dastSiteProfile` | DastSiteProfile | DAST Site Profile associated with the project | | `dastSiteProfile` | DastSiteProfile | DAST Site Profile associated with the project |
......
...@@ -17,7 +17,7 @@ RSpec.describe GitlabSchema.types['Group'] do ...@@ -17,7 +17,7 @@ RSpec.describe GitlabSchema.types['Group'] do
subgroup_creation_level require_two_factor_authentication subgroup_creation_level require_two_factor_authentication
two_factor_grace_period auto_devops_enabled emails_disabled two_factor_grace_period auto_devops_enabled emails_disabled
mentions_disabled parent boards milestones group_members mentions_disabled parent boards milestones group_members
merge_requests merge_requests container_repositories container_repositories_count
] ]
expect(described_class).to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
......
...@@ -30,7 +30,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -30,7 +30,7 @@ RSpec.describe GitlabSchema.types['Project'] do
alert_management_alerts alert_management_alert alert_management_alert_status_counts alert_management_alerts alert_management_alert alert_management_alert_status_counts
container_expiration_policy service_desk_enabled service_desk_address container_expiration_policy service_desk_enabled service_desk_address
issue_status_counts terraform_states alert_management_integrations issue_status_counts terraform_states alert_management_integrations
container_repositories container_repositories_count
] ]
expect(described_class).to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
......
...@@ -14,7 +14,7 @@ RSpec.describe 'getting container repositories in a group' do ...@@ -14,7 +14,7 @@ RSpec.describe 'getting container repositories in a group' do
let_it_be(:container_repositories) { [container_repository, container_repositories_delete_scheduled, container_repositories_delete_failed].flatten } let_it_be(:container_repositories) { [container_repository, container_repositories_delete_scheduled, container_repositories_delete_failed].flatten }
let_it_be(:container_expiration_policy) { project.container_expiration_policy } let_it_be(:container_expiration_policy) { project.container_expiration_policy }
let(:fields) do let(:container_repositories_fields) do
<<~GQL <<~GQL
edges { edges {
node { node {
...@@ -24,17 +24,25 @@ RSpec.describe 'getting container repositories in a group' do ...@@ -24,17 +24,25 @@ RSpec.describe 'getting container repositories in a group' do
GQL GQL
end end
let(:fields) do
<<~GQL
#{query_graphql_field('container_repositories', {}, container_repositories_fields)}
containerRepositoriesCount
GQL
end
let(:query) do let(:query) do
graphql_query_for( graphql_query_for(
'group', 'group',
{ 'fullPath' => group.full_path }, { 'fullPath' => group.full_path },
query_graphql_field('container_repositories', {}, fields) fields
) )
end end
let(:user) { owner } let(:user) { owner }
let(:variables) { {} } let(:variables) { {} }
let(:container_repositories_response) { graphql_data.dig('group', 'containerRepositories', 'edges') } let(:container_repositories_response) { graphql_data.dig('group', 'containerRepositories', 'edges') }
let(:container_repositories_count_response) { graphql_data.dig('group', 'containerRepositoriesCount') }
before do before do
group.add_owner(owner) group.add_owner(owner)
...@@ -101,7 +109,7 @@ RSpec.describe 'getting container repositories in a group' do ...@@ -101,7 +109,7 @@ RSpec.describe 'getting container repositories in a group' do
<<~GQL <<~GQL
query($path: ID!, $n: Int) { query($path: ID!, $n: Int) {
group(fullPath: $path) { group(fullPath: $path) {
containerRepositories(first: $n) { #{fields} } containerRepositories(first: $n) { #{container_repositories_fields} }
} }
} }
GQL GQL
...@@ -122,7 +130,7 @@ RSpec.describe 'getting container repositories in a group' do ...@@ -122,7 +130,7 @@ RSpec.describe 'getting container repositories in a group' do
<<~GQL <<~GQL
query($path: ID!, $name: String) { query($path: ID!, $name: String) {
group(fullPath: $path) { group(fullPath: $path) {
containerRepositories(name: $name) { #{fields} } containerRepositories(name: $name) { #{container_repositories_fields} }
} }
} }
GQL GQL
...@@ -143,4 +151,10 @@ RSpec.describe 'getting container repositories in a group' do ...@@ -143,4 +151,10 @@ RSpec.describe 'getting container repositories in a group' do
expect(container_repositories_response.first.dig('node', 'id')).to eq(container_repository.to_global_id.to_s) expect(container_repositories_response.first.dig('node', 'id')).to eq(container_repository.to_global_id.to_s)
end end
end end
it 'returns the total count of container repositories' do
subject
expect(container_repositories_count_response).to eq(container_repositories.size)
end
end end
...@@ -12,7 +12,7 @@ RSpec.describe 'getting container repositories in a project' do ...@@ -12,7 +12,7 @@ RSpec.describe 'getting container repositories in a project' do
let_it_be(:container_repositories) { [container_repository, container_repositories_delete_scheduled, container_repositories_delete_failed].flatten } let_it_be(:container_repositories) { [container_repository, container_repositories_delete_scheduled, container_repositories_delete_failed].flatten }
let_it_be(:container_expiration_policy) { project.container_expiration_policy } let_it_be(:container_expiration_policy) { project.container_expiration_policy }
let(:fields) do let(:container_repositories_fields) do
<<~GQL <<~GQL
edges { edges {
node { node {
...@@ -22,17 +22,25 @@ RSpec.describe 'getting container repositories in a project' do ...@@ -22,17 +22,25 @@ RSpec.describe 'getting container repositories in a project' do
GQL GQL
end end
let(:fields) do
<<~GQL
#{query_graphql_field('container_repositories', {}, container_repositories_fields)}
containerRepositoriesCount
GQL
end
let(:query) do let(:query) do
graphql_query_for( graphql_query_for(
'project', 'project',
{ 'fullPath' => project.full_path }, { 'fullPath' => project.full_path },
query_graphql_field('container_repositories', {}, fields) fields
) )
end end
let(:user) { project.owner } let(:user) { project.owner }
let(:variables) { {} } let(:variables) { {} }
let(:container_repositories_response) { graphql_data.dig('project', 'containerRepositories', 'edges') } let(:container_repositories_response) { graphql_data.dig('project', 'containerRepositories', 'edges') }
let(:container_repositories_count_response) { graphql_data.dig('project', 'containerRepositoriesCount') }
before do before do
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
...@@ -100,7 +108,7 @@ RSpec.describe 'getting container repositories in a project' do ...@@ -100,7 +108,7 @@ RSpec.describe 'getting container repositories in a project' do
<<~GQL <<~GQL
query($path: ID!, $n: Int) { query($path: ID!, $n: Int) {
project(fullPath: $path) { project(fullPath: $path) {
containerRepositories(first: $n) { #{fields} } containerRepositories(first: $n) { #{container_repositories_fields} }
} }
} }
GQL GQL
...@@ -121,7 +129,7 @@ RSpec.describe 'getting container repositories in a project' do ...@@ -121,7 +129,7 @@ RSpec.describe 'getting container repositories in a project' do
<<~GQL <<~GQL
query($path: ID!, $name: String) { query($path: ID!, $name: String) {
project(fullPath: $path) { project(fullPath: $path) {
containerRepositories(name: $name) { #{fields} } containerRepositories(name: $name) { #{container_repositories_fields} }
} }
} }
GQL GQL
...@@ -142,4 +150,10 @@ RSpec.describe 'getting container repositories in a project' do ...@@ -142,4 +150,10 @@ RSpec.describe 'getting container repositories in a project' do
expect(container_repositories_response.first.dig('node', 'id')).to eq(container_repository.to_global_id.to_s) expect(container_repositories_response.first.dig('node', 'id')).to eq(container_repository.to_global_id.to_s)
end end
end end
it 'returns the total count of container repositories' do
subject
expect(container_repositories_count_response).to eq(container_repositories.size)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment