tokite 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5713f325c58d3d8111e0a7d23474ff6f5102a15
4
- data.tar.gz: c8c4507ea06af90e808469887e83dc8038af430e
3
+ metadata.gz: 93c9e70ee7ad42fe6addd071c719a4e99d501e08
4
+ data.tar.gz: c4402fec11b740e86ced9bdfa9b575a0a834cbf9
5
5
  SHA512:
6
- metadata.gz: 8f13bf68e97bf9ce0b3ff43f1a6326964433545e1b4c6a6456da5371eecda96aa67f88d18e50c5591356cf7a0455f1a8557085f18703deb009eac3d808d9d602
7
- data.tar.gz: 106be23f58cb08f37146689762decbd6e5d05a902c46ed03afb58392574c88b5715ee8fd0d7bb0a57bdc0d09fcb9c2fbd67f6bc59c5e9e4198afd723d5a98b09
6
+ metadata.gz: 9e729210aee4fe79beb3b6aa0cd9793125dd74040116ec457d8c938c87864303a9b89193e44d34c96c5038742da00f9c69ba033586305899b6168b572bd03f52
7
+ data.tar.gz: a22b3fc1e2344aaef19ee1b78f66039b2aee377f723f079f5310dccaca4908d9d377576abe4f7aaafcc0a5effc79000a35e4ee2d666759d474e87b9bbfeb00c5
data/README.md CHANGED
@@ -34,13 +34,42 @@ $ ./bin/rails tokite:yarn:install
34
34
 
35
35
  ## Configuration
36
36
  <table>
37
- <tr><th>GOOGLE_CLIENT_ID</th><td>Google+ OAuth2 client ID</td></tr>
38
- <tr><th>GOOGLE_CLIENT_SECRET</th><td>Google+ OAuth2 client secret</td></tr>
39
- <tr><th>GOOGLE_HOSTED_DOMAIN (optional)</th><td>Limited by G Suite domain</td></tr>
37
+ <tr><th>GITHUB_CLIENT_ID</th><td>Google+ OAuth2 client ID</td></tr>
38
+ <tr><th>GITHUB_CLIENT_SECRET</th><td>Google+ OAuth2 client secret</td></tr>
39
+ <tr><th>GITHUB_HOST (optional)</th><td>GitHub Enterprise host</td></tr>
40
40
  <tr><th>SECRET_KEY_BASE</th><td><code>rails secret</code> key</td></tr>
41
41
  <tr><th>SLACK_WEBHOOK_URL</th><td>Slack incoming webhook url</td></tr>
42
42
  <tr><th>SLACK_NAME (optional)</th><td>Slack notification user name</td></tr>
43
43
  <tr><th>SLACK_ICON_EMOJI (optional)</th><td>Slack notification icon</td></tr>
44
- <tr><th>SENTRY_DSN (optional)</th><td>Sentry DSN</td></tr>
45
44
  <tr><th>APP_HOST (optional)</th><td>Application host url</td></tr>
46
45
  </table>
46
+
47
+ ## Usage
48
+ ### Supported Event
49
+
50
+ Tokite support only below events now.
51
+
52
+ - pull_request
53
+ - issues
54
+ - issue_comment
55
+
56
+ ### Supported query type
57
+
58
+ <table>
59
+ <tr><th>Name</th><th>Example</th></tr>
60
+ <tr><td>Plain text</td><td>hoge fuga moge</td></tr>
61
+ <tr><td>Quoted text</td><td>hoge/fuga/moge</td></tr>
62
+ <tr><td>Regular expression</td><td>/hoge|fuga|moge/</td></tr>
63
+ </table>
64
+
65
+ ### Supported query field
66
+
67
+ <table>
68
+ <tr><th>Name</th><th>Description</th><th>Example</th></tr>
69
+ <tr><td>repo:</td><td>Match repository name.</td><td>repo:hogelog/tokite</td></tr>
70
+ <tr><td>title:</td><td>Match pull_request or issues title.</td><td>title:Bug</td></tr>
71
+ <tr><td>event:</td><td>Match event type pull_request, issues or issue_comment.</td><td>event:/(pull_request|issues)/</td></tr>
72
+ <tr><td>body:</td><td>Match body text.</td><td>body:"review please"</td></tr>
73
+ <tr><td>user:</td><td>Match user name.</td><td>user:hogelog</td></tr>
74
+ <tr><td>unspecified</td><td>Match title or body field.</td><td>hogelog</td></tr>
75
+ </table>
@@ -27,7 +27,7 @@ module Tokite
27
27
  emoji = rule.icon_emoji.chomp.presence
28
28
  additional_text = rule.additional_text
29
29
 
30
- if payloads.none? {|payload| payload[:channel] == rule.channel && payload[:icon_emoji] == emoji && payload[:additional_text] == additional_text }
30
+ if payloads.none? {|payload| payload[:channel] == rule.channel && payload[:emoji] == emoji && payload[:additional_text] == additional_text }
31
31
  payloads << {
32
32
  channel: rule.channel,
33
33
  text: event.slack_text,
@@ -6,6 +6,11 @@ module Tokite
6
6
 
7
7
  validate :validate_query
8
8
  validate :validate_user_id
9
+ validate :validate_channel
10
+
11
+ before_validation :normalize_channel
12
+
13
+ INVALID_CHANNEL_CHARS = [" ", ","]
9
14
 
10
15
  # TODO: Performance
11
16
  def self.matched_rules(event)
@@ -37,7 +42,9 @@ module Tokite
37
42
  def user_link
38
43
  "<#{Tokite::Engine.routes.url_helpers.user_url(user)}|#{user.name}>"
39
44
  end
40
-
45
+
46
+ private
47
+
41
48
  def validate_query
42
49
  SearchQuery.parse(query)
43
50
  rescue SearchQuery::ParseError => e
@@ -49,5 +56,19 @@ module Tokite
49
56
  errors.add(:user_id, "Unknown user_id: #{user_id}")
50
57
  end
51
58
  end
59
+
60
+ def validate_channel
61
+ INVALID_CHANNEL_CHARS.each do |invalid_char|
62
+ errors.add(:channel, %(Invalid character: "#{invalid_char}")) if channel.index(invalid_char)
63
+ end
64
+ end
65
+
66
+ def normalize_channel
67
+ if channel.start_with?("#")
68
+ self.channel = channel.strip
69
+ else
70
+ self.channel = "##{channel.strip}"
71
+ end
72
+ end
52
73
  end
53
74
  end
@@ -4,6 +4,8 @@ module Tokite
4
4
  class SearchQuery
5
5
  attr_reader :query, :tree
6
6
 
7
+ DEFAULT_FIELDS = %i(title body)
8
+
7
9
  class ParseError < StandardError
8
10
  end
9
11
 
@@ -48,7 +50,7 @@ module Tokite
48
50
  if field
49
51
  targets = doc[field.to_sym] ? [doc[field.to_sym].downcase] : []
50
52
  else
51
- targets = doc.values.map(&:downcase)
53
+ targets = DEFAULT_FIELDS.map{|field| doc[field]&.downcase }.compact
52
54
  end
53
55
  if word[:regexp_word]
54
56
  regexp = Regexp.compile(word[:regexp_word].to_s, Regexp::IGNORECASE)
@@ -57,5 +57,5 @@
57
57
  %td user:hogelog
58
58
  %tr
59
59
  %td unspecified
60
- %td Match any field.
60
+ %td Match title or body field.
61
61
  %td hogelog
@@ -1,3 +1,3 @@
1
1
  module Tokite
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hogelog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-15 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails