oxidized icon indicating copy to clipboard operation
oxidized copied to clipboard

Update slackdiff.rb to use new slack file API

Open varesa opened this issue 1 year ago • 0 comments

Use new files.getUploadURLExternal API call to initiate the update instead of deprecated files.upload which is no longer available for newly created API tokens

Pre-Request Checklist

  • [x] Passes rubocop code analysis (try rubocop --auto-correct)
  • [ ] Tests added or adapted (try rake test)
  • [ ] Changes are reflected in the documentation
  • [x] User-visible changes appended to CHANGELOG.md

Description

The existing API method used for uploading diffs to slack is deprecated, and also not available for newly created API tokens: https://api.slack.com/methods/files.upload

files.upload is deprecated and will stop functioning on March 11, 2025. Use files.getUploadURLExternal and files.completeUploadExternal to upload files instead. Newly created apps will be unable to use files.upload beginning May 8, 2024. See Uploading files for more details on the process and this changelog for more on the deprecation.

The used 'slack_ruby_client' library implements the files_getUploadURLExternal and files_completeUploadExternal methods but as far as I can see, it does not include a method to actually upload the file. Replaced the deprecated call with these new functions and a simple HTTP POST to upload the actual bytes.

I am not sure if this upload functionality should be added to oxidized or slack_ruby_client. Or if it would be smarter to use something else than net/http (faraday?). Honestly, oxidized being my only exposure to the Ruby ecosystem, I'm trying to limit the area which I have to work with but I understand if this is not the approach the project wants to take.

The solution has been tested to work in practice:

I, [2024-09-13T17:09:22.953412 #397765]  INFO -- : Configuration updated for /fwtest.xxx.fi
I, [2024-09-13T17:09:22.953595 #397765]  INFO -- : SlackDiff: Connecting to slack
I, [2024-09-13T17:09:23.207599 #397765]  INFO -- : SlackDiff: Connected
I, [2024-09-13T17:09:23.230153 #397765]  INFO -- : SlackDiff: Posting diff as snippet to GM3HZPVTP
I, [2024-09-13T17:09:25.789587 #397765]  INFO -- : SlackDiff: Finished

screenshot_2024-09-13-171324

Closes issue #3189

varesa avatar Sep 13 '24 14:09 varesa