qiita_team_services 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rspec +3 -0
- data/.rubocop.yml +27 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/Rakefile +26 -0
- data/config/locales/en.yml +31 -0
- data/config/locales/ja.yml +32 -0
- data/lib/qiita/team/services/engine.rb +6 -0
- data/lib/qiita/team/services/errors.rb +7 -0
- data/lib/qiita/team/services/events/base.rb +47 -0
- data/lib/qiita/team/services/events/item_became_coediting.rb +10 -0
- data/lib/qiita/team/services/events/item_comment_created.rb +17 -0
- data/lib/qiita/team/services/events/item_comment_destroyed.rb +17 -0
- data/lib/qiita/team/services/events/item_comment_updated.rb +17 -0
- data/lib/qiita/team/services/events/item_created.rb +10 -0
- data/lib/qiita/team/services/events/item_destroyed.rb +10 -0
- data/lib/qiita/team/services/events/item_updated.rb +10 -0
- data/lib/qiita/team/services/events/project_activated.rb +10 -0
- data/lib/qiita/team/services/events/project_archived.rb +10 -0
- data/lib/qiita/team/services/events/project_comment_created.rb +19 -0
- data/lib/qiita/team/services/events/project_comment_destroyed.rb +19 -0
- data/lib/qiita/team/services/events/project_comment_updated.rb +19 -0
- data/lib/qiita/team/services/events/project_created.rb +10 -0
- data/lib/qiita/team/services/events/project_destroyed.rb +10 -0
- data/lib/qiita/team/services/events/project_updated.rb +10 -0
- data/lib/qiita/team/services/events/team_member_added.rb +12 -0
- data/lib/qiita/team/services/events/team_member_removed.rb +12 -0
- data/lib/qiita/team/services/events.rb +28 -0
- data/lib/qiita/team/services/hooks/base.rb +45 -0
- data/lib/qiita/team/services/hooks/chatwork_v1.rb +149 -0
- data/lib/qiita/team/services/hooks/concerns/event_handlable.rb +49 -0
- data/lib/qiita/team/services/hooks/concerns/http_client.rb +74 -0
- data/lib/qiita/team/services/hooks/concerns/persistable.rb +64 -0
- data/lib/qiita/team/services/hooks/concerns/service.rb +31 -0
- data/lib/qiita/team/services/hooks/concerns/slack.rb +338 -0
- data/lib/qiita/team/services/hooks/hipchat_v1.rb +143 -0
- data/lib/qiita/team/services/hooks/slack_v1.rb +25 -0
- data/lib/qiita/team/services/hooks/slack_v2.rb +19 -0
- data/lib/qiita/team/services/hooks/webhook.rb +193 -0
- data/lib/qiita/team/services/hooks.rb +25 -0
- data/lib/qiita/team/services/properties/base.rb +20 -0
- data/lib/qiita/team/services/properties/boolean_property.rb +12 -0
- data/lib/qiita/team/services/properties/string_property.rb +12 -0
- data/lib/qiita/team/services/properties.rb +21 -0
- data/lib/qiita/team/services/resources/README.md +177 -0
- data/lib/qiita/team/services/templates/chatwork_v1.html.erb +25 -0
- data/lib/qiita/team/services/templates/hipchat_v1.html.erb +58 -0
- data/lib/qiita/team/services/templates/slack_v1.html.erb +54 -0
- data/lib/qiita/team/services/templates/slack_v2.html.erb +44 -0
- data/lib/qiita/team/services/templates/webhook.html.erb +25 -0
- data/lib/qiita/team/services/version.rb +3 -0
- data/lib/qiita_team_services.rb +34 -0
- data/qiita_team_services.gemspec +42 -0
- data/spec/hooks/chatwork_v1_spec.rb +118 -0
- data/spec/hooks/hipchat_v1_spec.rb +139 -0
- data/spec/hooks/slack_v1_spec.rb +55 -0
- data/spec/hooks/slack_v2_spec.rb +50 -0
- data/spec/hooks/webhook_spec.rb +465 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/factories/comments.rb +21 -0
- data/spec/support/factories/items.rb +26 -0
- data/spec/support/factories/projects.rb +17 -0
- data/spec/support/factories/taggings.rb +9 -0
- data/spec/support/factories/teams.rb +9 -0
- data/spec/support/factories/users.rb +11 -0
- data/spec/support/factory_girl.rb +13 -0
- data/spec/support/helpers/event_helper.rb +49 -0
- data/spec/support/helpers/hook_helper.rb +33 -0
- data/spec/support/helpers/http_client_stub_helper.rb +19 -0
- data/spec/support/helpers/slack_hook_helper.rb +104 -0
- data/spec/support/matchers/match_slack_attachments_request.rb +7 -0
- data/spec/support/resources/base.rb +23 -0
- data/spec/support/resources/comment.rb +29 -0
- data/spec/support/resources/item.rb +53 -0
- data/spec/support/resources/project.rb +45 -0
- data/spec/support/resources/tagging.rb +15 -0
- data/spec/support/resources/team.rb +11 -0
- data/spec/support/resources/user.rb +17 -0
- metadata +323 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eff3571bb39f81229904e638bcd2b00987d7af27
|
4
|
+
data.tar.gz: 62b45b4dcb79e9df19edd07a66fbc358607e4189
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06adb30900a3650d9a65fcf0b1d7b6e61186da6be672fe7bb32ffd73f06f69c94a10e8e3669fc73acda75ee5adbf85bcbf23fd5c560dc41f31c1c369c858c4c3
|
7
|
+
data.tar.gz: 91b0e24486011558bc6760d19c45233038eedcff97fcb83da95e3bcc76d34ec9996c6b96c586aba1454cb0b24d74943dfeac06e01dc4878868efb9a10d3c1797
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
.publish
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Style/StringLiterals:
|
2
|
+
EnforcedStyle: double_quotes
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 100
|
6
|
+
|
7
|
+
# Document classes and non-namespace modules.
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/ClassAndModuleChildren:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/ModuleLength:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 20
|
22
|
+
|
23
|
+
Metrics/AbcSize:
|
24
|
+
Max: 20
|
25
|
+
|
26
|
+
Style/TrailingComma:
|
27
|
+
EnforcedStyleForMultiline: comma
|
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.3
|
4
|
+
cache: bundler
|
5
|
+
script:
|
6
|
+
- bundle exec rake
|
7
|
+
- bundle exec rake deploy-gh-pages
|
8
|
+
env:
|
9
|
+
global:
|
10
|
+
- GH_REF: github.com/increments/qiita-team-services.git
|
11
|
+
- secure: czpqXrO5AZUbvDRLmVb8i8wbTwzGX07pa9t5yu/byGEyeKMNsSvXf+bTep6tuKTf84+Axn0jhSxqjzyZtY0Dpz4z5MzPB4E6TXsqYSXE/fUqFsszXvuOQiT653ryV1KuaA4nNVh/0r9udN26ijmgWhqXth7V0IhPDsegWm0bFfppPWu1+VE02L4t+mN1gER3hHheI8B8MTFkiYyuzcEM6YA4r8dG6h6ZG2aQX54Zv8+Sd+tOy30rD4bh97kxgCgmXudHoZQJCQoESeg0iPme5cGHXC5o13NO5iuUyWCB9FFHpc8eit+hUGwVGwI5HVVGi/kInN6JVMHbjaIWWhnCrK+1xkIotU4zIGfElyETa2NffuvtfZ/dHcga0DPlpQnwR4iZAFMIV7eqYjDXDZNY5+khugnuWPQeZsh7Qy30msmsodm9H8gKLny6CiRPBve1RkOqauVxaV30XbchfH7eL1ADnVeCJVfenXOw7WfAKvGmUMZ5O0SSbJnpiT7RgJlbfm/9JYPVKrDiAkfiFTomLGJv19ZM/jsqxsugI6s0rSpTArzst/Rz27wqkfg/LZ+Gfe44LYbvwPhAAXD/cDDz+LePYvbnzkqjPHrIpe1N8e7Z3urwStDkas+wz4pylWQnrZwBpi4MtU+WQeaMkemtUJGpnjEeaWnJ7i9A4eR5oew=
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Increments Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
# qiita-team-services
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/increments/qiita-team-services.svg?branch=master)](https://travis-ci.org/increments/qiita-team-services) [![Code Climate](https://codeclimate.com/github/increments/qiita-team-services/badges/gpa.svg)](https://codeclimate.com/github/increments/qiita-team-services)
|
4
|
+
|
5
|
+
Official Qiita:Team Services Integration
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "rubocop/rake_task"
|
4
|
+
require "yard"
|
5
|
+
|
6
|
+
YARD_DIR = ".publish"
|
7
|
+
|
8
|
+
RuboCop::RakeTask.new
|
9
|
+
RSpec::Core::RakeTask.new
|
10
|
+
YARD::Rake::YardocTask.new do |t|
|
11
|
+
t.options = ["--output-dir=#{YARD_DIR}"]
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: [:rubocop, :spec]
|
15
|
+
|
16
|
+
task "deploy-gh-pages" => :yard do
|
17
|
+
Dir.chdir YARD_DIR do
|
18
|
+
sh "git init"
|
19
|
+
sh "git config user.name qiitan"
|
20
|
+
sh "git config user.email info@qiita.com"
|
21
|
+
sh "git add ."
|
22
|
+
sh "git commit -m 'Deployed to GitHub pages'"
|
23
|
+
sh "git remote add origin \"https://${GH_TOKEN}@${GH_REF}\""
|
24
|
+
sh "git push -f -q origin master:gh-pages > /dev/null 2>&1"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
en:
|
2
|
+
qiita:
|
3
|
+
team:
|
4
|
+
services:
|
5
|
+
templates:
|
6
|
+
slack_v2:
|
7
|
+
icon_emoji_help_block_html:
|
8
|
+
Any Slack icons are available here (eg <code>:shipit:</code>). <br/>
|
9
|
+
Qiita:Team icon is used by default.
|
10
|
+
webhook_url_help_block_html:
|
11
|
+
You can add incoming webhooks integration to your slack channels at
|
12
|
+
<a href="https://slack.com/integrations" target="_blank">https://slack.com/integrations</a>.
|
13
|
+
hooks:
|
14
|
+
chatwork_v1:
|
15
|
+
room_id: Room ID
|
16
|
+
token: Token
|
17
|
+
hipchat_v1:
|
18
|
+
color: Color
|
19
|
+
from: From
|
20
|
+
room: Room
|
21
|
+
token: Token
|
22
|
+
with_notification: Notify
|
23
|
+
slack_v1:
|
24
|
+
icon_emoji: Icon emoji
|
25
|
+
integration_token: Integration token
|
26
|
+
teamname: Teamname
|
27
|
+
username: Username
|
28
|
+
slack_v2:
|
29
|
+
icon_emoji: Icon emoji
|
30
|
+
username: Username
|
31
|
+
webhook_url: Webhook URL
|
@@ -0,0 +1,32 @@
|
|
1
|
+
ja:
|
2
|
+
qiita:
|
3
|
+
team:
|
4
|
+
services:
|
5
|
+
templates:
|
6
|
+
slack_v2:
|
7
|
+
icon_emoji_help_block_html: |-
|
8
|
+
Slackに登録されている全てのアイコンが指定可能です(例 <code>:shipit:</code>)。<br/>
|
9
|
+
省略した場合、Qiita:Teamのアイコンが使われます。
|
10
|
+
webhook_url_help_block_html: |-
|
11
|
+
SlackチャンネルへのIncoming webhooks連携は
|
12
|
+
<a href="https://slack.com/integrations" target="_blank">https://slack.com/integrations</a>
|
13
|
+
で追加することができます。
|
14
|
+
hooks:
|
15
|
+
chatwork_v1:
|
16
|
+
room_id: ルームID
|
17
|
+
token: トークン
|
18
|
+
hipchat_v1:
|
19
|
+
color: 色
|
20
|
+
from: 送信元
|
21
|
+
room: ルーム
|
22
|
+
token: トークン
|
23
|
+
with_notification: 通知する
|
24
|
+
slack_v1:
|
25
|
+
icon_emoji: ユーザアイコン絵文字
|
26
|
+
integration_token: トークン
|
27
|
+
teamname: チーム名
|
28
|
+
username: ユーザ名
|
29
|
+
slack_v2:
|
30
|
+
icon_emoji: ユーザアイコン絵文字
|
31
|
+
username: ユーザ名
|
32
|
+
webhook_url: Webhook URL
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "active_support/inflector"
|
2
|
+
|
3
|
+
require "qiita/team/services/events"
|
4
|
+
|
5
|
+
module Qiita::Team::Services
|
6
|
+
module Events
|
7
|
+
# @abstract
|
8
|
+
class Base
|
9
|
+
class << self
|
10
|
+
# @return [Symbol]
|
11
|
+
def event_name
|
12
|
+
@event_name ||= name.demodulize.underscore.to_sym
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def inherited(child)
|
18
|
+
super
|
19
|
+
Events.event_names << child.event_name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param resource [Qiita::Team::Services::Resources::Base]
|
24
|
+
# @param user [Qiita::Team::Services::Resources::User]
|
25
|
+
def initialize(resource, user, team)
|
26
|
+
@resource = resource
|
27
|
+
@user = user
|
28
|
+
@team = team
|
29
|
+
end
|
30
|
+
|
31
|
+
# Created/updated resource object.
|
32
|
+
#
|
33
|
+
# @return [Qiita::Team::Services::Resources::Base]
|
34
|
+
attr_reader :resource
|
35
|
+
|
36
|
+
# User who emitted the event.
|
37
|
+
#
|
38
|
+
# @return [Qiita::Team::Services::Resources::User]
|
39
|
+
attr_reader :user
|
40
|
+
|
41
|
+
# A team which the resource belongs to.
|
42
|
+
#
|
43
|
+
# @return [Qiita::Team::Services::Resources::Team]
|
44
|
+
attr_reader :team
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
3
|
+
require "qiita/team/services/events/base"
|
4
|
+
|
5
|
+
module Qiita::Team::Services
|
6
|
+
module Events
|
7
|
+
class ItemCommentCreated < Base
|
8
|
+
# @return [Qiita::Team::Services::Resources::Comment]
|
9
|
+
alias_method :comment, :resource
|
10
|
+
|
11
|
+
# Commented item.
|
12
|
+
#
|
13
|
+
# @return [Qiita::Team::Services::Resources::Item]
|
14
|
+
delegate :item, to: :comment
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
3
|
+
require "qiita/team/services/events/base"
|
4
|
+
|
5
|
+
module Qiita::Team::Services
|
6
|
+
module Events
|
7
|
+
class ItemCommentDestroyed < Base
|
8
|
+
# @return [Qiita::Team::Services::Resources::Comment]
|
9
|
+
alias_method :comment, :resource
|
10
|
+
|
11
|
+
# Commented item.
|
12
|
+
#
|
13
|
+
# @return [Qiita::Team::Services::Resources::Item]
|
14
|
+
delegate :item, to: :comment
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
3
|
+
require "qiita/team/services/events/base"
|
4
|
+
|
5
|
+
module Qiita::Team::Services
|
6
|
+
module Events
|
7
|
+
class ItemCommentUpdated < Base
|
8
|
+
# @return [Qiita::Team::Services::Resources::Comment]
|
9
|
+
alias_method :comment, :resource
|
10
|
+
|
11
|
+
# Commented item.
|
12
|
+
#
|
13
|
+
# @return [Qiita::Team::Services::Resources::Item]
|
14
|
+
delegate :item, to: :comment
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
3
|
+
require "qiita/team/services/events/base"
|
4
|
+
|
5
|
+
module Qiita::Team::Services
|
6
|
+
module Events
|
7
|
+
class ProjectCommentCreated < Base
|
8
|
+
# @return [Qiita::Team::Services::Resources::Comment]
|
9
|
+
alias_method :comment, :resource
|
10
|
+
|
11
|
+
# Commented project.
|
12
|
+
#
|
13
|
+
# @return [Qiita::Team::Services::Resources::Project]
|
14
|
+
def project
|
15
|
+
comment.item
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
3
|
+
require "qiita/team/services/events/base"
|
4
|
+
|
5
|
+
module Qiita::Team::Services
|
6
|
+
module Events
|
7
|
+
class ProjectCommentDestroyed < Base
|
8
|
+
# @return [Qiita::Team::Services::Resources::Comment]
|
9
|
+
alias_method :comment, :resource
|
10
|
+
|
11
|
+
# Commented project.
|
12
|
+
#
|
13
|
+
# @return [Qiita::Team::Services::Resources::Project]
|
14
|
+
def project
|
15
|
+
comment.item
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
3
|
+
require "qiita/team/services/events/base"
|
4
|
+
|
5
|
+
module Qiita::Team::Services
|
6
|
+
module Events
|
7
|
+
class ProjectCommentUpdated < Base
|
8
|
+
# @return [Qiita::Team::Services::Resources::Comment]
|
9
|
+
alias_method :comment, :resource
|
10
|
+
|
11
|
+
# Commented project.
|
12
|
+
#
|
13
|
+
# @return [Qiita::Team::Services::Resources::Project]
|
14
|
+
def project
|
15
|
+
comment.item
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "qiita/team/services/events/base"
|
2
|
+
|
3
|
+
module Qiita::Team::Services
|
4
|
+
module Events
|
5
|
+
class TeamMemberRemoved < Base
|
6
|
+
# Removed team member.
|
7
|
+
#
|
8
|
+
# @return [Qiita::Team::Services::Resources::User]
|
9
|
+
alias_method :member, :resource
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Qiita::Team::Services
|
2
|
+
module Events
|
3
|
+
class << self
|
4
|
+
# List of defined event names.
|
5
|
+
#
|
6
|
+
# @return [Array<Symbol>]
|
7
|
+
def event_names
|
8
|
+
@event_names ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param event_name [Symbol]
|
12
|
+
# @param resource [Qiita::Team::Services::Resources::Base]
|
13
|
+
# @param user [Qiita::Team::Services::Resources::User]
|
14
|
+
# @param team [Qiita::Team::Services::Resources::Team]
|
15
|
+
# @return [Qiita::Team::Services::Events::Base]
|
16
|
+
def create(event_name, resource, user, team)
|
17
|
+
event_class(event_name).new(resource, user, team)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @param event_name [String]
|
23
|
+
def event_class(event_name)
|
24
|
+
"Qiita::Team::Services::Events::#{event_name.to_s.camelize}".constantize
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
require "active_model"
|
4
|
+
|
5
|
+
require "qiita/team/services/hooks"
|
6
|
+
require "qiita/team/services/hooks/concerns/event_handlable"
|
7
|
+
require "qiita/team/services/hooks/concerns/persistable"
|
8
|
+
require "qiita/team/services/hooks/concerns/service"
|
9
|
+
|
10
|
+
module Qiita::Team::Services
|
11
|
+
module Hooks
|
12
|
+
# @abstract
|
13
|
+
class Base
|
14
|
+
include ActiveModel::Validations
|
15
|
+
include Concerns::EventHandlable
|
16
|
+
include Concerns::Persistable
|
17
|
+
include Concerns::Service
|
18
|
+
|
19
|
+
class << self
|
20
|
+
# @param attr [String]
|
21
|
+
# @return [String]
|
22
|
+
def human_attribute_name(attr, _options = {})
|
23
|
+
I18n.t("qiita.team.services.hooks.#{hook_type}.#{attr}")
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [String]
|
27
|
+
def render_form(binding)
|
28
|
+
ERB.new(form_template).result(binding)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def inherited(child)
|
34
|
+
super
|
35
|
+
Hooks.all_hooks << child
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [String]
|
39
|
+
def form_template
|
40
|
+
File.read(File.expand_path("../../templates/#{hook_type}.html.erb", __FILE__))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|