tokite 0.2.1 → 0.3.0

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: 93c9e70ee7ad42fe6addd071c719a4e99d501e08
4
- data.tar.gz: c4402fec11b740e86ced9bdfa9b575a0a834cbf9
3
+ metadata.gz: 61507370f117a063a32e900733d2aed4110f03db
4
+ data.tar.gz: 28fa71535585bcb3e540242c9129587997f5bacf
5
5
  SHA512:
6
- metadata.gz: 9e729210aee4fe79beb3b6aa0cd9793125dd74040116ec457d8c938c87864303a9b89193e44d34c96c5038742da00f9c69ba033586305899b6168b572bd03f52
7
- data.tar.gz: a22b3fc1e2344aaef19ee1b78f66039b2aee377f723f079f5310dccaca4908d9d377576abe4f7aaafcc0a5effc79000a35e4ee2d666759d474e87b9bbfeb00c5
6
+ metadata.gz: a4f6e950763b194f47a781d8fd90aaa31f17a0e06eb19253daf73841c53286f457ba26d98e4f77acec4775a15c5a7e89c2b030074a5fb0fbf44e25a55f3a2c14
7
+ data.tar.gz: 7bae44d0e99c447ab6e02d1054a025176a858fcab9aab169eecf2c86294931df30a968d7391961141360085f11f456fb14989fffa4b3fa07b6cb5eb1d0b8e9e3
data/README.md CHANGED
@@ -57,9 +57,10 @@ Tokite support only below events now.
57
57
 
58
58
  <table>
59
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>
60
+ <tr><td>Plain word</td><td>hoge fuga moge</td></tr>
61
+ <tr><td>Quoted word</td><td>"hoge fuga moge"</td></tr>
62
+ <tr><td>Regular expression word</td><td>/hoge|fuga|moge/</td></tr>
63
+ <tr><td>Exclude word</td><td> -/(hoge|fuga|moge)/ -user:hogelog</td></tr>
63
64
  </table>
64
65
 
65
66
  ### Supported query field
@@ -68,8 +69,9 @@ Tokite support only below events now.
68
69
  <tr><th>Name</th><th>Description</th><th>Example</th></tr>
69
70
  <tr><td>repo:</td><td>Match repository name.</td><td>repo:hogelog/tokite</td></tr>
70
71
  <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>event:</td><td>Match event type pull_request, issues, issue_comment, pull_request_review, pull_request_review_comment.</td><td>event:/pull_request|issues|pull_request_review|pull_request_review_comment/</td></tr>
72
73
  <tr><td>body:</td><td>Match body text.</td><td>body:"review please"</td></tr>
73
74
  <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
+ <tr><td>review_state:</td><td>Match pull_request_review state.</td><td>review_state:/commented|approved|changes_requested/</td></tr>
76
+ <tr><td>unspecified</td><td>Match title or body field.</td><td>review please</td></tr>
75
77
  </table>
@@ -1,9 +1,13 @@
1
+ require "tokite/exception_logger"
2
+
1
3
  module Tokite
2
4
  class NotifyGithubHookEventJob < ApplicationJob
3
5
  queue_as :default
4
6
 
5
7
  def perform(payload)
6
8
  Rails.application.config.slack_notifier.ping(payload)
9
+ rescue Slack::Notifier::APIError => e
10
+ ExceptionLogger.log(e, level: :warn)
7
11
  end
8
12
  end
9
13
  end
@@ -6,6 +6,8 @@ module Tokite
6
6
  "pull_request" => HookEvent::PullRequest,
7
7
  "issues" => HookEvent::Issues,
8
8
  "issue_comment" => HookEvent::IssueComment,
9
+ "pull_request_review" => HookEvent::PullRequestReview,
10
+ "pull_request_review_comment" => HookEvent::PullRequestReviewComment,
9
11
  }.freeze
10
12
 
11
13
  def self.fire!(github_event, hook_params)
