ruboty-github_assignor 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/github_assignor/repo_watcher.rb +36 -3
- data/lib/ruboty/github_assignor/version.rb +1 -1
- data/lib/ruboty/handlers/github_assignor.rb +2 -0
- data/spec/fixtures/issues2.json +1 -1
- data/spec/ruboty/github_assignor/repo_watcher_spec.rb +10 -1
- data/spec/spec_helper.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67330e6c1b98d85adb47bb8bf12a4f1414a59b13
|
4
|
+
data.tar.gz: 4054e335ad22e25c1e14d8666e8f64360281912f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97b474de37e720314d5b89e0010da2a66936bbf1a5aab75837cef1197baf6a5612f0058068e17479021ef7795a52dbe4ddd0d5bb177a22c42b7c540057694839
|
7
|
+
data.tar.gz: 8deb62744daa469b526cb3007c7314fdf5fa73b2d18e89c7c08de7dade175c3d4eda3a35d00a92419c2733fbfda8d556a8275e6ff09b8ba5b62e0f58890f885b
|
@@ -3,12 +3,13 @@ require 'octokit'
|
|
3
3
|
module Ruboty
|
4
4
|
module GithubAssignor
|
5
5
|
class RepoWatcher
|
6
|
-
def initialize(robot:, repo:, octokit:, assignor:, to:)
|
6
|
+
def initialize(robot:, repo:, octokit:, assignor:, to:, messages:)
|
7
7
|
@robot = robot
|
8
8
|
@repo = repo
|
9
9
|
@octokit = octokit
|
10
10
|
@assignor = assignor
|
11
11
|
@to = to
|
12
|
+
@messages = messages
|
12
13
|
|
13
14
|
@checked_issue_ids = []
|
14
15
|
|
@@ -21,7 +22,8 @@ module Ruboty
|
|
21
22
|
@octokit.issues(@repo).each do |issue|
|
22
23
|
unless @checked_issue_ids.include?(issue[:id])
|
23
24
|
log "New issue found (#{issue[:id]} / #{issue[:title]})"
|
24
|
-
|
25
|
+
message = find_message(issue)
|
26
|
+
if message && assign && !issue[:assignee]
|
25
27
|
# assign this issue
|
26
28
|
assignee = @assignor.next
|
27
29
|
log "Assigning this issue to #{assignee}..."
|
@@ -31,7 +33,7 @@ module Ruboty
|
|
31
33
|
|
32
34
|
log "Reminding the user of the issue..."
|
33
35
|
say(<<-EOC)
|
34
|
-
@#{assignee.chat_name}
|
36
|
+
@#{assignee.chat_name} さん、#{message['message']}お願いします!
|
35
37
|
|
36
38
|
#{issue[:title]}
|
37
39
|
<#{issue[:html_url]}>
|
@@ -60,6 +62,37 @@ module Ruboty
|
|
60
62
|
|
61
63
|
private
|
62
64
|
|
65
|
+
# messages
|
66
|
+
# [
|
67
|
+
# {
|
68
|
+
# "message": "レビュー",
|
69
|
+
# "conditions": [{
|
70
|
+
# "keywords": [...], # AND
|
71
|
+
# "including_mention": true/false,
|
72
|
+
# }],
|
73
|
+
# }
|
74
|
+
# ]
|
75
|
+
def find_message(issue)
|
76
|
+
body = issue[:body] || ''
|
77
|
+
including_mention = (/(^| )@\w+/ =~ body)
|
78
|
+
|
79
|
+
@messages.find do |message|
|
80
|
+
message['conditions'].any? do |condition|
|
81
|
+
if condition.has_key?('including_mention') &&
|
82
|
+
(condition['including_mention'] && !including_mention ||
|
83
|
+
!condition['including_mention'] && including_mention)
|
84
|
+
next false
|
85
|
+
end
|
86
|
+
|
87
|
+
including_all_keywords = condition['keywords'].all? do |keyword|
|
88
|
+
body.downcase.include?(keyword.downcase)
|
89
|
+
end
|
90
|
+
|
91
|
+
including_all_keywords
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
63
96
|
def say(body)
|
64
97
|
from = if @robot.send(:adapter).respond_to?(:jid, true)
|
65
98
|
@robot.send(:adapter).send(:jid)
|
@@ -24,6 +24,7 @@ module Ruboty
|
|
24
24
|
data.each do |datum|
|
25
25
|
repo = datum['repo']
|
26
26
|
to = datum['to']
|
27
|
+
messages = datum['messages'] || []
|
27
28
|
assignees = datum['assignees'].map {|assignee| Hash[assignee.map {|k, v| [k.to_sym, v] }] }
|
28
29
|
assignor = Ruboty::GithubAssignor::Assignor.new(assignees)
|
29
30
|
|
@@ -33,6 +34,7 @@ module Ruboty
|
|
33
34
|
octokit: octokit,
|
34
35
|
assignor: assignor,
|
35
36
|
to: to,
|
37
|
+
messages: messages,
|
36
38
|
)
|
37
39
|
watcher.start((ENV['GITHUB_ASSIGNOR_INTERVAL'] || 60).to_i)
|
38
40
|
end
|
data/spec/fixtures/issues2.json
CHANGED
@@ -17,6 +17,15 @@ describe Ruboty::GithubAssignor::RepoWatcher do
|
|
17
17
|
octokit: octokit,
|
18
18
|
assignor: assignor,
|
19
19
|
to: 'room',
|
20
|
+
messages: [
|
21
|
+
{
|
22
|
+
'message' => 'レビュー',
|
23
|
+
'conditions' => [{
|
24
|
+
'including_mention' => false,
|
25
|
+
'keywords' => %w!please review!,
|
26
|
+
}],
|
27
|
+
},
|
28
|
+
],
|
20
29
|
)
|
21
30
|
end
|
22
31
|
|
@@ -38,7 +47,7 @@ describe Ruboty::GithubAssignor::RepoWatcher do
|
|
38
47
|
|
39
48
|
expect(robot).to receive(:say).with(
|
40
49
|
hash_including(body: <<-EOC)
|
41
|
-
@alice
|
50
|
+
@alice さん、レビューお願いします!
|
42
51
|
|
43
52
|
Found a bug
|
44
53
|
<https://github.com/octocat/Hello-World/issues/1347>
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-github_assignor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|