This repository was archived by the owner on Jul 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnippo.rb
More file actions
134 lines (106 loc) · 3.01 KB
/
nippo.rb
File metadata and controls
134 lines (106 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
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
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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
require 'octokit'
USER_NAME = ENV['NIPPO_GITHUB_USER_NAME']
class Nippo
def pull_requests
@pull_requests ||= PullRequests.new(all_user_events)
end
def client
@@client = Octokit::Client.new(login: USER_NAME, access_token: ENV['NIPPO_GITHUB_API_TOKEN'])
end
def all_user_events
@all_user_events ||= (user_events + user_public_events).uniq{|e| e.id}
end
def user_events
@@user_events ||= client.user_events(USER_NAME, per_page: 100)
end
def user_public_events
@@user_public_events ||= client.user_public_events(USER_NAME, per_page: 100)
end
class Events
def initialize(events)
@events = events
end
protected
def list
@events.select{|event| event.type == self.type}
end
def events_by_action(action)
list.select{|event| event.payload.action == action}
end
end
module IssueBaseEvents
def assigned
events_by_action('assigned')
end
def unassigned
events_by_action('unassigned')
end
def labeled
events_by_action('labeled')
end
def unlabeled
events_by_action('unlabeled')
end
def opened
events_by_action('opened')
end
def closed
events_by_action('closed')
end
def reopened
events_by_action('reopened')
end
def synchronize
events_by_action('synchronize')
end
end
class PullRequests < Events
include IssueBaseEvents
def type
'PullRequestEvent'
end
def all
list
end
def opened
exclude_ids = (merged + unmerged).map{|e| e.payload.pull_request.id}
super.select{|event| not exclude_ids.include?(event.payload.pull_request.id) }
end
def opened_at(date)
opened.select{|event| event.payload.pull_request.created_at.to_date == date }
end
def merged
closed.select{|event| event.payload.pull_request.merged}
end
def merged_at(date)
merged.select{|event| event.payload.pull_request.merged_at.to_date == date}
end
def unmerged
closed.select{|event| !event.payload.pull_request.merged}
end
def unmerged_at(date)
unmerged.select{|event| event.payload.pull_request.closed_at.to_date == date}
end
end
end
def puts_pr_md(title, events, indent)
spaces = ' '
print spaces * indent, "- #{title}\n" unless events.empty?
events.each do |pull_request|
item = "- "
item << "[#{pull_request.payload.pull_request.title} "
item << "by #{pull_request.payload.pull_request.user.login}"
item << " · "
item << "Pull Request ##{pull_request.payload.pull_request.number}"
item << " · "
item << "#{pull_request.repo.name}]"
item << "(#{pull_request.payload.pull_request.html_url})"
item << "\n"
print spaces * (indent + 1), item
end
end
nippo = Nippo.new
puts '- pull_request' unless nippo.pull_requests.all.empty?
puts_pr_md('merged', nippo.pull_requests.merged_at(Date.today), 1)
puts_pr_md('rejected', nippo.pull_requests.unmerged_at(Date.today), 1)
puts_pr_md('opened', nippo.pull_requests.opened_at(Date.today), 1)