Skip to content

Commit

Permalink
fix: resolve deprecated Slack files.upload
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Feb 13, 2025
1 parent 8cee844 commit 406d612
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tf-managed/modules/sync-check/service/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
source 'https://rubygems.org'

gem 'docker-api', '>= 2.2.0'
gem 'slack-ruby-client', '>= 2.1.0'
gem 'slack-ruby-client', '>= 2.5.1'
gem 'sys-filesystem', '>=1.4.3'
43 changes: 26 additions & 17 deletions tf-managed/modules/sync-check/service/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
GEM
remote: https://rubygems.org/
specs:
docker-api (2.2.0)
excon (>= 0.47.0)
docker-api (2.4.0)
excon (>= 0.64.0)
multi_json
excon (0.99.0)
faraday (2.7.4)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
excon (1.2.3)
faraday (2.12.2)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-mashify (0.1.1)
faraday (~> 2.0)
hashie
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (3.0.2)
ffi (1.15.5)
gli (2.21.0)
faraday-multipart (1.1.0)
multipart-post (~> 2.0)
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
ffi (1.17.1-x86_64-linux-gnu)
gli (2.22.2)
ostruct
hashie (5.0.0)
json (2.10.1)
logger (1.6.6)
multi_json (1.15.0)
multipart-post (2.3.0)
ruby2_keywords (0.0.5)
slack-ruby-client (2.1.0)
multipart-post (2.4.1)
net-http (0.6.0)
uri
ostruct (0.6.1)
slack-ruby-client (2.5.1)
faraday (>= 2.0)
faraday-mashify
faraday-multipart
gli
hashie
sys-filesystem (1.4.3)
logger
sys-filesystem (1.5.3)
ffi (~> 1.1)
uri (1.0.2)

PLATFORMS
x86_64-linux

DEPENDENCIES
docker-api (>= 2.2.0)
slack-ruby-client (>= 2.1.0)
slack-ruby-client (>= 2.5.1)
sys-filesystem (>= 1.4.3)

BUNDLED WITH
2.3.4
2.5.22
9 changes: 6 additions & 3 deletions tf-managed/scripts/ruby_common/slack_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
class SlackClient
@last_thread = nil
@channel = nil
# Some APIs require the `channel_id` instead of the channel name.
@channel_id = nil
@client = nil

def initialize(channel, token)
Expand All @@ -24,6 +26,7 @@ def initialize(channel, token)
def post_message(text)
msg = @client.chat_postMessage(channel: @channel, text: text)
@last_thread = msg[:ts]
@channel_id = msg[:channel]
end

# Attaches a comment/reply to the latest posted thread.
Expand All @@ -45,10 +48,10 @@ def attach_file(file)
return unless File.exist? file
raise 'Need to create a thread before attaching a file.' if @last_thread.nil?

@client.files_upload(
channels: @channel,
file: Faraday::UploadIO.new(file, 'text/plain'),
@client.files_upload_v2(
filename: File.basename(file),
content: File.read(file),
channel_id: @channel_id,
initial_comment: 'Attached a file.',
thread_ts: @last_thread
)
Expand Down

0 comments on commit 406d612

Please sign in to comment.