roko 0.2.0

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.
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'client'
4
+ require_relative 'event_adapter'
5
+ require 'roko/source/base/report_events'
6
+
7
+ module Roko
8
+ module Source
9
+ module GoogleCalendar
10
+ # report events from google calendar
11
+ class ReportEvents < Roko::Source::Base::ReportEvents
12
+ def client
13
+ Client.new_client
14
+ end
15
+
16
+ def fetch_service_event(client)
17
+ client
18
+ .list_events(
19
+ 'primary',
20
+ time_min: DateTime.parse(@start.to_s).rfc3339,
21
+ time_max: DateTime.parse(@end.to_s).rfc3339
22
+ )
23
+ .items
24
+ end
25
+
26
+ def to_report_event(event)
27
+ EventAdapter.to_report_event(event)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'roko/report_event'
4
+ require 'time'
5
+
6
+ module Roko
7
+ module Source
8
+ module Jira
9
+ # event adapter from jira to report event
10
+ module EventAdapter
11
+ class << self
12
+ # @param event [JIRA::Resource::Issue]
13
+ # @return [Roko::ReportEvent]
14
+ def to_report_event(event)
15
+ source = 'jira'
16
+ event_type = 'ticket'
17
+
18
+ key = event.attrs['key']
19
+ url = "#{ENV['JIRA_URL']}#{ENV['JIRA_CONTEXT_PATH']}/browse/#{key}"
20
+
21
+ fields = event.attrs['fields']
22
+
23
+ created_at = Time.parse(fields['updated'])
24
+
25
+ summary = "[#{key}] #{fields['summary']}"
26
+ detail = fields['description']
27
+ Roko::ReportEvent.new(source, event_type, created_at, url, summary, detail)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jira-ruby'
4
+ require 'roko/source/base/report_events'
5
+
6
+ require_relative 'event_adapter'
7
+
8
+ module Roko
9
+ module Source
10
+ module Jira
11
+ # report events from Jira
12
+ class ReportEvents < Roko::Source::Base::ReportEvents
13
+ def client
14
+ options = {
15
+ username: ENV['JIRA_USER'],
16
+ password: ENV['JIRA_PASSWORD'],
17
+ site: ENV['JIRA_URL'],
18
+ context_path: ENV['JIRA_CONTEXT_PATH'],
19
+ auth_type: :basic,
20
+ rest_base_path: '/rest/api/2'
21
+ }
22
+ JIRA::Client.new(options)
23
+ end
24
+
25
+ # @param client [JIRA::Client]
26
+ def fetch_service_event(client)
27
+ jql = jql_status_changed_between(@start, @end)
28
+ client.Issue.jql(jql)
29
+ end
30
+
31
+ # @param start_time [Time]
32
+ # @param end_time [Time]
33
+ def jql_status_changed_between(start_time, end_time)
34
+ start_date = start_time.strftime('%Y/%m/%d')
35
+ end_date = end_time.strftime('%Y/%m/%d')
36
+ 'status changed by currentUser()' \
37
+ " AND updatedDate >= \"#{start_date}\"" \
38
+ " AND updatedDate < \"#{end_date}\""
39
+ end
40
+
41
+ # @param event [JIRA::Resource::Issue]
42
+ def to_report_event(event)
43
+ EventAdapter.to_report_event(event)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'roko/report_event'
4
+ require 'time'
5
+
6
+ module Roko
7
+ module Source
8
+ module Slack
9
+ # event adapter from slack to report event
10
+ module EventAdapter
11
+ MAX_SUMMARY_TEXT_LENGTH = 20
12
+ class << self
13
+ # @param event [Slack::Messages::Message]
14
+ # @return [Roko::ReportEvent]
15
+ def to_report_event(event)
16
+ source = 'slack'
17
+ event_type = 'comment'
18
+
19
+ created_at = Time.at(event.ts.to_i)
20
+
21
+ url = event.permalink
22
+ text = event.text
23
+
24
+ summary_text = summarize(text)
25
+
26
+ summary = "in ##{event.channel.name} \"#{summary_text}\""
27
+ detail = text
28
+ Roko::ReportEvent.new(source, event_type, created_at, url, summary, detail)
29
+ end
30
+
31
+ private
32
+
33
+ def summarize(text)
34
+ if text.length > MAX_SUMMARY_TEXT_LENGTH
35
+ text[0, MAX_SUMMARY_TEXT_LENGTH] + '...'
36
+ else
37
+ text
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Roko
4
+ module Source
5
+ module Slack
6
+ # access slack events
7
+ #
8
+ # @!attribute [Slack::Web::Client] client
9
+ class Events
10
+ DEFAULT_MESSAGE_COUNT_PER_PAGE = 100
11
+
12
+ # @param client [Faraday::Connection]
13
+ def initialize(client)
14
+ @client = client
15
+ end
16
+
17
+ # @param start_date [String]
18
+ # @param end_date [String]
19
+ def fetch(start_date, end_date)
20
+ user = my_user
21
+ after = Date.parse(start_date).prev_day.to_s
22
+ before = Date.parse(end_date).to_s
23
+ query = "from:@#{user} after:#{after} before:#{before}"
24
+ search_all_messages(query)
25
+ end
26
+
27
+ private
28
+
29
+ def my_user
30
+ @client.auth_test.user
31
+ end
32
+
33
+ # @param query [String] search query
34
+ def search_all_messages(query)
35
+ first_page = search_messages_per_page(query, 1)
36
+ total_page_count = first_page.pagination.page_count
37
+
38
+ return first_page.matches if total_page_count == 1
39
+
40
+ all_messages = first_page.matches
41
+ (2..total_page_count).each do |page_index|
42
+ page = search_messages_per_page(query, page_index)
43
+ all_messages.concat page.matches
44
+ end
45
+ all_messages
46
+ end
47
+
48
+ # @param query [String] search query
49
+ # @param page [Int] page
50
+ # @see https://api.slack.com/methods/search.messages
51
+ # @see https://github.com/slack-ruby/slack-ruby-client/blob/master/lib/slack/web/api/endpoints/search.rb
52
+ def search_messages_per_page(query, page)
53
+ @client
54
+ .search_messages({
55
+ query: query,
56
+ page: page,
57
+ count: DEFAULT_MESSAGE_COUNT_PER_PAGE,
58
+ sort: 'timestamp'
59
+ })
60
+ .messages
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'slack-ruby-client'
4
+
5
+ require_relative 'events'
6
+ require_relative 'event_adapter'
7
+ require 'roko/source/base/report_events'
8
+
9
+ # alias for Slack module defined in slack-ruby-client
10
+ SlackClient = Slack
11
+
12
+ module Roko
13
+ module Source
14
+ module Slack
15
+ # report events from slack
16
+ class ReportEvents < Roko::Source::Base::ReportEvents
17
+ def client
18
+ SlackClient.configure do |config|
19
+ config.token = ENV['SLACK_API_TOKEN']
20
+ end
21
+ SlackClient::Web::Client.new
22
+ end
23
+
24
+ def fetch_service_event(client)
25
+ Events.new(client).fetch(@start.to_s, @end.to_s)
26
+ end
27
+
28
+ def to_report_event(event)
29
+ EventAdapter.to_report_event(event)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Roko
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/roko/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'roko'
7
+ spec.version = Roko::VERSION
8
+ spec.authors = ['miyado']
9
+ spec.email = ['hmiyado@gmail.com']
10
+
11
+ spec.summary = 'generate daily activity.'
12
+ spec.description = 'generate daily activity report such as github, slack, jira, confluence'
13
+ spec.homepage = 'https://github.com/hmiyado/roko'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roko
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - miyado
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: generate daily activity report such as github, slack, jira, confluence
14
+ email:
15
+ - hmiyado@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".reek.yml"
22
+ - ".rspec"
23
+ - ".solargraph.yml"
24
+ - ".travis.yml"
25
+ - ".vscode/settings.json"
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - README.md
29
+ - bin/console
30
+ - bin/roko
31
+ - bin/setup
32
+ - lib/roko.rb
33
+ - lib/roko/cli.rb
34
+ - lib/roko/report_event.rb
35
+ - lib/roko/source/base/report_events.rb
36
+ - lib/roko/source/configurable.rb
37
+ - lib/roko/source/confluence/event_adapter.rb
38
+ - lib/roko/source/confluence/events.rb
39
+ - lib/roko/source/confluence/report_events.rb
40
+ - lib/roko/source/events.rb
41
+ - lib/roko/source/github/event_adapter.rb
42
+ - lib/roko/source/github/report_events.rb
43
+ - lib/roko/source/google_calendar/client.rb
44
+ - lib/roko/source/google_calendar/event_adapter.rb
45
+ - lib/roko/source/google_calendar/report_events.rb
46
+ - lib/roko/source/jira/event_adapter.rb
47
+ - lib/roko/source/jira/report_events.rb
48
+ - lib/roko/source/slack/event_adapter.rb
49
+ - lib/roko/source/slack/events.rb
50
+ - lib/roko/source/slack/report_events.rb
51
+ - lib/roko/version.rb
52
+ - roko.gemspec
53
+ homepage: https://github.com/hmiyado/roko
54
+ licenses: []
55
+ metadata:
56
+ homepage_uri: https://github.com/hmiyado/roko
57
+ source_code_uri: https://github.com/hmiyado/roko
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.3.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.1.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: generate daily activity.
77
+ test_files: []