diff options
Diffstat (limited to 'lib/api/services.rb')
-rw-r--r-- | lib/api/services.rb | 373 |
1 files changed, 187 insertions, 186 deletions
diff --git a/lib/api/services.rb b/lib/api/services.rb index bda6be51553..60a37802ca5 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module API class Services < Grape::API CHAT_NOTIFICATION_SETTINGS = [ @@ -6,20 +7,20 @@ module API required: true, name: :webhook, type: String, - desc: 'The chat webhook' + desc: "The chat webhook", }, { required: false, name: :username, type: String, - desc: 'The chat username' + desc: "The chat username", }, { required: false, name: :channel, type: String, - desc: 'The default chat channel' - } + desc: "The default chat channel", + }, ].freeze CHAT_NOTIFICATION_FLAGS = [ @@ -27,14 +28,14 @@ module API required: false, name: :notify_only_broken_pipelines, type: Boolean, - desc: 'Send notifications for broken pipelines' + desc: "Send notifications for broken pipelines", }, { required: false, name: :notify_only_default_branch, type: Boolean, - desc: 'Send notifications only for the default branch' - } + desc: "Send notifications only for the default branch", + }, ].freeze CHAT_NOTIFICATION_CHANNELS = [ @@ -42,50 +43,50 @@ module API required: false, name: :push_channel, type: String, - desc: 'The name of the channel to receive push_events notifications' + desc: "The name of the channel to receive push_events notifications", }, { required: false, name: :issue_channel, type: String, - desc: 'The name of the channel to receive issues_events notifications' + desc: "The name of the channel to receive issues_events notifications", }, { required: false, name: :confidential_issue_channel, type: String, - desc: 'The name of the channel to receive confidential_issues_events notifications' + desc: "The name of the channel to receive confidential_issues_events notifications", }, { required: false, name: :merge_request_channel, type: String, - desc: 'The name of the channel to receive merge_requests_events notifications' + desc: "The name of the channel to receive merge_requests_events notifications", }, { required: false, name: :note_channel, type: String, - desc: 'The name of the channel to receive note_events notifications' + desc: "The name of the channel to receive note_events notifications", }, { required: false, name: :tag_push_channel, type: String, - desc: 'The name of the channel to receive tag_push_events notifications' + desc: "The name of the channel to receive tag_push_events notifications", }, { required: false, name: :pipeline_channel, type: String, - desc: 'The name of the channel to receive pipeline_events notifications' + desc: "The name of the channel to receive pipeline_events notifications", }, { required: false, name: :wiki_page_channel, type: String, - desc: 'The name of the channel to receive wiki_page_events notifications' - } + desc: "The name of the channel to receive wiki_page_events notifications", + }, ].freeze CHAT_NOTIFICATION_EVENTS = [ @@ -93,571 +94,571 @@ module API required: false, name: :push_events, type: Boolean, - desc: 'Enable notifications for push_events' + desc: "Enable notifications for push_events", }, { required: false, name: :issues_events, type: Boolean, - desc: 'Enable notifications for issues_events' + desc: "Enable notifications for issues_events", }, { required: false, name: :confidential_issues_events, type: Boolean, - desc: 'Enable notifications for confidential_issues_events' + desc: "Enable notifications for confidential_issues_events", }, { required: false, name: :merge_requests_events, type: Boolean, - desc: 'Enable notifications for merge_requests_events' + desc: "Enable notifications for merge_requests_events", }, { required: false, name: :note_events, type: Boolean, - desc: 'Enable notifications for note_events' + desc: "Enable notifications for note_events", }, { required: false, name: :tag_push_events, type: Boolean, - desc: 'Enable notifications for tag_push_events' + desc: "Enable notifications for tag_push_events", }, { required: false, name: :pipeline_events, type: Boolean, - desc: 'Enable notifications for pipeline_events' + desc: "Enable notifications for pipeline_events", }, { required: false, name: :wiki_page_events, type: Boolean, - desc: 'Enable notifications for wiki_page_events' - } + desc: "Enable notifications for wiki_page_events", + }, ].freeze services = { - 'asana' => [ + "asana" => [ { required: true, name: :api_key, type: String, - desc: 'User API token' + desc: "User API token", }, { required: false, name: :restrict_to_branch, type: String, - desc: 'Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches' - } + desc: "Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches", + }, ], - 'assembla' => [ + "assembla" => [ { required: true, name: :token, type: String, - desc: 'The authentication token' + desc: "The authentication token", }, { required: false, name: :subdomain, type: String, - desc: 'Subdomain setting' - } + desc: "Subdomain setting", + }, ], - 'bamboo' => [ + "bamboo" => [ { required: true, name: :bamboo_url, type: String, - desc: 'Bamboo root URL like https://bamboo.example.com' + desc: "Bamboo root URL like https://bamboo.example.com", }, { required: true, name: :build_key, type: String, - desc: 'Bamboo build plan key like' + desc: "Bamboo build plan key like", }, { required: true, name: :username, type: String, - desc: 'A user with API access, if applicable' + desc: "A user with API access, if applicable", }, { required: true, name: :password, type: String, - desc: 'Passord of the user' - } + desc: "Passord of the user", + }, ], - 'bugzilla' => [ + "bugzilla" => [ { required: true, name: :new_issue_url, type: String, - desc: 'New issue URL' + desc: "New issue URL", }, { required: true, name: :issues_url, type: String, - desc: 'Issues URL' + desc: "Issues URL", }, { required: true, name: :project_url, type: String, - desc: 'Project URL' + desc: "Project URL", }, { required: false, name: :description, type: String, - desc: 'Description' + desc: "Description", }, { required: false, name: :title, type: String, - desc: 'Title' - } + desc: "Title", + }, ], - 'buildkite' => [ + "buildkite" => [ { required: true, name: :token, type: String, - desc: 'Buildkite project GitLab token' + desc: "Buildkite project GitLab token", }, { required: true, name: :project_url, type: String, - desc: 'The buildkite project URL' + desc: "The buildkite project URL", }, { required: false, name: :enable_ssl_verification, type: Boolean, - desc: 'Enable SSL verification for communication' - } + desc: "Enable SSL verification for communication", + }, ], - 'campfire' => [ + "campfire" => [ { required: true, name: :token, type: String, - desc: 'Campfire token' + desc: "Campfire token", }, { required: false, name: :subdomain, type: String, - desc: 'Campfire subdomain' + desc: "Campfire subdomain", }, { required: false, name: :room, type: String, - desc: 'Campfire room' - } + desc: "Campfire room", + }, ], - 'custom-issue-tracker' => [ + "custom-issue-tracker" => [ { required: true, name: :new_issue_url, type: String, - desc: 'New issue URL' + desc: "New issue URL", }, { required: true, name: :issues_url, type: String, - desc: 'Issues URL' + desc: "Issues URL", }, { required: true, name: :project_url, type: String, - desc: 'Project URL' + desc: "Project URL", }, { required: false, name: :description, type: String, - desc: 'Description' + desc: "Description", }, { required: false, name: :title, type: String, - desc: 'Title' - } + desc: "Title", + }, ], - 'discord' => [ + "discord" => [ { required: true, name: :webhook, type: String, - desc: 'Discord webhook. e.g. https://discordapp.com/api/webhooks/…' - } + desc: "Discord webhook. e.g. https://discordapp.com/api/webhooks/…", + }, ], - 'drone-ci' => [ + "drone-ci" => [ { required: true, name: :token, type: String, - desc: 'Drone CI token' + desc: "Drone CI token", }, { required: true, name: :drone_url, type: String, - desc: 'Drone CI URL' + desc: "Drone CI URL", }, { required: false, name: :enable_ssl_verification, type: Boolean, - desc: 'Enable SSL verification for communication' - } + desc: "Enable SSL verification for communication", + }, ], - 'emails-on-push' => [ + "emails-on-push" => [ { required: true, name: :recipients, type: String, - desc: 'Comma-separated list of recipient email addresses' + desc: "Comma-separated list of recipient email addresses", }, { required: false, name: :disable_diffs, type: Boolean, - desc: 'Disable code diffs' + desc: "Disable code diffs", }, { required: false, name: :send_from_committer_email, type: Boolean, - desc: 'Send from committer' - } + desc: "Send from committer", + }, ], - 'external-wiki' => [ + "external-wiki" => [ { required: true, name: :external_wiki_url, type: String, - desc: 'The URL of the external Wiki' - } + desc: "The URL of the external Wiki", + }, ], - 'flowdock' => [ + "flowdock" => [ { required: true, name: :token, type: String, - desc: 'Flowdock token' - } + desc: "Flowdock token", + }, ], - 'hangouts-chat' => [ + "hangouts-chat" => [ { required: true, name: :webhook, type: String, - desc: 'The Hangouts Chat webhook. e.g. https://chat.googleapis.com/v1/spaces…' + desc: "The Hangouts Chat webhook. e.g. https://chat.googleapis.com/v1/spaces…", }, - CHAT_NOTIFICATION_EVENTS + CHAT_NOTIFICATION_EVENTS, ].flatten, - 'irker' => [ + "irker" => [ { required: true, name: :recipients, type: String, - desc: 'Recipients/channels separated by whitespaces' + desc: "Recipients/channels separated by whitespaces", }, { required: false, name: :default_irc_uri, type: String, - desc: 'Default: irc://irc.network.net:6697' + desc: "Default: irc://irc.network.net:6697", }, { required: false, name: :server_host, type: String, - desc: 'Server host. Default localhost' + desc: "Server host. Default localhost", }, { required: false, name: :server_port, type: Integer, - desc: 'Server port. Default 6659' + desc: "Server port. Default 6659", }, { required: false, name: :colorize_messages, type: Boolean, - desc: 'Colorize messages' - } + desc: "Colorize messages", + }, ], - 'jira' => [ + "jira" => [ { required: true, name: :url, type: String, - desc: 'The base URL to the JIRA instance web interface which is being linked to this GitLab project. E.g., https://jira.example.com' + desc: "The base URL to the JIRA instance web interface which is being linked to this GitLab project. E.g., https://jira.example.com", }, { required: false, name: :api_url, type: String, - desc: 'The base URL to the JIRA instance API. Web URL value will be used if not set. E.g., https://jira-api.example.com' + desc: "The base URL to the JIRA instance API. Web URL value will be used if not set. E.g., https://jira-api.example.com", }, { required: true, name: :username, type: String, - desc: 'The username of the user created to be used with GitLab/JIRA' + desc: "The username of the user created to be used with GitLab/JIRA", }, { required: true, name: :password, type: String, - desc: 'The password of the user created to be used with GitLab/JIRA' + desc: "The password of the user created to be used with GitLab/JIRA", }, { required: false, name: :jira_issue_transition_id, type: String, - desc: 'The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`' - } + desc: "The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`", + }, ], - 'kubernetes' => [ + "kubernetes" => [ { required: true, name: :namespace, type: String, - desc: 'The Kubernetes namespace to use' + desc: "The Kubernetes namespace to use", }, { required: true, name: :api_url, type: String, - desc: 'The URL to the Kubernetes cluster API, e.g., https://kubernetes.example.com' + desc: "The URL to the Kubernetes cluster API, e.g., https://kubernetes.example.com", }, { required: true, name: :token, type: String, - desc: 'The service token to authenticate against the Kubernetes cluster with' + desc: "The service token to authenticate against the Kubernetes cluster with", }, { required: false, name: :ca_pem, type: String, - desc: 'A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format)' - } + desc: "A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format)", + }, ], - 'mattermost-slash-commands' => [ + "mattermost-slash-commands" => [ { required: true, name: :token, type: String, - desc: 'The Mattermost token' - } + desc: "The Mattermost token", + }, ], - 'slack-slash-commands' => [ + "slack-slash-commands" => [ { required: true, name: :token, type: String, - desc: 'The Slack token' - } + desc: "The Slack token", + }, ], - 'packagist' => [ + "packagist" => [ { required: true, name: :username, type: String, - desc: 'The username' + desc: "The username", }, { required: true, name: :token, type: String, - desc: 'The Packagist API token' + desc: "The Packagist API token", }, { required: false, name: :server, type: String, - desc: 'The server' - } + desc: "The server", + }, ], - 'pipelines-email' => [ + "pipelines-email" => [ { required: true, name: :recipients, type: String, - desc: 'Comma-separated list of recipient email addresses' + desc: "Comma-separated list of recipient email addresses", }, { required: false, name: :notify_only_broken_pipelines, type: Boolean, - desc: 'Notify only broken pipelines' - } + desc: "Notify only broken pipelines", + }, ], - 'pivotaltracker' => [ + "pivotaltracker" => [ { required: true, name: :token, type: String, - desc: 'The Pivotaltracker token' + desc: "The Pivotaltracker token", }, { required: false, name: :restrict_to_branch, type: String, - desc: 'Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches.' - } + desc: "Comma-separated list of branches which will be automatically inspected. Leave blank to include all branches.", + }, ], - 'prometheus' => [ + "prometheus" => [ { required: true, name: :api_url, type: String, - desc: 'Prometheus API Base URL, like http://prometheus.example.com/' - } + desc: "Prometheus API Base URL, like http://prometheus.example.com/", + }, ], - 'pushover' => [ + "pushover" => [ { required: true, name: :api_key, type: String, - desc: 'The application key' + desc: "The application key", }, { required: true, name: :user_key, type: String, - desc: 'The user key' + desc: "The user key", }, { required: true, name: :priority, type: String, - desc: 'The priority' + desc: "The priority", }, { required: true, name: :device, type: String, - desc: 'Leave blank for all active devices' + desc: "Leave blank for all active devices", }, { required: true, name: :sound, type: String, - desc: 'The sound of the notification' - } + desc: "The sound of the notification", + }, ], - 'redmine' => [ + "redmine" => [ { required: true, name: :new_issue_url, type: String, - desc: 'The new issue URL' + desc: "The new issue URL", }, { required: true, name: :project_url, type: String, - desc: 'The project URL' + desc: "The project URL", }, { required: true, name: :issues_url, type: String, - desc: 'The issues URL' + desc: "The issues URL", }, { required: false, name: :description, type: String, - desc: 'The description of the tracker' - } + desc: "The description of the tracker", + }, ], - 'youtrack' => [ + "youtrack" => [ { required: true, name: :project_url, type: String, - desc: 'The project URL' + desc: "The project URL", }, { required: true, name: :issues_url, type: String, - desc: 'The issues URL' + desc: "The issues URL", }, { required: false, name: :description, type: String, - desc: 'The description of the tracker' - } + desc: "The description of the tracker", + }, ], - 'slack' => [ + "slack" => [ CHAT_NOTIFICATION_SETTINGS, CHAT_NOTIFICATION_FLAGS, CHAT_NOTIFICATION_CHANNELS, - CHAT_NOTIFICATION_EVENTS + CHAT_NOTIFICATION_EVENTS, ].flatten, - 'microsoft-teams' => [ + "microsoft-teams" => [ { required: true, name: :webhook, type: String, - desc: 'The Microsoft Teams webhook. e.g. https://outlook.office.com/webhook/…' - } + desc: "The Microsoft Teams webhook. e.g. https://outlook.office.com/webhook/…", + }, ], - 'mattermost' => [ + "mattermost" => [ CHAT_NOTIFICATION_SETTINGS, CHAT_NOTIFICATION_FLAGS, CHAT_NOTIFICATION_CHANNELS, - CHAT_NOTIFICATION_EVENTS + CHAT_NOTIFICATION_EVENTS, ].flatten, - 'teamcity' => [ + "teamcity" => [ { required: true, name: :teamcity_url, type: String, - desc: 'TeamCity root URL like https://teamcity.example.com' + desc: "TeamCity root URL like https://teamcity.example.com", }, { required: true, name: :build_type, type: String, - desc: 'Build configuration ID' + desc: "Build configuration ID", }, { required: true, name: :username, type: String, - desc: 'A user with permissions to trigger a manual build' + desc: "A user with permissions to trigger a manual build", }, { required: true, name: :password, type: String, - desc: 'The password of the user' - } - ] + desc: "The password of the user", + }, + ], } service_classes = [ @@ -689,25 +690,25 @@ module API SlackService, MattermostService, MicrosoftTeamsService, - TeamcityService + TeamcityService, ] if Rails.env.development? - services['mock-ci'] = [ + services["mock-ci"] = [ { required: true, name: :mock_service_url, type: String, - desc: 'URL to the mock service' - } + desc: "URL to the mock service", + }, ] - services['mock-deployment'] = [] - services['mock-monitoring'] = [] + services["mock-deployment"] = [] + services["mock-monitoring"] = [] service_classes += [ MockCiService, MockDeploymentService, - MockMonitoringService + MockMonitoringService, ] end @@ -721,30 +722,30 @@ module API required: false, name: event_name.to_sym, type: String, - desc: service.event_description(event_name) + desc: service.event_description(event_name), } end end TRIGGER_SERVICES = { - 'mattermost-slash-commands' => [ + "mattermost-slash-commands" => [ { name: :token, type: String, - desc: 'The Mattermost token' - } + desc: "The Mattermost token", + }, ], - 'slack-slash-commands' => [ + "slack-slash-commands" => [ { name: :token, type: String, - desc: 'The Slack token' - } - ] + desc: "The Slack token", + }, + ], }.freeze params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do before { authenticate! } @@ -776,34 +777,34 @@ module API if service.update(service_params) present service, with: Entities::ProjectService else - render_api_error!('400 Bad Request', 400) + render_api_error!("400 Bad Request", 400) end end end desc "Delete a service for project" params do - requires :service_slug, type: String, values: SERVICES.keys, desc: 'The name of the service' + requires :service_slug, type: String, values: SERVICES.keys, desc: "The name of the service" end delete ":id/services/:service_slug" do service = user_project.find_or_initialize_service(params[:service_slug].underscore) destroy_conditionally!(service) do - attrs = service_attributes(service).inject({}) do |hash, key| + attrs = service_attributes(service).inject({}) { |hash, key| hash.merge!(key => nil) - end + } unless service.update(attrs.merge(active: false)) - render_api_error!('400 Bad Request', 400) + render_api_error!("400 Bad Request", 400) end end end - desc 'Get the service settings for project' do + desc "Get the service settings for project" do success Entities::ProjectService end params do - requires :service_slug, type: String, values: SERVICES.keys, desc: 'The name of the service' + requires :service_slug, type: String, values: SERVICES.keys, desc: "The name of the service" end get ":id/services/:service_slug" do service = user_project.find_or_initialize_service(params[:service_slug].underscore) @@ -823,11 +824,11 @@ module API end params do - requires :id, type: String, desc: 'The ID of a project' + requires :id, type: String, desc: "The ID of a project" end resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do desc "Trigger a slash command for #{service_slug}" do - detail 'Added in GitLab 8.13' + detail "Added in GitLab 8.13" end params do settings.each do |setting| @@ -838,7 +839,7 @@ module API project = find_project(params[:id]) # This is not accurate, but done to prevent leakage of the project names - not_found!('Service') unless project + not_found!("Service") unless project service = slash_command_service(project, service_slug, params) result = service.try(:trigger, params) @@ -847,7 +848,7 @@ module API status result[:status] || 200 present result else - not_found!('Service') + not_found!("Service") end end end |