diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 09:09:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 09:09:54 +0300 |
commit | f6cdec670b9b757fc2225a2c6627ab79765e5b8a (patch) | |
tree | 7a1fde030f117b69332d01b22deefd1c81fff458 /app | |
parent | e2ee1eec50aa8df8543d7ecc585ec0ba5ee544ac (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/static_site_editor/components/saved_changes_message.vue | 80 | ||||
-rw-r--r-- | app/graphql/resolvers/projects/services_resolver.rb | 39 | ||||
-rw-r--r-- | app/graphql/types/project_type.rb | 6 | ||||
-rw-r--r-- | app/graphql/types/projects/service_type.rb | 29 | ||||
-rw-r--r-- | app/graphql/types/projects/service_type_enum.rb | 13 | ||||
-rw-r--r-- | app/graphql/types/projects/services/base_service_type.rb | 15 | ||||
-rw-r--r-- | app/graphql/types/projects/services/jira_service_type.rb | 18 | ||||
-rw-r--r-- | app/models/service.rb | 65 |
8 files changed, 228 insertions, 37 deletions
diff --git a/app/assets/javascripts/static_site_editor/components/saved_changes_message.vue b/app/assets/javascripts/static_site_editor/components/saved_changes_message.vue new file mode 100644 index 00000000000..adcacf8a1b0 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/components/saved_changes_message.vue @@ -0,0 +1,80 @@ +<script> +import { isString } from 'lodash'; + +import { GlLink, GlNewButton } from '@gitlab/ui'; + +const validateUrlAndLabel = value => isString(value.label) && isString(value.url); + +export default { + components: { + GlLink, + GlNewButton, + }, + props: { + branch: { + type: Object, + required: true, + validator: validateUrlAndLabel, + }, + commit: { + type: Object, + required: true, + validator: validateUrlAndLabel, + }, + mergeRequest: { + type: Object, + required: true, + validator: validateUrlAndLabel, + }, + returnUrl: { + type: String, + required: true, + }, + }, +}; +</script> + +<template> + <div> + <div> + <h3>{{ s__('StaticSiteEditor|Success!') }}</h3> + <p> + {{ + s__( + 'StaticSiteEditor|Your changes have been submitted and a merge request has been created. The changes won’t be visible on the site until the merge request has been accepted.', + ) + }} + </p> + <div> + <gl-new-button ref="returnToSiteButton" :href="returnUrl">{{ + s__('StaticSiteEditor|Return to site') + }}</gl-new-button> + <gl-new-button ref="mergeRequestButton" :href="mergeRequest.url" variant="info">{{ + s__('StaticSiteEditor|View merge request') + }}</gl-new-button> + </div> + </div> + + <hr /> + + <div> + <h4>{{ s__('StaticSiteEditor|Summary of changes') }}</h4> + <ul> + <li> + {{ s__('StaticSiteEditor|A new branch was created:') }} + <gl-link ref="branchLink" :href="branch.url">{{ branch.label }}</gl-link> + </li> + <li> + {{ s__('StaticSiteEditor|Your changes were committed to it:') }} + <gl-link ref="commitLink" :href="commit.url">{{ commit.label }}</gl-link> + </li> + <li> + {{ s__('StaticSiteEditor|A merge request was created:') }} + <gl-link ref="mergeRequestLink" :href="mergeRequest.url">{{ + mergeRequest.label + }}</gl-link> + </li> + </ul> + </div> + </div> +</template> diff --git a/app/graphql/resolvers/projects/services_resolver.rb b/app/graphql/resolvers/projects/services_resolver.rb new file mode 100644 index 00000000000..40c64c24513 --- /dev/null +++ b/app/graphql/resolvers/projects/services_resolver.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Resolvers + module Projects + class ServicesResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + argument :active, + GraphQL::BOOLEAN_TYPE, + required: false, + description: 'Indicates if the service is active' + argument :type, + Types::Projects::ServiceTypeEnum, + required: false, + description: 'Class name of the service' + + alias_method :project, :object + + def resolve(**args) + authorize!(project) + + services(args[:active], args[:type]) + end + + def authorized_resource?(project) + Ability.allowed?(context[:current_user], :admin_project, project) + end + + private + + def services(active, type) + servs = project.services + servs = servs.by_active_flag(active) unless active.nil? + servs = servs.by_type(type) unless type.blank? + servs + end + end + end +end diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index d82feffe441..3115a53e053 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -199,6 +199,12 @@ module Types null: true, description: 'Jira imports into the project', resolver: Resolvers::Projects::JiraImportsResolver + + field :services, + Types::Projects::ServiceType.connection_type, + null: true, + description: 'Project services', + resolver: Resolvers::Projects::ServicesResolver end end diff --git a/app/graphql/types/projects/service_type.rb b/app/graphql/types/projects/service_type.rb new file mode 100644 index 00000000000..55dd828d4b8 --- /dev/null +++ b/app/graphql/types/projects/service_type.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Types + module Projects + module ServiceType + include Types::BaseInterface + graphql_name 'Service' + + # TODO: Add all the fields that we want to expose for the project services intergrations + # https://gitlab.com/gitlab-org/gitlab/-/issues/213088 + field :type, GraphQL::STRING_TYPE, null: true, + description: 'Class name of the service' + field :active, GraphQL::BOOLEAN_TYPE, null: true, + description: 'Indicates if the service is active' + + definition_methods do + def resolve_type(object, context) + if object.is_a?(::JiraService) + Types::Projects::Services::JiraServiceType + else + Types::Projects::Services::BaseServiceType + end + end + end + + orphan_types Types::Projects::Services::BaseServiceType, Types::Projects::Services::JiraServiceType + end + end +end diff --git a/app/graphql/types/projects/service_type_enum.rb b/app/graphql/types/projects/service_type_enum.rb new file mode 100644 index 00000000000..340fdff6b86 --- /dev/null +++ b/app/graphql/types/projects/service_type_enum.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Types + module Projects + class ServiceTypeEnum < BaseEnum + graphql_name 'ServiceType' + + ::Service.services_types.each do |service_type| + value service_type.underscore.upcase, value: service_type + end + end + end +end diff --git a/app/graphql/types/projects/services/base_service_type.rb b/app/graphql/types/projects/services/base_service_type.rb new file mode 100644 index 00000000000..5341ae2a864 --- /dev/null +++ b/app/graphql/types/projects/services/base_service_type.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Types + module Projects + module Services + class BaseServiceType < BaseObject + graphql_name 'BaseService' + + implements(Types::Projects::ServiceType) + + authorize :admin_project + end + end + end +end diff --git a/app/graphql/types/projects/services/jira_service_type.rb b/app/graphql/types/projects/services/jira_service_type.rb new file mode 100644 index 00000000000..4fd9e61f5a4 --- /dev/null +++ b/app/graphql/types/projects/services/jira_service_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Types + module Projects + module Services + class JiraServiceType < BaseObject + graphql_name 'JiraService' + + implements(Types::Projects::ServiceType) + + authorize :admin_project + # This is a placeholder for now for the actuall implementation of the JiraServiceType + # Here we will want to expose a field with jira_projects fetched through Jira Rest API + # MR implementing it https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28190 + end + end + end +end diff --git a/app/models/service.rb b/app/models/service.rb index 017c15468a2..543869c71d6 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -8,6 +8,17 @@ class Service < ApplicationRecord include ProjectServicesLoggable include DataFields + SERVICE_NAMES = %w[ + alerts asana assembla bamboo bugzilla buildkite campfire custom_issue_tracker discord + drone_ci emails_on_push external_wiki flowdock hangouts_chat hipchat irker jira + mattermost mattermost_slash_commands microsoft_teams packagist pipelines_email + pivotaltracker prometheus pushover redmine slack slack_slash_commands teamcity unify_circuit youtrack + ].freeze + + DEV_SERVICE_NAMES = %w[ + mock_ci mock_deployment mock_monitoring + ].freeze + serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize default_value_for :active, false @@ -46,6 +57,7 @@ class Service < ApplicationRecord scope :active, -> { where(active: true) } scope :without_defaults, -> { where(default: false) } scope :by_type, -> (type) { where(type: type) } + scope :by_active_flag, -> (flag) { where(active: flag) } scope :templates, -> { where(template: true, type: available_services_types) } scope :instances, -> { where(instance: true, type: available_services_types) } @@ -295,51 +307,30 @@ class Service < ApplicationRecord end def self.available_services_names - service_names = %w[ - alerts - asana - assembla - bamboo - bugzilla - buildkite - campfire - custom_issue_tracker - discord - drone_ci - emails_on_push - external_wiki - flowdock - hangouts_chat - hipchat - irker - jira - mattermost - mattermost_slash_commands - microsoft_teams - packagist - pipelines_email - pivotaltracker - prometheus - pushover - redmine - slack - slack_slash_commands - teamcity - unify_circuit - youtrack - ] - - if Rails.env.development? - service_names += %w[mock_ci mock_deployment mock_monitoring] - end + service_names = services_names + service_names += dev_services_names service_names.sort_by(&:downcase) end + def self.services_names + SERVICE_NAMES + end + + def self.dev_services_names + return [] unless Rails.env.development? + + DEV_SERVICE_NAMES + end + def self.available_services_types available_services_names.map { |service_name| "#{service_name}_service".camelize } end + def self.services_types + services_names.map { |service_name| "#{service_name}_service".camelize } + end + def self.build_from_template(project_id, template) service = template.dup |