class Github::Nippou::Format

Attributes

settings[R]

Public Class Methods

new(settings, debug) click to toggle source

@param settings [Settings] @param debug [Boolean]

# File lib/github/nippou/format.rb, line 9
def initialize(settings, debug)
  @settings = settings
  @debug = debug
end

Public Instance Methods

all(lines) click to toggle source
# File lib/github/nippou/format.rb, line 35
def all(lines)
  result = ""
  prev_repo_name = nil
  current_repo_name = nil

  sort(lines).each do |line|
    current_repo_name = line[:repo_name]

    unless current_repo_name == prev_repo_name
      prev_repo_name = current_repo_name
      result << "\n#{format_subject(current_repo_name)}\n\n"
    end

    result << "#{format_line(line)}\n"
  end

  result
end
line(user_event, i) click to toggle source
# File lib/github/nippou/format.rb, line 14
def line(user_event, i)
  STDERR.puts "#{i % settings.thread_num} : #{user_event.html_url}\n" if @debug
  issue = issue(user_event)

  line = {
    title: issue.title,
    repo_name: user_event.repo.name,
    url: user_event.html_url,
    user: issue.user.login,
  }

  line[:status] =
    if issue.merged
      :merged
    elsif issue.state == 'closed'
      :closed
    end

  line
end

Private Instance Methods

format_line(line) click to toggle source
# File lib/github/nippou/format.rb, line 78
def format_line(line)
  sprintf(
    settings.format.line,
    title: line[:title].markdown_escape,
    url: line[:url],
    user: line[:user],
    status: format_status(line[:status])
  ).strip
end
format_status(status) click to toggle source
# File lib/github/nippou/format.rb, line 88
def format_status(status)
  return nil if status.nil?
  settings.dictionary.status.send(status)
end
format_subject(subject) click to toggle source
# File lib/github/nippou/format.rb, line 74
def format_subject(subject)
  sprintf(settings.format.subject, subject: subject)
end
issue(user_event) click to toggle source
# File lib/github/nippou/format.rb, line 58
def issue(user_event)
  case
  when user_event.payload.pull_request
    settings.client.pull_request(user_event.repo.name, user_event.payload.pull_request.number)
  when user_event.payload.issue.pull_request
    # a pull_request like an issue
    settings.client.pull_request(user_event.repo.name, user_event.payload.issue.number)
  else
    settings.client.issue(user_event.repo.name, user_event.payload.issue.number)
  end
end
sort(lines) click to toggle source
# File lib/github/nippou/format.rb, line 70
def sort(lines)
  lines.sort { |a, b| a[:url] <=> b[:url] }
end