Class: Lolcommits::Plugin::Slack
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::Slack
- Defined in:
- lib/lolcommits/plugin/slack.rb
Constant Summary collapse
- GET_UPLOAD_URL_ENDPOINT =
Slack API endpoints
'https://slack.com/api/files.getUploadURLExternal'.freeze
- COMPLETE_UPLOAD_ENDPOINT =
'https://slack.com/api/files.completeUploadExternal'.freeze
- RETRY_COUNT =
Number of times to retry if RestClient.post fails
2
Instance Method Summary collapse
-
#configure_options! ⇒ Hash
Prompts the user to configure integration with Slack.
-
#run_capture_ready ⇒ Object
Capture ready hook, runs after lolcommits captures a snapshot.
Instance Method Details
#configure_options! ⇒ Hash
Prompts the user to configure integration with Slack
Prompts user for a Slack access_token and a comma seperated
list of valid Slack channel IDs.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/lolcommits/plugin/slack.rb', line 50 def = super if [:enabled] print "Open the URL below to create a new Slack app (or view existing):\n" print "https://api.slack.com/apps?new_app=1\n" print "Ensure OAuth User Token Scopes includes files:write\n" print "Install the app to your Slack workspace\n" print "Paste the app's User OAuth Token below: (e.g. xxxx-xxxxxxxxx-xxxx)\n" code = parse_user_input(gets.strip) print "Enter a comma-seperated list of channel IDs to post into: (e.g. C0FPKDOJJ,C0APK3PPK)\n" print "Note: you must use channel IDs (not names). Right-click channel -> View Channel Details -> look for a Channel ID\n" channels = parse_user_input(gets.strip) .merge!( access_token: code, channels: channels ) end end |
#run_capture_ready ⇒ Object
Capture ready hook, runs after lolcommits captures a snapshot.
Uses RestClient to post the lolcommit to (one or more) Slack
channels using the new 3-step upload process. Each step will be
retried (RETRY_COUNT) times if any error occurs.
The post contains the git commit message, repo name and the SHA is used for the filename. The response from the final POST request is sent to the debug log.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lolcommits/plugin/slack.rb', line 28 def run_capture_ready print "Posting to Slack ... " upload_url, file_id = get_upload_url upload_file(upload_url) complete_upload(file_id) print "done!\n" rescue => e print "failed! #{e.message}\n" puts 'Try running config again:' puts "\tlolcommits --config -p slack" end |