Sha256: c06946603a7d154b2341c27bcffd139cd4ac886da91a06295384e1e1157fadc5

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Ruboty
  module Github
    module Actions
      class CloseIssue < Base
        def call
          if !has_access_token?
            require_access_token
          elsif has_closed_issue_number?
            reply_already_closed
          else
            close
          end
        rescue Octokit::Unauthorized
          message.reply('Failed in authentication (401)')
        rescue Octokit::NotFound
          message.reply('Could not find that issue')
        rescue StandardError => e
          message.reply("Failed by #{e.class}")
          raise e
        end

        private

        def close
          request
          message.reply("Closed #{issue.html_url}")
        end

        def request
          client.close_issue(repository, issue_number)
        end

        def has_closed_issue_number?
          issue.state == 'closed'
        end

        def reply_already_closed
          message.reply("Already closed #{issue.html_url}")
        end

        def issue
          @issue ||= client.issue(repository, issue_number)
        end

        def issue_number
          message[:number]
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruboty-qiita-github-0.3.4 lib/ruboty/github/actions/close_issue.rb
ruboty-qiita-github-0.3.3 lib/ruboty/github/actions/close_issue.rb
ruboty-qiita-github-0.3.2 lib/ruboty/github/actions/close_issue.rb