Class: Furik::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/furik/cli.rb

Instance Method Summary collapse

Instance Method Details

#activityObject



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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/furik/cli.rb', line 48

def activity
  from = Date.parse(options[:from])
  to   = Date.parse(options[:to])
  since = options[:since]

  diff = (to - from).to_i
  diff.zero? ? from -= since : since = diff

  period = case since
  when 999 then 'All'
  when 0 then "Today's"
  else "#{since + 1}days"
  end
  puts "#{period} Activities"
  puts '-'
  puts ''

  Furik.events_with_grouping(gh: options[:gh], ghe: options[:ghe], from: from, to: to) do |repo, events|
    puts "### #{repo}"
    puts ''

    events.sort_by(&:type).reverse.each_with_object({ keys: [] }) do |event, memo|

      payload_type = event.type.
      gsub('Event', '').
      gsub(/.*Comment/, 'Comment').
      gsub('Issues', 'Issue').
      underscore
      payload = event.payload.send(:"#{payload_type}")
      type = payload_type.dup

      title = case event.type
      when 'IssueCommentEvent'
        "#{payload.body.plain.cut} (#{event.payload.issue.title.cut(30)})"
      when 'CommitCommentEvent'
        payload.body.plain.cut
      when 'IssuesEvent'
        type = "#{event.payload.action}_#{type}"
        payload.title.plain.cut
      when 'PullRequestReviewCommentEvent'
        type = 'comment'
        if event.payload.pull_request.respond_to?(:title)
          "#{payload.body.plain.cut} (#{event.payload.pull_request.title.cut(30)})"
        else
          payload.body.plain.cut
        end
      else
        payload.title.plain.cut
      end

      link = payload.html_url
      key = "#{type}-#{link}"

      next if memo[:keys].include?(key)
      memo[:keys] << key

      puts "- [#{type}](#{link}): #{title}"
    end

    puts ''
  end
end

#pullsObject



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
# File 'lib/furik/cli.rb', line 11

def pulls
  start_date = Date.parse(options[:start_date]) if options[:start_date]
  end_date = Date.parse(options[:end_date]) if options[:end_date]

  puts "Pull Requests#{" (#{start_date}...#{end_date})" if start_date && end_date}"
  puts '-'
  puts ''

  Furik.pull_requests(gh: options[:gh], ghe: options[:ghe]) do |repo, issues|
    if issues && !issues.empty?
      string_issues = issues.each.with_object('') do |issue, memo|
        date = issue.created_at.localtime.to_date

        next if start_date && date < start_date
        next if end_date && date > end_date

        memo << "- [#{issue.title}](#{issue.html_url}):"
        memo << " (#{issue.body.plain.cut})" if issue.body && !issue.body.empty?
        memo << " #{issue.created_at.localtime.to_date}\n"
      end

      unless string_issues == ''
        puts "### #{repo}"
        puts ''
        puts string_issues
        puts ''
      end
    end
  end
end