<commit_before>require 'cinch'
require 'octokit'
require_relative '../../variables'

module Plugins
  module Commands
    class IssueLink
      include Cinch::Plugin

      set(:prefix, /\#/)
      match(/([\d]+)/)

      def form_message(state, title, labels, number)
        if labels.empty?
          "The issue, \"#{title}\" ##{number}, is #{state}."
        else
          "The issue, \"#{title}\" ##{number}, is #{state}, with the " \
          "following labels: #{labels.join(', ')}"
        end
      end

      def execute(msg, issue_num)
        if Variables::Constants::ISSUE_TRACKING.include? msg.channel
          repo = Variables::Constants::ISSUE_TRACKING[msg.channel]
          begin
            issue = Octokit.issue(repo, issue_num)
            state = issue['state']
            title = issue['title']
            labels = []
            issue['labels'].each do |l|
              labels << l['name']
            end
            msg.reply("https://github.com/#{repo}/issues/#{issue_num}")
            msg.reply(form_message(state, title, labels, issue_num))
          rescue Octokit::NotFound
            msg.reply("Issue ##{issue_num} cannot be found.")
          end
        end
      end
    end
  end
end<commit_msg>:gem: Use user/repo syntax to get issue information. Close #70.<commit_after>require 'cinch'
require 'octokit'
require_relative '../../variables'

module Plugins
  module Commands
    class IssueLink
      include Cinch::Plugin

      match(/([\d]+)/, method: :default_repo, prefix: /\#/)

      def form_message(state, title, labels, number)
        if labels.empty?
          "The issue, \"#{title}\" ##{number}, is #{state}."
        else
          "The issue, \"#{title}\" ##{number}, is #{state}, with the " \
          "following labels: #{labels.join(', ')}"
        end
      end

      def default_repo(msg, issue_num)
        match = msg.message.match(/(\S+)\/(\S+)##{issue_num}/)
        unless match.nil?
          msg_data = match.to_s.split(/[\#\/]/)
          repo_syntax(msg, msg_data[0], msg_data[1], msg_data[2])
          return
        end
        return unless Variables::Constants::ISSUE_TRACKING.include?(msg.channel)
        repo = Variables::Constants::ISSUE_TRACKING[msg.channel]
        begin
          issue = Octokit.issue(repo, issue_num)
          state = issue['state']
          title = issue['title']
          labels = []
          issue['labels'].each do |l|
            labels << l['name']
          end
          msg.reply("https://github.com/#{repo}/issues/#{issue_num}")
          msg.reply(form_message(state, title, labels, issue_num))
        rescue Octokit::NotFound
          msg.reply("Issue ##{issue_num} cannot be found.")
        end
      end

      def repo_syntax(msg, user, repo, num)
        issue = Octokit.issue("#{user}/#{repo}", num)
        labels = []
        issue['labels'].each do |label|
          labels << label['name']
        end
        msg.reply("https://github.com/#{user}/#{repo}/#{num}")
        msg.reply(form_message(issue['state'], issue['title'], labels, num))
      rescue Octokit::NotFound
        msg.relpy("Issue ##{issue} cannot be found.")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.15678896205707119, 'fraction_numerical': 0.0015678896205707118, 'mean_word_length': 2.115234375, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4720186', 'n_tokens_mistral': 962, 'n_tokens_neox': 950, 'n_words': 220}