Commit 89435a2b authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'ajk-rubcop-violations-MAR' into 'master'

Fix TODO-ed rubocop violations

See merge request gitlab-org/gitlab!56702
parents 9bbece77 f19aa7a9
......@@ -29,11 +29,9 @@ module Mutations
end
def ready?(**args)
if Gitlab::Database.read_only?
raise_resource_not_available_error! ERROR_MESSAGE
else
true
end
raise_resource_not_available_error! ERROR_MESSAGE if Gitlab::Database.read_only?
true
end
def load_application_object(argument, lookup_as_type, id, context)
......
......@@ -7,6 +7,10 @@ module Resolvers
include ResolvesProject
type Types::Ci::Config::ConfigType, null: true
description <<~MD
Linted and processed contents of a CI config.
Should not be requested more than once per request.
MD
authorize :read_pipeline
......@@ -55,7 +59,7 @@ module Resolvers
name: job[:name],
stage: job[:stage],
group_name: CommitStatus.new(name: job[:name]).group_name,
needs: job.dig(:needs) || [],
needs: job[:needs] || [],
allow_failure: job[:allow_failure],
before_script: job[:before_script],
script: job[:script],
......
......@@ -3,24 +3,30 @@
module Resolvers
module Ci
class RunnerSetupResolver < BaseResolver
ACCESS_DENIED = 'User is not authorized to register a runner for the specified resource!'
type Types::Ci::RunnerSetupType, null: true
description 'Runner setup instructions.'
argument :platform, GraphQL::STRING_TYPE,
required: true,
description: 'Platform to generate the instructions for.'
argument :platform,
type: GraphQL::STRING_TYPE,
required: true,
description: 'Platform to generate the instructions for.'
argument :architecture, GraphQL::STRING_TYPE,
required: true,
description: 'Architecture to generate the instructions for.'
argument :architecture,
type: GraphQL::STRING_TYPE,
required: true,
description: 'Architecture to generate the instructions for.'
argument :project_id, ::Types::GlobalIDType[::Project],
required: false,
description: 'Project to register the runner for.'
argument :project_id,
type: ::Types::GlobalIDType[::Project],
required: false,
description: 'Project to register the runner for.'
argument :group_id, ::Types::GlobalIDType[::Group],
required: false,
description: 'Group to register the runner for.'
argument :group_id,
type: ::Types::GlobalIDType[::Group],
required: false,
description: 'Group to register the runner for.'
def resolve(platform:, architecture:, **args)
instructions = Gitlab::Ci::RunnerInstructions.new(
......@@ -35,11 +41,15 @@ module Resolvers
register_instructions: instructions.register_command
}
ensure
raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'User is not authorized to register a runner for the specified resource!' if instructions.errors.include?('Gitlab::Access::AccessDeniedError')
raise Gitlab::Graphql::Errors::ResourceNotAvailable, ACCESS_DENIED if access_denied?(instructions)
end
private
def access_denied?(instructions)
instructions.errors.include?('Gitlab::Access::AccessDeniedError')
end
def other_install_instructions(platform)
Gitlab::Ci::RunnerInstructions::OTHER_ENVIRONMENTS[platform.to_sym][:installation_instructions_url]
end
......
......@@ -5,8 +5,10 @@ module Resolvers
type ::GraphQL::STRING_TYPE, null: false
description 'Testing endpoint to validate the API with'
argument :text, GraphQL::STRING_TYPE, required: true,
description: 'Text to echo back.'
argument :text,
type: GraphQL::STRING_TYPE,
required: true,
description: 'Text to echo back.'
def resolve(text:)
username = current_user&.username
......
# frozen_string_literal: true
# rubocop:disable Graphql/ResolverType (inherited from MilestonesResolver)
module Resolvers
class GroupMilestonesResolver < MilestonesResolver
......
......@@ -5,8 +5,8 @@ module Resolvers
type Types::ProjectType.connection_type, null: true
argument :search, GraphQL::STRING_TYPE,
required: false,
description: 'Search query.'
required: false,
description: 'Search query.'
alias_method :user, :object
......
......@@ -10,7 +10,10 @@ module Types
argument :not, NegatedBoardIssueInputType,
required: false,
description: 'List of negated params. Warning: this argument is experimental and a subject to change in future.'
description: <<~MD
List of negated arguments.
Warning: this argument is experimental and a subject to change in future.
MD
argument :search, GraphQL::STRING_TYPE,
required: false,
......
......@@ -8,39 +8,65 @@ module Types
expose_permissions Types::PermissionTypes::Group
field :web_url, GraphQL::STRING_TYPE, null: false,
field :web_url,
type: GraphQL::STRING_TYPE,
null: false,
description: 'Web URL of the group.'
field :avatar_url, GraphQL::STRING_TYPE, null: true,
field :avatar_url,
type: GraphQL::STRING_TYPE,
null: true,
description: 'Avatar URL of the group.'
field :custom_emoji, Types::CustomEmojiType.connection_type, null: true,
field :custom_emoji,
type: Types::CustomEmojiType.connection_type,
null: true,
description: 'Custom emoji within this namespace.',
feature_flag: :custom_emoji
field :share_with_group_lock, GraphQL::BOOLEAN_TYPE, null: true,
field :share_with_group_lock,
type: GraphQL::BOOLEAN_TYPE,
null: true,
description: 'Indicates if sharing a project with another group within this group is prevented.'
field :project_creation_level, GraphQL::STRING_TYPE, null: true, method: :project_creation_level_str,
field :project_creation_level,
type: GraphQL::STRING_TYPE,
null: true,
method: :project_creation_level_str,
description: 'The permission level required to create projects in the group.'
field :subgroup_creation_level, GraphQL::STRING_TYPE, null: true, method: :subgroup_creation_level_str,
field :subgroup_creation_level,
type: GraphQL::STRING_TYPE,
null: true,
method: :subgroup_creation_level_str,
description: 'The permission level required to create subgroups within the group.'
field :require_two_factor_authentication, GraphQL::BOOLEAN_TYPE, null: true,
field :require_two_factor_authentication,
type: GraphQL::BOOLEAN_TYPE,
null: true,
description: 'Indicates if all users in this group are required to set up two-factor authentication.'
field :two_factor_grace_period, GraphQL::INT_TYPE, null: true,
field :two_factor_grace_period,
type: GraphQL::INT_TYPE,
null: true,
description: 'Time before two-factor authentication is enforced.'
field :auto_devops_enabled, GraphQL::BOOLEAN_TYPE, null: true,
field :auto_devops_enabled,
type: GraphQL::BOOLEAN_TYPE,
null: true,
description: 'Indicates whether Auto DevOps is enabled for all projects within this group.'
field :emails_disabled, GraphQL::BOOLEAN_TYPE, null: true,
field :emails_disabled,
type: GraphQL::BOOLEAN_TYPE,
null: true,
description: 'Indicates if a group has email notifications disabled.'
field :mentions_disabled, GraphQL::BOOLEAN_TYPE, null: true,
field :mentions_disabled,
type: GraphQL::BOOLEAN_TYPE,
null: true,
description: 'Indicates if a group is disabled from getting mentioned.'
field :parent, GroupType, null: true,
field :parent,
type: GroupType,
null: true,
description: 'Parent group.'
field :issues,
......@@ -55,7 +81,7 @@ module Types
description: 'Merge requests for projects in this group.',
resolver: Resolvers::GroupMergeRequestsResolver
field :milestones, Types::MilestoneType.connection_type, null: true,
field :milestones,
description: 'Milestones of the group.',
resolver: Resolvers::GroupMilestonesResolver
......@@ -76,9 +102,10 @@ module Types
Types::LabelType,
null: true,
description: 'A label available on this group.' do
argument :title, GraphQL::STRING_TYPE,
required: true,
description: 'Title of the label.'
argument :title,
type: GraphQL::STRING_TYPE,
required: true,
description: 'Title of the label.'
end
field :group_members,
......@@ -92,7 +119,9 @@ module Types
resolver: Resolvers::ContainerRepositoriesResolver,
authorize: :read_container_image
field :container_repositories_count, GraphQL::INT_TYPE, null: false,
field :container_repositories_count,
type: GraphQL::INT_TYPE,
null: false,
description: 'Number of container repositories in the group.'
field :packages,
......
......@@ -5,12 +5,12 @@ module Types
graphql_name 'JiraUsersMappingInputType'
argument :jira_account_id,
GraphQL::STRING_TYPE,
required: true,
description: 'Jira account ID of the user.'
GraphQL::STRING_TYPE,
required: true,
description: 'Jira account ID of the user.'
argument :gitlab_id,
GraphQL::INT_TYPE,
required: false,
description: 'Id of the GitLab user.'
GraphQL::INT_TYPE,
required: false,
description: 'ID of the GitLab user.'
end
end
......@@ -55,7 +55,10 @@ module Types
field :container_repository, Types::ContainerRepositoryDetailsType,
null: true,
description: 'Find a container repository.' do
argument :id, ::Types::GlobalIDType[::ContainerRepository], required: true, description: 'The global ID of the container repository.'
argument :id,
type: ::Types::GlobalIDType[::ContainerRepository],
required: true,
description: 'The global ID of the container repository.'
end
field :package,
......@@ -72,9 +75,7 @@ module Types
description: 'Find users.',
resolver: Resolvers::UsersResolver
field :echo, GraphQL::STRING_TYPE, null: false,
description: 'Text to echo back.',
resolver: Resolvers::EchoResolver
field :echo, resolver: Resolvers::EchoResolver
field :issue, Types::IssueType,
null: true,
......@@ -102,18 +103,10 @@ module Types
null: true,
description: 'CI related settings that apply to the entire instance.'
field :runner_platforms, Types::Ci::RunnerPlatformType.connection_type,
null: true, description: 'Supported runner platforms.',
resolver: Resolvers::Ci::RunnerPlatformsResolver
field :runner_platforms, resolver: Resolvers::Ci::RunnerPlatformsResolver
field :runner_setup, resolver: Resolvers::Ci::RunnerSetupResolver
field :runner_setup, Types::Ci::RunnerSetupType, null: true,
description: 'Get runner setup instructions.',
resolver: Resolvers::Ci::RunnerSetupResolver
field :ci_config, Types::Ci::Config::ConfigType, null: true,
description: 'Get linted and processed contents of a CI config. Should not be requested more than once per request.',
resolver: Resolvers::Ci::ConfigResolver,
complexity: 126 # AUTHENTICATED_COMPLEXITY / 2 + 1
field :ci_config, resolver: Resolvers::Ci::ConfigResolver, complexity: 126 # AUTHENTICATED_COMPLEXITY / 2 + 1
def design_management
DesignManagementObject.new(nil)
......
......@@ -11,44 +11,72 @@ module Types
expose_permissions Types::PermissionTypes::User
field :id, GraphQL::ID_TYPE, null: false,
field :id,
type: GraphQL::ID_TYPE,
null: false,
description: 'ID of the user.'
field :bot, GraphQL::BOOLEAN_TYPE, null: false,
field :bot,
type: GraphQL::BOOLEAN_TYPE,
null: false,
description: 'Indicates if the user is a bot.',
method: :bot?
field :username, GraphQL::STRING_TYPE, null: false,
field :username,
type: GraphQL::STRING_TYPE,
null: false,
description: 'Username of the user. Unique within this instance of GitLab.'
field :name, GraphQL::STRING_TYPE, null: false,
field :name,
type: GraphQL::STRING_TYPE,
null: false,
description: 'Human-readable name of the user.'
field :state, Types::UserStateEnum, null: false,
field :state,
type: Types::UserStateEnum,
null: false,
description: 'State of the user.'
field :email, GraphQL::STRING_TYPE, null: true,
field :email,
type: GraphQL::STRING_TYPE,
null: true,
description: 'User email.', method: :public_email,
deprecated: { reason: :renamed, replacement: 'User.publicEmail', milestone: '13.7' }
field :public_email, GraphQL::STRING_TYPE, null: true,
field :public_email,
type: GraphQL::STRING_TYPE,
null: true,
description: "User's public email."
field :avatar_url, GraphQL::STRING_TYPE, null: true,
field :avatar_url,
type: GraphQL::STRING_TYPE,
null: true,
description: "URL of the user's avatar."
field :web_url, GraphQL::STRING_TYPE, null: false,
field :web_url,
type: GraphQL::STRING_TYPE,
null: false,
description: 'Web URL of the user.'
field :web_path, GraphQL::STRING_TYPE, null: false,
field :web_path,
type: GraphQL::STRING_TYPE,
null: false,
description: 'Web path of the user.'
field :todos, Types::TodoType.connection_type, null: false,
field :todos,
resolver: Resolvers::TodoResolver,
description: 'To-do items of the user.'
field :group_memberships, Types::GroupMemberType.connection_type, null: true,
field :group_memberships,
type: Types::GroupMemberType.connection_type,
null: true,
description: 'Group memberships of the user.'
field :group_count, GraphQL::INT_TYPE, null: true,
field :group_count,
resolver: Resolvers::Users::GroupCountResolver,
description: 'Group count for the user.',
feature_flag: :user_group_counts
field :status, Types::UserStatusType, null: true,
description: 'User status.'
field :location, ::GraphQL::STRING_TYPE, null: true,
field :status,
type: Types::UserStatusType,
null: true,
description: 'User status.'
field :location,
type: ::GraphQL::STRING_TYPE,
null: true,
description: 'The location of the user.'
field :project_memberships, Types::ProjectMemberType.connection_type, null: true,
field :project_memberships,
type: Types::ProjectMemberType.connection_type,
null: true,
description: 'Project memberships of the user.'
field :starred_projects, Types::ProjectType.connection_type, null: true,
field :starred_projects,
description: 'Projects starred by the user.',
resolver: Resolvers::UserStarredProjectsResolver
......@@ -64,8 +92,6 @@ module Types
description: 'Merge Requests assigned to the user for review.'
field :snippets,
Types::SnippetType.connection_type,
null: true,
description: 'Snippets authored by the user.',
resolver: Resolvers::Users::SnippetsResolver
field :callouts,
......
......@@ -38,7 +38,8 @@ Returns [`CiApplicationSettings`](#ciapplicationsettings).
### `ciConfig`
Get linted and processed contents of a CI config. Should not be requested more than once per request.
Linted and processed contents of a CI config.
Should not be requested more than once per request.
Returns [`CiConfig`](#ciconfig).
......@@ -93,7 +94,7 @@ Returns [`DevopsAdoptionSegmentConnection`](#devopsadoptionsegmentconnection).
### `echo`
Text to echo back.
Testing endpoint to validate the API with.
Returns [`String!`](#string).
......@@ -271,7 +272,7 @@ Returns [`RunnerPlatformConnection`](#runnerplatformconnection).
### `runnerSetup`
Get runner setup instructions.
Runner setup instructions.
Returns [`RunnerSetup`](#runnersetup).
......@@ -398,7 +399,9 @@ Returns [`VulnerabilitiesCountByDayConnection`](#vulnerabilitiescountbydayconnec
### `vulnerabilitiesCountByDayAndSeverity`
Number of vulnerabilities per severity level, per day, for the projects on the current user's instance security dashboard.
Number of vulnerabilities per severity level, per day, for the projects on the
current user's instance security dashboard.
.
WARNING:
**Deprecated** in 13.3.
......@@ -6509,7 +6512,7 @@ Representation of a GitLab user.
| `starredProjects` | [`ProjectConnection`](#projectconnection) | Projects starred by the user. |
| `state` | [`UserState!`](#userstate) | State of the user. |
| `status` | [`UserStatus`](#userstatus) | User status. |
| `todos` | [`TodoConnection!`](#todoconnection) | To-do items of the user. |
| `todos` | [`TodoConnection`](#todoconnection) | To-do items of the user. |
| `userPermissions` | [`UserPermissions!`](#userpermissions) | Permissions for the current user on the resource. |
| `username` | [`String!`](#string) | Username of the user. Unique within this instance of GitLab. |
| `webPath` | [`String!`](#string) | Web path of the user. |
......
......@@ -32,15 +32,20 @@ module EE
field :vulnerabilities_count_by_day,
::Types::VulnerabilitiesCountByDayType.connection_type,
null: true,
description: "Number of vulnerabilities per day for the projects on the current user's instance security dashboard.",
resolver: ::Resolvers::VulnerabilitiesCountPerDayResolver
resolver: ::Resolvers::VulnerabilitiesCountPerDayResolver,
description: <<~DESC
Number of vulnerabilities per day for the projects on the current user's instance security dashboard.
DESC
field :vulnerabilities_count_by_day_and_severity,
::Types::VulnerabilitiesCountByDayAndSeverityType.connection_type,
null: true,
description: "Number of vulnerabilities per severity level, per day, for the projects on the current user's instance security dashboard.",
resolver: ::Resolvers::VulnerabilitiesHistoryResolver,
deprecated: { reason: :discouraged, replacement: 'Query.vulnerabilitiesCountByDay', milestone: '13.3' }
deprecated: { reason: :discouraged, replacement: 'Query.vulnerabilitiesCountByDay', milestone: '13.3' },
description: <<~DESC
Number of vulnerabilities per severity level, per day, for the projects on the
current user's instance security dashboard.
DESC
field :geo_node, ::Types::Geo::GeoNodeType,
null: true,
......
......@@ -54,6 +54,10 @@ module RuboCop
(send nil? :value ...)
PATTERN
def_node_matcher :resolver_kwarg, <<~PATTERN
(... (hash <(pair (sym :resolver) $_) ...>))
PATTERN
def_node_matcher :description_kwarg, <<~PATTERN
(... (hash <(pair (sym :description) $_) ...>))
PATTERN
......@@ -64,6 +68,7 @@ module RuboCop
def on_send(node)
return unless graphql_describable?(node)
return if resolver_kwarg(node) # Fields may inherit the description from their resolvers.
description = locate_description(node)
......
......@@ -6,7 +6,7 @@ require_relative '../../../../rubocop/cop/graphql/descriptions'
RSpec.describe RuboCop::Cop::Graphql::Descriptions do
subject(:cop) { described_class.new }
context 'fields' do
context 'with fields' do
it 'adds an offense when there is no description' do
expect_offense(<<~TYPE)
module Types
......@@ -46,9 +46,19 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
TYPE
end
it 'does not add an offense when there is a resolver' do
expect_no_offenses(<<~TYPE.strip)
module Types
class FakeType < BaseObject
field :a_thing, resolver: ThingResolver
end
end
TYPE
end
end
context 'arguments' do
context 'with arguments' do
it 'adds an offense when there is no description' do
expect_offense(<<~TYPE)
module Types
......@@ -90,7 +100,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
context 'enum values' do
context 'with enum values' do
it 'adds an offense when there is no description' do
expect_offense(<<~TYPE)
module Types
......
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