hitorigoto_reporter 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.dockerignore +5 -0
- data/.gitignore +53 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Dockerfile +32 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +13 -0
- data/hitorigoto_reporter.gemspec +27 -0
- data/lib/hitorigoto_reporter.rb +11 -0
- data/lib/hitorigoto_reporter/config.rb +49 -0
- data/lib/hitorigoto_reporter/formatter.rb +56 -0
- data/lib/hitorigoto_reporter/hitorigoto.rb +26 -0
- data/lib/hitorigoto_reporter/reporter.rb +43 -0
- data/lib/hitorigoto_reporter/version.rb +3 -0
- data/main.rb +14 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 894e97fd6a385bd309b4f57caf6598e6af1f7c63
|
4
|
+
data.tar.gz: b6bf5d8360a74d4fde12a20f5de9d5650bbf2de1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7655874a4cc432c00985367003c419d16afe368e6e3a44f70e4a84076931cfaf69eac7e851d2119fc3ea98f54697e0af65421616827250444459f6a2d8b2557d
|
7
|
+
data.tar.gz: 662b9649e699a6ef118b11aa5c4d74cc8ae1d62e7c94980224ab5b0d6a4a2d16308602568398f913948631f5185c487c7d66f24db7efc53a6de7e5c079ef6921
|
data/.dockerignore
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Created by https://www.gitignore.io/api/ruby
|
2
|
+
|
3
|
+
### Ruby ###
|
4
|
+
*.gem
|
5
|
+
*.rbc
|
6
|
+
/.config
|
7
|
+
/coverage/
|
8
|
+
/InstalledFiles
|
9
|
+
/pkg/
|
10
|
+
/spec/reports/
|
11
|
+
/spec/examples.txt
|
12
|
+
/test/tmp/
|
13
|
+
/test/version_tmp/
|
14
|
+
/tmp/
|
15
|
+
|
16
|
+
# Used by dotenv library to load environment variables.
|
17
|
+
# .env
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at masayuki@izumin.info. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Dockerfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
FROM ruby:2.3.1-alpine
|
2
|
+
|
3
|
+
MAINTAINER izumin5210 <masayuki@izumin.info>
|
4
|
+
|
5
|
+
ENV WORKDIR /app
|
6
|
+
RUN mkdir $WORKDIR
|
7
|
+
WORKDIR $WORKDIR
|
8
|
+
|
9
|
+
ARG run_at=0\t2\t*\t*\t*\t
|
10
|
+
|
11
|
+
RUN apk add --update --virtual build-dependencies \
|
12
|
+
g++ \
|
13
|
+
make \
|
14
|
+
&& apk add \
|
15
|
+
libstdc++ \
|
16
|
+
musl-dev \
|
17
|
+
openssl \
|
18
|
+
tzdata \
|
19
|
+
&& cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
|
20
|
+
&& printenv | sed 's/^\(.*\)$/export \1/g' | grep -e "GEM" -e "BUNDLE" >> /root/.profile \
|
21
|
+
&& echo -e "$run_at . /root/.profile; cd $(pwd); $(which ruby) main.rb" >> /var/spool/cron/crontabs/root
|
22
|
+
|
23
|
+
COPY Gemfile .
|
24
|
+
COPY Gemfile.lock .
|
25
|
+
|
26
|
+
RUN bundle install -j4 \
|
27
|
+
&& apk del build-dependencies \
|
28
|
+
&& rm -rf /var/cache/apk/*
|
29
|
+
|
30
|
+
COPY . .
|
31
|
+
|
32
|
+
CMD ["crond", "-l", "2", "-f"]
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hitorigoto_reporter (3.0.0)
|
5
|
+
esa (~> 1.5)
|
6
|
+
slack-api (~> 1.2.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
esa (1.7.0)
|
13
|
+
faraday (~> 0.9)
|
14
|
+
faraday_middleware
|
15
|
+
mime-types (~> 2.6)
|
16
|
+
multi_xml (~> 0.5.5)
|
17
|
+
eventmachine (1.2.0.1)
|
18
|
+
faraday (0.9.2)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
faraday_middleware (0.10.0)
|
21
|
+
faraday (>= 0.7.4, < 0.10)
|
22
|
+
faye-websocket (0.9.2)
|
23
|
+
eventmachine (>= 0.12.0)
|
24
|
+
websocket-driver (>= 0.5.1)
|
25
|
+
mime-types (2.99.3)
|
26
|
+
multi_json (1.12.1)
|
27
|
+
multi_xml (0.5.5)
|
28
|
+
multipart-post (2.0.0)
|
29
|
+
rake (10.5.0)
|
30
|
+
rspec (3.5.0)
|
31
|
+
rspec-core (~> 3.5.0)
|
32
|
+
rspec-expectations (~> 3.5.0)
|
33
|
+
rspec-mocks (~> 3.5.0)
|
34
|
+
rspec-core (3.5.4)
|
35
|
+
rspec-support (~> 3.5.0)
|
36
|
+
rspec-expectations (3.5.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.5.0)
|
39
|
+
rspec-mocks (3.5.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.5.0)
|
42
|
+
rspec-support (3.5.0)
|
43
|
+
slack-api (1.2.4)
|
44
|
+
faraday (>= 0.7, < 0.10)
|
45
|
+
faraday_middleware (~> 0.8)
|
46
|
+
faye-websocket (~> 0.9.2)
|
47
|
+
multi_json (~> 1.0, >= 1.0.3)
|
48
|
+
websocket-driver (0.6.4)
|
49
|
+
websocket-extensions (>= 0.1.0)
|
50
|
+
websocket-extensions (0.1.2)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
bundler (~> 1.12)
|
57
|
+
hitorigoto_reporter!
|
58
|
+
rake (~> 10.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.12.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 izumin5210
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Hitorigoto Reporter
|
2
|
+
Summarize slack posts into esa.io
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
Execute:
|
6
|
+
|
7
|
+
```
|
8
|
+
$ bundle install
|
9
|
+
```
|
10
|
+
|
11
|
+
And then run this app:
|
12
|
+
|
13
|
+
```
|
14
|
+
$ ruby main.rb
|
15
|
+
```
|
16
|
+
|
17
|
+
Or when you use docker:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ docker-compose up
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
## Configure
|
25
|
+
Add your configuration to enviromnent variables:
|
26
|
+
|
27
|
+
```
|
28
|
+
export SLACK_ACCESS_TOKEN="your-slack-access-token"
|
29
|
+
export SLACK_TARGET_CHANNELS="hitorigoto-syaro;hitorigoto-cocoa;hitorigoto-chino;hitorigoto-rize;hitorigoto-chiya"
|
30
|
+
export ESA_ACCESS_TOKEN="your-esa-access-token"
|
31
|
+
export ESA_CURRENT_TEAM="your-esa-team"
|
32
|
+
export ESA_REPORT_CATEGORY="日報/%Y/%m/%d"
|
33
|
+
```
|
34
|
+
|
35
|
+
## LICENSE
|
36
|
+
Licensed under [MIT License](https://izumin.mit-license.org/2016).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hitorigoto_reporter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
version: '2'
|
2
|
+
services:
|
3
|
+
reporter:
|
4
|
+
build:
|
5
|
+
context: .
|
6
|
+
args:
|
7
|
+
- run_at=0\t2\t*\t*\t*\t
|
8
|
+
environment:
|
9
|
+
- SLACK_ACCESS_TOKEN=$SLACK_ACCESS_TOKEN
|
10
|
+
- SLACK_TARGET_CHANNELS=$SLACK_TARGET_CHANNELS
|
11
|
+
- ESA_ACCESS_TOKEN=$ESA_ACCESS_TOKEN
|
12
|
+
- ESA_CURRENT_TEAM=$ESA_CURRENT_TEAM
|
13
|
+
- ESA_REPORT_CATEGORY=$ESA_REPORT_CATEGORY
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hitorigoto_reporter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hitorigoto_reporter"
|
8
|
+
spec.version = HitorigotoReporter::VERSION
|
9
|
+
spec.authors = ["izumin5210"]
|
10
|
+
spec.email = ["masayuki@izumin.info"]
|
11
|
+
|
12
|
+
spec.summary = %q{Summarize slack posts into esa.io}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/izumin5210/hitorigoto_reporter"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "esa", "~> 1.5"
|
23
|
+
spec.add_runtime_dependency "slack-api", "~> 1.2.1"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'uri'
|
3
|
+
require 'logger'
|
4
|
+
require 'slack'
|
5
|
+
require 'esa'
|
6
|
+
|
7
|
+
require 'hitorigoto_reporter/version'
|
8
|
+
require 'hitorigoto_reporter/reporter'
|
9
|
+
require 'hitorigoto_reporter/hitorigoto'
|
10
|
+
require 'hitorigoto_reporter/formatter'
|
11
|
+
require 'hitorigoto_reporter/config'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module HitorigotoReporter
|
2
|
+
def self.configure(&block)
|
3
|
+
@config = Config::Builder.new(&block).build
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configuration
|
7
|
+
@config ||= configure {}
|
8
|
+
end
|
9
|
+
|
10
|
+
class Config
|
11
|
+
attr_accessor :logger,
|
12
|
+
:slack_access_token, :slack_target_channels, :slack_target_channels_delimiter,
|
13
|
+
:esa_access_token, :esa_current_team, :esa_report_category, :esa_user
|
14
|
+
|
15
|
+
def self.configure(&block)
|
16
|
+
@config = Config::Builder.new(&block).build
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configuration
|
20
|
+
@config ||= configure {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@logger = Logger.new(STDOUT)
|
25
|
+
@slack_target_channels_delimiter = ";"
|
26
|
+
@esa_user = "esa_bot"
|
27
|
+
end
|
28
|
+
|
29
|
+
class Builder
|
30
|
+
def initialize(&block)
|
31
|
+
@config = Config.new
|
32
|
+
block.call(@config)
|
33
|
+
end
|
34
|
+
|
35
|
+
def build
|
36
|
+
configure_slack
|
37
|
+
@config
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def configure_slack
|
43
|
+
Slack.configure do |config|
|
44
|
+
config.token = @config.slack_access_token
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module HitorigotoReporter
|
2
|
+
class Formatter
|
3
|
+
def initialize(hitorigoto_list)
|
4
|
+
@hitorigoto_list = hitorigoto_list
|
5
|
+
end
|
6
|
+
|
7
|
+
def empty?
|
8
|
+
@hitorigoto_list.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_markdown
|
12
|
+
filtered_list, file_comments = filter_list_and_extract_comments
|
13
|
+
|
14
|
+
filtered_list
|
15
|
+
.reverse
|
16
|
+
.map { |h| "### #{h.username} at [#{h.created_at.strftime('%T')}](#{h.permalink})\n#{format_body(h.text, file_comments)}" }
|
17
|
+
.join("\n\n\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
def stamps
|
21
|
+
filtered_list, file_comments = filter_list_and_extract_comments
|
22
|
+
filtered_list.flat_map(&:stamps).uniq
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def filter_list_and_extract_comments
|
28
|
+
file_comments = Hash.new { |h, k| h[k] = [] }
|
29
|
+
|
30
|
+
filtered_list =
|
31
|
+
@hitorigoto_list.reject do |h|
|
32
|
+
pattern = /commented on \<.+\>'s file \<(?<url>.+)\|.+\>: (?<comment>.+)/
|
33
|
+
m = pattern.match(h.text)
|
34
|
+
unless m.nil?
|
35
|
+
file_comments[m[:url]] << "#{m[:comment]} by #{h.username} at [#{h.created_at.strftime('%T')}](#{h.permalink})"
|
36
|
+
end
|
37
|
+
!m.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
[filtered_list, file_comments]
|
41
|
+
end
|
42
|
+
|
43
|
+
def format_body(text, file_comments)
|
44
|
+
URI.extract(text, ["http", "https"]).inject(text) do |md, url|
|
45
|
+
pattern = /uploaded a file: \<(?<url>#{url})\|(?<title>.+)\>(:? and commented: ?(?<comment>.+)\n)?/
|
46
|
+
replaced = md.gsub(pattern, '\k<title>: \k<url>')
|
47
|
+
unless Regexp.last_match.nil?
|
48
|
+
comment = Regexp.last_match[:comment]
|
49
|
+
file_comments[url].unshift(comment) if !comment.nil? && !comment.empty? && !(/^\s*$/ =~ comment)
|
50
|
+
replaced += "\n\n" + file_comments[url].map { |c| "- #{c}" }.join("\n")
|
51
|
+
end
|
52
|
+
replaced
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module HitorigotoReporter
|
2
|
+
class Hitorigoto
|
3
|
+
attr_reader :username, :text, :permalink, :created_at, :stamps
|
4
|
+
|
5
|
+
def initialize(json, stamps = [])
|
6
|
+
@username = json['username']
|
7
|
+
@text = json['text']
|
8
|
+
@permalink = json['permalink']
|
9
|
+
@created_at = Time.at(json['ts'].to_f)
|
10
|
+
@stamps = stamps
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.fetch(channel_name, target_date)
|
14
|
+
date_query = target_date.strftime("%Y-%m-%d")
|
15
|
+
query = ["on:#{date_query}", "in:#{channel_name}"].join(' ')
|
16
|
+
res = Slack.client.search_messages(query: query)
|
17
|
+
res['messages']['matches']
|
18
|
+
.select { |m| m['type'] == 'message' }
|
19
|
+
.map { |m|
|
20
|
+
reaction = Slack.client.reactions_get(channel: m['channel']['id'], timestamp: m['ts'])
|
21
|
+
stamps = (reaction['message']['reactions'] || []).map { |r| r['name'] }
|
22
|
+
Hitorigoto.new(m, stamps)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module HitorigotoReporter
|
2
|
+
class Reporter
|
3
|
+
def report(date)
|
4
|
+
target_channels.each do |channel|
|
5
|
+
hitorigoto_list = Hitorigoto.fetch(channel, date)
|
6
|
+
formatter = Formatter.new(hitorigoto_list)
|
7
|
+
if formatter.empty?
|
8
|
+
logger.debug("#{channel} has no hitorigoto on #{date.strftime("%Y-%m-%d")}")
|
9
|
+
else
|
10
|
+
post_report(channel: channel, report: formatter.to_markdown, date: date, tags: formatter.stamps)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def post_report(channel:, report:, date:, wip: false, tags:)
|
18
|
+
category = report_category(date)
|
19
|
+
client.create_post(name: channel, body_md: report, category: category, wip: false, user: config.esa_user, tags: tags)
|
20
|
+
logger.debug("Posted #{category}/#{channel} to #{config.esa_current_team}.esa.io")
|
21
|
+
end
|
22
|
+
|
23
|
+
def config
|
24
|
+
HitorigotoReporter.configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def target_channels
|
28
|
+
config.slack_target_channels.split(config.slack_target_channels_delimiter)
|
29
|
+
end
|
30
|
+
|
31
|
+
def client
|
32
|
+
Esa::Client.new(access_token: config.esa_access_token, current_team: config.esa_current_team)
|
33
|
+
end
|
34
|
+
|
35
|
+
def report_category(date)
|
36
|
+
date.strftime(config.esa_report_category)
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger
|
40
|
+
config.logger
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/main.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require
|
3
|
+
|
4
|
+
require 'hitorigoto_reporter'
|
5
|
+
|
6
|
+
HitorigotoReporter.configure do |config|
|
7
|
+
config.slack_access_token = ENV['SLACK_ACCESS_TOKEN']
|
8
|
+
config.slack_target_channels = ENV['SLACK_TARGET_CHANNELS']
|
9
|
+
config.esa_access_token = ENV['ESA_ACCESS_TOKEN']
|
10
|
+
config.esa_current_team = ENV['ESA_CURRENT_TEAM']
|
11
|
+
config.esa_report_category = ENV['ESA_REPORT_CATEGORY']
|
12
|
+
end
|
13
|
+
|
14
|
+
HitorigotoReporter::Reporter.new.report(Date.today - 1)
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hitorigoto_reporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- izumin5210
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: esa
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: slack-api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Summarize slack posts into esa.io
|
84
|
+
email:
|
85
|
+
- masayuki@izumin.info
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".dockerignore"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Dockerfile
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- docker-compose.yml
|
104
|
+
- hitorigoto_reporter.gemspec
|
105
|
+
- lib/hitorigoto_reporter.rb
|
106
|
+
- lib/hitorigoto_reporter/config.rb
|
107
|
+
- lib/hitorigoto_reporter/formatter.rb
|
108
|
+
- lib/hitorigoto_reporter/hitorigoto.rb
|
109
|
+
- lib/hitorigoto_reporter/reporter.rb
|
110
|
+
- lib/hitorigoto_reporter/version.rb
|
111
|
+
- main.rb
|
112
|
+
homepage: https://github.com/izumin5210/hitorigoto_reporter
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.5.1
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Summarize slack posts into esa.io
|
136
|
+
test_files: []
|