Top Level Namespace

Defined Under Namespace

Modules: Senju

Constant Summary collapse

COLORS =
%w{green blue light_blue}

Instance Method Summary collapse

Instance Method Details

#exec(repo, command, option) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/senju/command.rb', line 25

def exec(repo, command, option)
  puts "================= #{repo.name} ====================".colorize(:green).bold

  if command.to_i != 0
    issue = repo.issue(command.to_i)
    print_issue issue
    puts "Opened by #{issue.owner} at #{issue.created_at}"

    puts "\n" + Rumoji.decode(TTY::Markdown.parse(issue.body))

    if option == "-v" || option == "comments"
      repo.comments(command.to_i).each do |comment|
        #color = COLORS[comment.owner[0].ord % 3]
        puts "\nComment: #{comment.owner} at #{comment.created_at}".bold
        puts Rumoji.decode(TTY::Markdown.parse(comment.body))
      end
    elsif option == "diff"
      repo.changes(command.to_i).each do |change|
        puts "\n#{change.filename}".bold
        puts Senju::Diff.print(change.patch)
      end
    end

    return
  end

  case command
  when "issues"
    repo.issues.each do |issue|
      print_issue(issue)
    end
  when "mr"
    command = option
    option = ARGV[3]
    issue = repo.pull_request(command.to_i)
    print_issue issue
    puts "Opened by #{issue.owner} at #{issue.created_at}"

    puts "\n" + Rumoji.decode(TTY::Markdown.parse(issue.body))

    if option == "-v" || option == "comments"
      repo.comments(command.to_i).each do |comment|
        #color = COLORS[comment.owner[0].ord % 3]
        puts "\nComment: #{comment.owner} at #{comment.created_at}".bold
        puts Rumoji.decode(TTY::Markdown.parse(comment.body))
      end
    elsif option == "diff"
      repo.changes(command.to_i).each do |change|
        puts "\n#{change.filename}".bold
        puts Senju::Diff.print(change.patch)
      end
    end
  when "pr"
    repo.pull_requests.each do |issue|
      print_issue(issue)
    end
  end
end


11
12
13
# File 'lib/senju/command.rb', line 11

def link_to(text, url)
  "\e]8;;#{url}\e\\#{text}\e]8;;\e\\"
end


15
16
17
18
19
20
21
22
23
# File 'lib/senju/command.rb', line 15

def print_issue(issue)
  print link_to("##{issue.no} ".colorize(:blue).bold, issue.url) + issue.title
  if issue.labels.length != 0
    issue.labels.each do |label|
      print " [#{label}]".colorize(:light_blue)
    end
  end
  print "\n"
end