Skip to content

Commit 326bd5c

Browse files
committed
Update events incrementally.
1 parent e1a2c4d commit 326bd5c

File tree

5 files changed

+73
-22
lines changed

5 files changed

+73
-22
lines changed

.rubocop_todo.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-09-21 13:03:00 UTC using RuboCop version 1.80.2.
3+
# on 2025-09-21 15:55:34 UTC using RuboCop version 1.80.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 4
9+
# Offense count: 5
1010
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1111
Metrics/AbcSize:
1212
Max: 49
@@ -27,7 +27,7 @@ Metrics/ClassLength:
2727
Metrics/CyclomaticComplexity:
2828
Max: 20
2929

30-
# Offense count: 5
30+
# Offense count: 6
3131
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
3232
Metrics/MethodLength:
3333
Max: 32
@@ -49,7 +49,7 @@ Security/Open:
4949
- 'tasks/lib/docs/events_downloader.rb'
5050
- 'tasks/lib/docs/methods_downloader.rb'
5151

52-
# Offense count: 4
52+
# Offense count: 5
5353
# Configuration parameters: AllowedConstants.
5454
Style/Documentation:
5555
Exclude:
@@ -58,9 +58,10 @@ Style/Documentation:
5858
- 'tasks/lib/docs/downloader.rb'
5959
- 'tasks/lib/docs/events_downloader.rb'
6060
- 'tasks/lib/docs/methods_downloader.rb'
61+
- 'tasks/lib/slack_api/events_generator.rb'
6162
- 'tasks/lib/slack_api/methods_generator.rb'
6263

63-
# Offense count: 6
64+
# Offense count: 7
6465
# This cop supports unsafe autocorrection (--autocorrect-all).
6566
# Configuration parameters: EnforcedStyle.
6667
# SupportedStyles: always, always_true, never
@@ -69,6 +70,7 @@ Style/FrozenStringLiteralComment:
6970
- '**/*.arb'
7071
- 'tasks/events.rake'
7172
- 'tasks/lib/docs/downloader.rb'
73+
- 'tasks/lib/slack_api/events_generator.rb'
7274
- 'tasks/lib/slack_api/methods_generator.rb'
7375
- 'tasks/methods.rake'
7476
- 'tasks/update.rake'

tasks/events.rake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require_relative 'lib/slack_api/events_generator'
12
require_relative 'lib/slack_api/spec_validator'
23

34
namespace :api do
@@ -11,5 +12,11 @@ namespace :api do
1112
abort "Invalid file format: #{file}" unless validator.valid?(file)
1213
end
1314
end
15+
16+
desc 'Update events.'
17+
task :update do
18+
# Rake::Task['api:clean_files'].invoke('events')
19+
SlackApi::EventsGenerator.new.generate!
20+
end
1421
end
1522
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module SlackApi
2+
class EventsGenerator
3+
def downloader
4+
@downloader ||= SlackApi::Docs::Downloader.new
5+
end
6+
7+
def generate!
8+
events = JSON.load_file(downloader.events_downloader.events_path)
9+
10+
events.each do |data|
11+
event_data = {
12+
'name' => data['name'],
13+
'desc' => "#{data['description']}.",
14+
'required_scope' => massage_scope(data['APIs'].first)
15+
}
16+
process_event(event_data)
17+
end
18+
19+
existing_events = Dir.glob('events/**/*.json').grep_v(%r{/_patches\b})
20+
updated_events = events.map { |event| "events/#{event['name']}.json" }
21+
(existing_events - updated_events).each do |removed_event|
22+
puts "(delete) #{removed_event}"
23+
File.delete(removed_event)
24+
end
25+
end
26+
27+
private
28+
29+
def massage_scope(scope)
30+
case scope
31+
when 'Events' then 'RTM'
32+
else scope
33+
end
34+
end
35+
36+
def process_event(data)
37+
filename = "events/#{data['name']}.json"
38+
puts filename
39+
existing_event_data = File.exist?(filename) ? JSON.load_file(filename) : {}
40+
all_data = existing_event_data.merge(data)
41+
File.write(filename, JSON.pretty_generate(all_data))
42+
end
43+
end
44+
end

tasks/methods.rake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require_relative 'lib/slack_api/methods_generator'
12
require_relative 'lib/slack_api/spec_validator'
23

34
namespace :api do
@@ -12,4 +13,11 @@ namespace :api do
1213
end
1314
end
1415
end
16+
17+
desc 'Update methods and events.'
18+
task :update do
19+
Rake::Task['api:clean_files'].invoke('methods')
20+
Rake::Task['api:clean_files'].invoke('groups')
21+
SlackApi::MethodsGenerator.new.generate!
22+
end
1523
end

tasks/update.rake

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
require_relative 'lib/slack_api/methods_generator'
2-
31
namespace :api do
4-
namespace :methods do
5-
desc 'Update methods.'
6-
task :update do
7-
Rake::Task['api:methods:clean_files'].invoke('methods')
8-
Rake::Task['api:methods:clean_files'].invoke('groups')
9-
SlackApi::MethodsGenerator.new.generate!
10-
end
11-
12-
desc 'Delete all generated files except undocumented ones.'
13-
task :clean_files, :dirs do |_t, args|
14-
raise 'Missing :dirs' unless args[:dirs]
2+
desc 'Delete all generated files except undocumented ones.'
3+
task :clean_files, :dirs do |_t, args|
4+
raise 'Missing :dirs' unless args[:dirs]
155

16-
# keep _undocumented and _patches
17-
files = Dir["./{#{Array(args[:dirs]).join(',')}}/*"].grep_v(%r{/_\w*\b})
18-
FileUtils.rm_rf files
19-
end
6+
# keep _undocumented and _patches
7+
files = Dir["./{#{Array(args[:dirs]).join(',')}}/*"].grep_v(%r{/_\w*\b})
8+
FileUtils.rm_rf files
209
end
2110

2211
task :update do
2312
Rake::Task['api:methods:update'].invoke
13+
Rake::Task['api:events:update'].invoke
2414
end
2515
end

0 commit comments

Comments
 (0)