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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4f189154d3633ba2c3bf0e70cea9234251b43bd
4
- data.tar.gz: cd236b8776e7579ac0704c1abe5c7e75e0d7fe2e
3
+ metadata.gz: 67330e6c1b98d85adb47bb8bf12a4f1414a59b13
4
+ data.tar.gz: 4054e335ad22e25c1e14d8666e8f64360281912f
5
5
  SHA512:
6
- metadata.gz: f9ce12f320ee1d3c2ad2fe06ab1b9fd855161b68e1e48a33082bf05907c3d189fd3d588363835913ebbf88ab90095cc0650120b54f900121bcdf417fc0f54dfc
7
- data.tar.gz: dde4baa295adf27d5cedd7fdb1178b2c28a1bae47d837c4619a80cdc4a0b69bef6c7b82f5878bf1d51a256f8e62f3b702aba67eb1c9b4987b3b1552857eeb075
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
- if assign && !issue[:assignee]
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)
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module GithubAssignor
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -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
@@ -84,7 +84,7 @@
84
84
  "number": 1347,
85
85
  "state": "open",
86
86
  "title": "Found a bug",
87
- "body": "I'm having a problem with this.",
87
+ "body": "Please review this.",
88
88
  "user": {
89
89
  "login": "octocat",
90
90
  "id": 1,
@@ -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
@@ -1,3 +1,5 @@
1
+ ENV.delete('OCTOKIT_API_ENDPOINT')
2
+
1
3
  require 'ruboty/github_assignor'
2
4
  require 'webmock/rspec'
3
5
 
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.2
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-13 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty