Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-06 12:06:23 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-06 12:06:23 +0300
commitd15180e00b209d0fbe3d8ce61b3af269aecdf7f5 (patch)
treee24bcc044a3e471811b91ade8a23120a27210c3f /lib/gitlab/slash_commands
parent505c40d537244b35807129ade0c577f752e9d564 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/slash_commands')
-rw-r--r--lib/gitlab/slash_commands/command.rb1
-rw-r--r--lib/gitlab/slash_commands/issue_comment.rb55
-rw-r--r--lib/gitlab/slash_commands/presenters/access.rb4
-rw-r--r--lib/gitlab/slash_commands/presenters/issue_comment.rb43
-rw-r--r--lib/gitlab/slash_commands/presenters/note_base.rb48
5 files changed, 151 insertions, 0 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