diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-06 09:06:23 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-06 09:06:23 +0000 |
commit | d15180e00b209d0fbe3d8ce61b3af269aecdf7f5 (patch) | |
tree | e24bcc044a3e471811b91ade8a23120a27210c3f /lib | |
parent | 505c40d537244b35807129ade0c577f752e9d564 (diff) | |
download | gitlab-ce-d15180e00b209d0fbe3d8ce61b3af269aecdf7f5.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/slash_commands/command.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/slash_commands/issue_comment.rb | 55 | ||||
-rw-r--r-- | lib/gitlab/slash_commands/presenters/access.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/slash_commands/presenters/issue_comment.rb | 43 | ||||
-rw-r--r-- | lib/gitlab/slash_commands/presenters/note_base.rb | 48 | ||||
-rw-r--r-- | lib/gitlab/usage_data.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/usage_data_counters/web_ide_counter.rb | 14 |
7 files changed, 166 insertions, 2 deletions
diff --git a/lib/gitlab/slash_commands/command.rb b/lib/gitlab/slash_commands/command.rb index 079b5916566..239479f99d2 100644 --- a/lib/gitlab/slash_commands/command.rb +++ b/lib/gitlab/slash_commands/command.rb @@ -10,6 +10,7 @@ module Gitlab Gitlab::SlashCommands::IssueSearch, Gitlab::SlashCommands::IssueMove, Gitlab::SlashCommands::IssueClose, + Gitlab::SlashCommands::IssueComment, Gitlab::SlashCommands::Deploy, Gitlab::SlashCommands::Run ] diff --git a/lib/gitlab/slash_commands/issue_comment.rb b/lib/gitlab/slash_commands/issue_comment.rb new file mode 100644 index 00000000000..cbb9c41aab0 --- /dev/null +++ b/lib/gitlab/slash_commands/issue_comment.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +module Gitlab + module SlashCommands + class IssueComment < IssueCommand + def self.match(text) + /\Aissue\s+comment\s+#{Issue.reference_prefix}?(?<iid>\d+)\n*(?<note_body>(.|\n)*)/.match(text) + end + + def self.help_message + 'issue comment <id> *`⇧ Shift`*+*`↵ Enter`* <comment>' + end + + def execute(match) + note_body = match[:note_body].to_s.strip + issue = find_by_iid(match[:iid]) + + return not_found unless issue + return access_denied unless can_create_note?(issue) + + note = create_note(issue: issue, note: note_body) + + if note.persisted? + presenter(note).present + else + presenter(note).display_errors + end + end + + private + + def can_create_note?(issue) + Ability.allowed?(current_user, :create_note, issue) + end + + def not_found + Gitlab::SlashCommands::Presenters::Access.new.not_found + end + + def access_denied + Gitlab::SlashCommands::Presenters::Access.new.generic_access_denied + end + + def create_note(issue:, note:) + note_params = { noteable: issue, note: note } + + Notes::CreateService.new(project, current_user, note_params).execute + end + + def presenter(note) + Gitlab::SlashCommands::Presenters::IssueComment.new(note) + end + end + end +end diff --git a/lib/gitlab/slash_commands/presenters/access.rb b/lib/gitlab/slash_commands/presenters/access.rb index 9ce1bcfb37c..fbc3cf2e049 100644 --- a/lib/gitlab/slash_commands/presenters/access.rb +++ b/lib/gitlab/slash_commands/presenters/access.rb @@ -15,6 +15,10 @@ module Gitlab MESSAGE end + def generic_access_denied + ephemeral_response(text: 'You are not allowed to perform the given chatops command.') + end + def deactivated ephemeral_response(text: <<~MESSAGE) You are not allowed to perform the given chatops command since diff --git a/lib/gitlab/slash_commands/presenters/issue_comment.rb b/lib/gitlab/slash_commands/presenters/issue_comment.rb new file mode 100644 index 00000000000..cce71e23b21 --- /dev/null +++ b/lib/gitlab/slash_commands/presenters/issue_comment.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Gitlab + module SlashCommands + module Presenters + class IssueComment < Presenters::Base + include Presenters::NoteBase + + def present + ephemeral_response(new_note) + end + + private + + def new_note + { + attachments: [ + { + title: "#{issue.title} · #{issue.to_reference}", + title_link: resource_url, + author_name: author.name, + author_icon: author.avatar_url, + fallback: "New comment on #{issue.to_reference}: #{issue.title}", + pretext: pretext, + color: color, + fields: fields, + mrkdwn_in: [ + :title, + :pretext, + :fields + ] + } + ] + } + end + + def pretext + "I commented on an issue on #{author_profile_link}'s behalf: *#{issue.to_reference}* in #{project_link}" + end + end + end + end +end diff --git a/lib/gitlab/slash_commands/presenters/note_base.rb b/lib/gitlab/slash_commands/presenters/note_base.rb new file mode 100644 index 00000000000..7758fc740de --- /dev/null +++ b/lib/gitlab/slash_commands/presenters/note_base.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Gitlab + module SlashCommands + module Presenters + module NoteBase + GREEN = '#38ae67' + + def color + GREEN + end + + def issue + resource.noteable + end + + def project + issue.project + end + + def project_link + "[#{project.full_name}](#{project.web_url})" + end + + def author + resource.author + end + + def author_profile_link + "[#{author.to_reference}](#{url_for(author)})" + end + + def fields + [ + { + title: 'Comment', + value: resource.note + } + ] + end + + private + + attr_reader :resource + end + end + end +end diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb index 30c9855507d..5dbdc8b2cdd 100644 --- a/lib/gitlab/usage_data.rb +++ b/lib/gitlab/usage_data.rb @@ -131,7 +131,8 @@ module Gitlab omniauth_enabled: Gitlab::Auth.omniauth_enabled?, prometheus_metrics_enabled: Gitlab::Metrics.prometheus_metrics_enabled?, reply_by_email_enabled: Gitlab::IncomingEmail.enabled?, - signup_enabled: Gitlab::CurrentSettings.allow_signup? + signup_enabled: Gitlab::CurrentSettings.allow_signup?, + web_ide_clientside_preview_enabled: Gitlab::CurrentSettings.web_ide_clientside_preview_enabled? } end diff --git a/lib/gitlab/usage_data_counters/web_ide_counter.rb b/lib/gitlab/usage_data_counters/web_ide_counter.rb index 0718c1dd761..c012a6c96df 100644 --- a/lib/gitlab/usage_data_counters/web_ide_counter.rb +++ b/lib/gitlab/usage_data_counters/web_ide_counter.rb @@ -8,6 +8,7 @@ module Gitlab COMMITS_COUNT_KEY = 'WEB_IDE_COMMITS_COUNT' MERGE_REQUEST_COUNT_KEY = 'WEB_IDE_MERGE_REQUESTS_COUNT' VIEWS_COUNT_KEY = 'WEB_IDE_VIEWS_COUNT' + PREVIEW_COUNT_KEY = 'WEB_IDE_PREVIEWS_COUNT' class << self def increment_commits_count @@ -34,11 +35,22 @@ module Gitlab total_count(VIEWS_COUNT_KEY) end + def increment_previews_count + return unless Gitlab::CurrentSettings.web_ide_clientside_preview_enabled? + + increment(PREVIEW_COUNT_KEY) + end + + def total_previews_count + total_count(PREVIEW_COUNT_KEY) + end + def totals { web_ide_commits: total_commits_count, web_ide_views: total_views_count, - web_ide_merge_requests: total_merge_requests_count + web_ide_merge_requests: total_merge_requests_count, + web_ide_previews: total_previews_count } end end |