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

issue_close.rb « slash_commands « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5fcc86e91c411b2e10b37248e5dfa4e823c5f16f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

module Gitlab
  module SlashCommands
    class IssueClose < IssueCommand
      def self.match(text)
        /\Aissue\s+close\s+#{Issue.reference_prefix}?(?<iid>\d+)/.match(text)
      end

      def self.help_message
        "issue close <id>"
      end

      def self.allowed?(project, user)
        can?(user, :update_issue, project)
      end

      def execute(match)
        issue = find_by_iid(match[:iid])

        return not_found unless issue
        return presenter(issue).already_closed if issue.closed?

        close_issue(issue: issue)

        presenter(issue).present
      end

      private

      def close_issue(issue:)
        Issues::CloseService.new(project, current_user).execute(issue)
      end

      def presenter(issue)
        Gitlab::SlashCommands::Presenters::IssueClose.new(issue)
      end

      def not_found
        Gitlab::SlashCommands::Presenters::Access.new.not_found
      end
    end
  end
end