lita-pullrequests 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lita/handlers/pullrequests.rb +43 -21
- data/lita-pullrequests.gemspec +2 -1
- data/spec/lita/handlers/pullrequests_spec.rb +6 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2eeaab6bd4a825ee5ce6018fb4c2de5b7e1d514
|
4
|
+
data.tar.gz: da7813b33b98caa2b6b51dd03f79de499d92f2df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19bc54da7c1049c1f770ad2ae62a2b6cff3e6ff67ef88ca3a8e5441ca76c0fcc707d63e2973a3a7890a7d541c7765873b4196039621eedfd4e6bcadcfe5a25bc
|
7
|
+
data.tar.gz: b146587dfa273e7b887b0aa98b456eb890f7835f5e33e69084bb6819a611afcef17f4b93263ab38230f1e601d653f799aef0a83ee6efa711ccd37dbbe5c07c0c
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "rufus-scheduler"
|
2
|
+
|
1
3
|
module Lita
|
2
4
|
module Handlers
|
3
5
|
class Pullrequests < Handler
|
@@ -6,6 +8,11 @@ module Lita
|
|
6
8
|
config :review_label, type: String, required: false
|
7
9
|
config :merge_label, type: String, required: false
|
8
10
|
|
11
|
+
on :loaded, :remember_reminder
|
12
|
+
|
13
|
+
SCHEDULER = Rufus::Scheduler.new
|
14
|
+
REDIS_KEY = "pullrequests-cron"
|
15
|
+
|
9
16
|
route(/^(pull request( me)?)|(give me something to review)$/, :get_random_pr, command: true, help: {
|
10
17
|
"give me something to review" => "Shows you a random pull request that needs reviewing.",
|
11
18
|
"pull request (me)" => "Shows you a random pull request that needs reviewing."
|
@@ -15,20 +22,23 @@ module Lita
|
|
15
22
|
"(summarize|all) pull requests" => "Lists all pull requests that need action."
|
16
23
|
})
|
17
24
|
|
25
|
+
route(/^set pull requests reminder for (.*)$/, :set_reminder, command: true, help: {
|
26
|
+
"set pull requests reminder for CRON EXPRESSION" => "Sets a cron task that will trigger a pr summary."
|
27
|
+
})
|
18
28
|
|
19
|
-
|
20
|
-
|
21
|
-
|
29
|
+
def remember_reminder(payload)
|
30
|
+
reminder = redis.hgetall(REDIS_KEY)["reminder-info"]
|
31
|
+
if reminder
|
32
|
+
info = MultiJson.load(reminder)
|
33
|
+
job = SCHEDULER.cron info["cron_expression"] do |job|
|
34
|
+
target = Source.new(user: info["u_id"], room: info["room"])
|
35
|
+
robot.send_messages(target, formatted_pull_request_summary)
|
36
|
+
end
|
22
37
|
|
23
|
-
|
24
|
-
length_with_room_for_omission = truncate_at - omission.length
|
25
|
-
stop = if options[:separator]
|
26
|
-
str.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
|
38
|
+
log.info "Created cron job: #{info['cron_expression']}."
|
27
39
|
else
|
28
|
-
|
40
|
+
log.info "no reminder found."
|
29
41
|
end
|
30
|
-
|
31
|
-
"#{str[0, stop]}#{omission}"
|
32
42
|
end
|
33
43
|
|
34
44
|
def fetch_pull_requests
|
@@ -41,15 +51,8 @@ module Lita
|
|
41
51
|
def get_random_pr(chat)
|
42
52
|
pr = pulls_that_need_reviews.sample
|
43
53
|
if pr
|
44
|
-
title, user,
|
45
|
-
|
46
|
-
|
47
|
-
chat.reply %Q(
|
48
|
-
#{title} - #{user}
|
49
|
-
#{url}
|
50
|
-
-------------------
|
51
|
-
#{body}
|
52
|
-
)
|
54
|
+
title, user, url = pr["title"], pr["user"]["login"], pr["pull_request"]["html_url"]
|
55
|
+
chat.reply "_#{title}_ - #{user} \n #{url}"
|
53
56
|
else
|
54
57
|
chat.reply "No pull requests need reviews right now!"
|
55
58
|
end
|
@@ -73,7 +76,7 @@ module Lita
|
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
|
-
def
|
79
|
+
def formatted_pull_request_summary
|
77
80
|
response = ":heavy_exclamation_mark: *Pull Requests that need review*:\n"
|
78
81
|
|
79
82
|
response += pulls_that_need_reviews.map do |pr|
|
@@ -89,8 +92,27 @@ module Lita
|
|
89
92
|
url = pr["pull_request"]["html_url"]
|
90
93
|
"- _#{title}_ - #{user} \n #{url}"
|
91
94
|
end.join("\n\n")
|
95
|
+
end
|
96
|
+
|
97
|
+
def list_all_pull_requests(chat)
|
98
|
+
chat.reply(formatted_pull_request_summary)
|
99
|
+
end
|
100
|
+
|
101
|
+
def set_reminder(chat)
|
102
|
+
input = chat.matches[0][0].split(" ")
|
103
|
+
cron_expression = input[0..4].join(" ")
|
104
|
+
job = SCHEDULER.cron cron_expression do |job|
|
105
|
+
list_all_pull_requests(chat)
|
106
|
+
end
|
107
|
+
|
108
|
+
redis.hset(REDIS_KEY, "reminder-info", {
|
109
|
+
:cron_expression => cron_expression,
|
110
|
+
:j_id => job,
|
111
|
+
:u_id => chat.message.source.user.id,
|
112
|
+
:room => chat.message.source.room
|
113
|
+
}.to_json)
|
92
114
|
|
93
|
-
chat.reply(
|
115
|
+
chat.reply("I will post a pull request summary according to this cron: #{cron_expression}")
|
94
116
|
end
|
95
117
|
end
|
96
118
|
|
data/lita-pullrequests.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-pullrequests"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.4"
|
4
4
|
spec.authors = ["Taylor Lapeyre"]
|
5
5
|
spec.email = ["taylorlapeyre@gmail.com"]
|
6
6
|
spec.description = %q{A Lita handler to help you keep track of your pull requests.}
|
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
17
|
spec.add_runtime_dependency "lita", ">= 4.1"
|
18
|
+
spec.add_runtime_dependency "rufus-scheduler"
|
18
19
|
|
19
20
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
21
|
spec.add_development_dependency "rake"
|
@@ -13,6 +13,7 @@ describe Lita::Handlers::Pullrequests, lita_handler: true do
|
|
13
13
|
it { is_expected.to route_command("give me something to review").to(:get_random_pr) }
|
14
14
|
it { is_expected.to route_command("all pull requests").to(:list_all_pull_requests) }
|
15
15
|
it { is_expected.to route_command("summarize pull requests").to(:list_all_pull_requests) }
|
16
|
+
it { is_expected.to route_command("set pull requests reminder for 0 20 * * 1-5").to(:set_reminder) }
|
16
17
|
|
17
18
|
it { is_expected.to_not route_command("all pull requests").to(:get_random_pr) }
|
18
19
|
|
@@ -28,4 +29,9 @@ describe Lita::Handlers::Pullrequests, lita_handler: true do
|
|
28
29
|
expect(replies.last).to match /Example of a pull request ready for merge/
|
29
30
|
expect(replies.last).to match /Example of a pull request ready for review/
|
30
31
|
end
|
32
|
+
|
33
|
+
it "can schedule a reminder" do
|
34
|
+
send_command("set pull requests reminder for 0 20 * * 1-5")
|
35
|
+
expect(replies.last).to match /0 20 \* \* 1\-5/
|
36
|
+
end
|
31
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-pullrequests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Lapeyre
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rufus-scheduler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|