@@ -0,0 +1,54 @@
1
+ module Tokite
2
+ module HookEvent
3
+ class PullRequestReview < BaseEvent
4
+ def fields
5
+ {
6
+ event: "pull_request_review",
7
+ repo: hook_params[:repository][:full_name],
8
+ body: hook_params[:review][:body],
9
+ user: hook_params[:review][:user][:login],
10
+ review_state: hook_params[:review][:state],
11
+ }
12
+ end
13
+
14
+ def notify?
15
+ return false unless hook_params[:action] == "submitted"
16
+ if hook_params[:review][:state] == "commented"
17
+ hook_params[:review][:body]
18
+ else
19
+ true
20
+ end
21
+ end
22
+
23
+ def slack_text
24
+ repo = "<#{hook_params[:repository][:html_url]}|[#{hook_params[:repository][:full_name]}]>"
25
+ user = "<#{hook_params[:review][:user][:html_url]}|#{hook_params[:review][:user][:login]}>"
26
+ title = "<#{hook_params[:pull_request][:html_url]}|##{hook_params[:pull_request][:number]} #{hook_params[:pull_request][:title]}>"
27
+ case hook_params[:review][:state]
28
+ when "commented"
29
+ "#{repo} New comment by #{user} on pull request #{title}"
30
+ when "approved"
31
+ "#{repo} #{user} approved #{title}"
32
+ when "changes_requested"
33
+ "#{repo} #{user} requested changes #{title}"
34
+ end
35
+ end
36
+
37
+ def slack_attachment
38
+ return unless hook_params[:review][:body]
39
+ case hook_params[:review][:state]
40
+ when "commented"
41
+ when "approved"
42
+ color = "good"
43
+ when "changes_requested"
44
+ color = "warning"
45
+ end
46
+ {
47
+ fallback: hook_params[:review][:body],
48
+ text: hook_params[:review][:body],
49
+ color: color,
50
+ }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ module Tokite
2
+ module HookEvent
3
+ class PullRequestReviewComment < BaseEvent
4
+ def fields
5
+ {
6
+ event: "pull_request_review_comment",
7
+ repo: hook_params[:repository][:full_name],
8
+ body: hook_params[:comment][:body],
9
+ user: hook_params[:comment][:user][:login],
10
+ }
11
+ end
12
+
13
+ def notify?
14
+ hook_params[:action] == "created"
15
+ end
16
+
17
+ def slack_text
18
+ nil
19
+ end
20
+
21
+ def slack_attachment
22
+ user = hook_params[:comment][:user][:login]
23
+ line = hook_params[:comment][:position]
24
+ path = hook_params[:comment][:path]
25
+ footer_url = hook_params[:comment][:html_url]
26
+ footer_text = "Comment by #{user} on line #{line} of #{path}"
27
+ {
28
+ fallback: "#{hook_params[:comment][:body]}\n#{footer_text}",
29
+ text: hook_params[:comment][:body],
30
+ footer: "<#{footer_url}|#{footer_text}>"
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,7 +3,8 @@ module Tokite
3
3
  attr_reader :search_query
4
4
 
5
5
  belongs_to :user
6
-
6
+
7
+ validates :name, presence: true
7
8
  validate :validate_query
8
9
  validate :validate_user_id
9
10
  validate :validate_channel
@@ -22,10 +22,11 @@ module Tokite
22
22
  rule(:regexp_word) { slash >> regexp_char.repeat(1).as(:regexp_word) >> slash }
23
23
  rule(:quot_word) { quot >> quoted_char.repeat(1).as(:word) >> quot }
24
24
  rule(:plain_word) { (match('[^\s/"]') >> match('[^\s]').repeat).as(:word) }
25
+ rule(:exclude) { match('-').as(:exclude) }
25
26
  rule(:field) { match('\w').repeat(1).as(:field) }
26
- rule(:word) { (field >> str(':') >> space?).maybe >> (regexp_word | quot_word | plain_word) }
27
+ rule(:word) { exclude.maybe >> (field >> str(':') >> space?).maybe >> (regexp_word | quot_word | plain_word) }
27
28
 
28
- rule(:query) { word >> (space >> word).repeat }
29
+ rule(:query) { space? >> word >> (space >> word).repeat >> space? }
29
30
  root :query
30
31
  end
31
32
 
@@ -54,11 +55,12 @@ module Tokite
54
55
  end
55
56
  if word[:regexp_word]
56
57
  regexp = Regexp.compile(word[:regexp_word].to_s, Regexp::IGNORECASE)
57
- targets.any?{|text| regexp.match?(text) }
58
+ matched = targets.any?{|text| regexp.match?(text) }
58
59
  else
59
60
  value = word[:word].to_s.downcase
60
- targets.any?{|text| text.index(value) }
61
+ matched = targets.any?{|text| text.index(value) }
61
62
  end
63
+ word[:exclude].present? ? !matched : matched
62
64
  end
63
65
  end
64
66
  end
@@ -20,14 +20,17 @@
20
20
  %th Name
21
21
  %th Example
22
22
  %tr
23
- %td Plain text
23
+ %td Plain word
24
24
  %td hoge fuga moge
25
25
  %tr
26
- %td Quoted text
26
+ %td Quoted word
27
27
  %td "hoge fuga moge"
28
28
  %tr
29
- %td Regular expression
29
+ %td Regular expression word
30
30
  %td /(hoge|fuga|moge)/
31
+ %tr
32
+ %td Exclude word
33
+ %td -/(hoge|fuga|moge)/ -user:hogelog
31
34
 
32
35
  %h2 Supported query field
33
36
  %table.table.is-bordered
@@ -45,8 +48,8 @@
45
48
  %td title:Bug
46
49
  %tr
47
50
  %td event:
48
- %td Match event type pull_request, issues or issue_comment.
49
- %td event:/(pull_request|issues)/
51
+ %td Match event type pull_request, issues, issue_comment, pull_request_review, pull_request_review_comment.
52
+ %td event:/pull_request|issues|pull_request_review|pull_request_review_comment/
50
53
  %tr
51
54
  %td body:
52
55
  %td Match body text.
@@ -55,7 +58,11 @@
55
58
  %td user:
56
59
  %td Match user name.
57
60
  %td user:hogelog
61
+ %tr
62
+ %td review_state:
63
+ %td Match pull_request_review state.
64
+ %td review_state:/commented|approved|changes_requested/
58
65
  %tr
59
66
  %td unspecified
60
67
  %td Match title or body field.
61
- %td hogelog
68
+ %td review please
@@ -1,5 +1,11 @@
1
1
  if ENV["SLACK_WEBHOOK_URL"]
2
- Tokite::Engine.config.slack_notifier = Slack::Notifier.new ENV["SLACK_WEBHOOK_URL"] do
2
+ webhook_url = ENV["SLACK_WEBHOOK_URL"]
3
+ elsif Rails.env.test?
4
+ webhook_url = "https://example.com/notify"
5
+ end
6
+
7
+ if webhook_url
8
+ Tokite::Engine.config.slack_notifier = Slack::Notifier.new webhook_url do
3
9
  if ENV["SLACK_ICON_EMOJI"]
4
10
  defaults username: ENV.fetch("SLACK_NAME", "tokite"), icon_emoji: ENV["SLACK_ICON_EMOJI"]
5
11
  else
@@ -25,13 +25,11 @@ namespace :tokite do
25
25
 
26
26
  desc "Install schema"
27
27
  task :install do
28
- tokite_schema_dir = app_path("schema/tokite")
29
- mkdir(tokite_schema_dir) unless Dir.exist?(tokite_schema_dir)
30
-
31
28
  schema_dir = app_path("schema")
32
- mkdir(schema_dir) unless Dir.exist?(schema_dir)
29
+ tokite_schema_dir = app_path("schema/tokite")
30
+ mkdir_p(tokite_schema_dir) unless Dir.exist?(tokite_schema_dir)
33
31
 
34
- Dir.glob("#{engine_path("schema")}/*").each do |src_path|
32
+ Dir.glob("#{engine_path("schema")}/**/*.schema").each do |src_path|
35
33
  basename = File.basename(src_path)
36
34
  if File.exist?(File.join(tokite_schema_dir, basename))
37
35
  puts "Skip install schema #{src_path}"
@@ -0,0 +1,15 @@
1
+ module Tokite
2
+ class ExceptionLogger
3
+ def self.callbacks
4
+ @callbacks ||= []
5
+ end
6
+
7
+ def self.configure(callback)
8
+ callbacks << callback
9
+ end
10
+
11
+ def self.log(e, options = {})
12
+ callbacks.each{|callback| callback.call(e, options) }
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Tokite
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
data/schema/Schemafile ADDED
@@ -0,0 +1,3 @@
1
+ Dir.glob(File.expand_path("../*.schema", __FILE__)).each do |path|
2
+ require path
3
+ end
@@ -0,0 +1,7 @@
1
+ create_table "tokite_repositories", force: :cascade do |t|
2
+ t.string "name", limit: 200, null: false
3
+ t.string "url", limit: 200, null: false
4
+ t.datetime "created_at", null: false
5
+ end
6
+
7
+ add_index "tokite_repositories", ["name"], name: "tokite_repositories_uniq_name", unique: true, using: :btree
@@ -0,0 +1,12 @@
1
+ create_table "tokite_rules", force: :cascade do |t|
2
+ t.integer "user_id", null: false
3
+ t.string "name", limit: 50, null: false
4
+ t.string "query", limit: 2000, null: false
5
+ t.string "channel", limit: 100, null: false
6
+ t.string "icon_emoji", limit: 20, null: false, default: ""
7
+ t.string "additional_text", limit: 200, null: false, default: ""
8
+ t.datetime "created_at", null: false
9
+ t.datetime "updated_at", null: false
10
+ end
11
+
12
+ add_index "tokite_rules", ["user_id", "name"], name: "tokite_rule_uniq_name", unique: true, using: :btree
@@ -0,0 +1,8 @@
1
+ create_table "tokite_secure_user_tokens", force: :cascade do |t|
2
+ t.integer "user_id", null: false
3
+ t.string "token", limit: 40, null: false
4
+ t.datetime "created_at", null: false
5
+ t.datetime "updated_at", null: false
6
+ end
7
+
8
+ add_index "tokite_secure_user_tokens", ["user_id"], name: "tokite_secure_user_token_uniq_user_id", unique: true, using: :btree
@@ -0,0 +1,10 @@
1
+ create_table "tokite_users", force: :cascade do |t|
2
+ t.string "provider", limit: 20, null: false
3
+ t.string "uid", limit: 40, null: false
4
+ t.string "name", limit: 40, null: false
5
+ t.string "image_url", limit: 200, null: false
6
+ t.datetime "created_at", null: false
7
+ t.datetime "updated_at", null: false
8
+ end
9
+
10
+ add_index "tokite_users", ["provider", "uid"], name: "tokite_user_uniq_provider_uid", unique: true, using: :btree
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.1
4
+ version: 0.3.0
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-20 00:00:00.000000000 Z
11
+ date: 2017-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -210,6 +210,8 @@ files:
210
210
  - app/models/tokite/hook_event/issue_comment.rb
211
211
  - app/models/tokite/hook_event/issues.rb
212
212
  - app/models/tokite/hook_event/pull_request.rb
213
+ - app/models/tokite/hook_event/pull_request_review.rb
214
+ - app/models/tokite/hook_event/pull_request_review_comment.rb
213
215
  - app/models/tokite/repository.rb
214
216
  - app/models/tokite/revision.rb
215
217
  - app/models/tokite/rule.rb
@@ -242,7 +244,13 @@ files:
242
244
  - lib/tasks/yarn.rake
243
245
  - lib/tokite.rb
244
246
  - lib/tokite/engine.rb
247
+ - lib/tokite/exception_logger.rb
245
248
  - lib/tokite/version.rb
249
+ - schema/Schemafile
250
+ - schema/tokite_repositories.schema
251
+ - schema/tokite_rules.schema
252
+ - schema/tokite_secure_user_tokens.schema
253
+ - schema/tokite_users.schema
246
254
  homepage: https://github.com/hogelog/tokite/
247
255
  licenses:
248
256
  - MIT