Slack Upload


Source link: https://github.com/brunodles/SlackUpload

SlackSender Plugin

A gradle plugin to send files to slack.

Sometime in your developer life, you will need to send files to slack. When this became a routine I wrote this plugin that does the work for me. With it we're able to create custom gradle tasks that sends some file.

This was built just to upload files, if you're looking for a plugin to send messages use this one, which is based on Java Slack-webhook.

How to use

App Token

First we need to generate a token for our app. Click on the buttom bellow to generate a token for you.

How to Install

To install this task is simple, it's released into Jitpack.

Go to your build.gradle and add the following, it can be on your root level or on app level:

buildscript {

  repositories {

maven {
 url "https://jitpack.io" 
}

  
}

  dependencies {

classpath 'com.github.brunodles:SlackUpload:-SNAPSHOT'
  
}
 
}

Create your upload task

You can create a new task to upload the file you want.

task <your task name>(type: com.brunodles.slackupload.UploadTask) {

  token "<your token>" // required, A token to identify who you are and where to send. To create the token look above. Don't need to be filled if you you use the `tokenFile`.
  tokenFile "<path to your tokenfile>" // fill with the path to your token file. Don't use when `token` is filled.
  file "<path to your file>" // fill with the path to the file you want to send. Don't fill this if `content` is filled
  content "<content>" // fill with any content, in this case the content will be converted into a Snippet. Don't fill this if `file` is filled.
  fileType "<type>" // optional
  filename "<file name>" // optional, will be used on download the file
  title "<title for this file>" // optional, will be shown on slack
  initial_comment "<first comment>" // optional, the description of the file
  channels "<channel name>" // required, can be a channel or a private group 
}

Samples

Just used to test the upload task.

task testSlack(type: com.brunodles.slackupload.UploadTask) {

  token "xoxp-11111111111-22222222222-33333333333-654asd645asd645sager654hge"
  file "build.gradle"
  channels "#general" 
}

I built this task for the project I'm working on.

task sendQARelease(type: com.github.brunodles.slacksender.UploadTask, dependsOn: 'assembleRelease') {

  description "Send the apk to QA Channel on Slack"
  group "build"
  token "xoxp-11111111111-22222222222-33333333333-654asd645asd645sager654hge"
  file "app/build/outputs/apk/app-release.apk"
  channels "QA"
  initial_comment "*pr-${
prNumber()
}
* - https://bitbucket.org/myteam/myproject/pull-requests/${
prNumber()
}
"
  fileType "apk"
  filename "app-release${
prNumber()
}
.apk"
  title getCurrentBranchCodeName() 
}

Did you noticed the getCurrentBranchCodeName? It's a custom method inside my gradle file, so you can call it inside the task setup.

Protect you token

As I said on the description, this task post as you, won't be cool everyone posting as you on the slack. So you can read the token from a file. To do that just replace the token value by a file read operation project.file("token").text. To do that use the tokenFile property to setup your task. Like this

task sendQARelease(type: com.github.brunodles.slacksender.UploadTask, dependsOn: 'assembleRelease') {

  ...
  tokenFile "token" 
}

Now add the file ( token) into your .gitignore.

Plugin and Multiple upload tasks

When you have multiple upload tasks you can create a plugin extension in your project and apply the slackUpload plugin in you app level gradle file. root/app/build.gradle

apply plugin: 'com.github.brunodles.SlackUpload' slackUpload {

  // choose one
  token "<your token>"
  tokenFile "<path to your tokenfile>" // <- this one is suggested 
}

Just need to add this before your tasks.

Contributing

Issues are welcome, create one and we will discourse about it. If you saw any error, please reports, it will be a great help.

Licence

You can use any code you found here, some of then I found on the internet too.

I'm using the MIT Licence, take a look on Licence.

If you're using this task, please give me some credits too.

Sources

Slack

Groovy

Gradle

JitPack

Resources

A simple util and example of how to track connectivity changes in Android applications.

A generic popover drawable for Android views.

Android Library to check if there is an Ad Blocker enabled and shows a customizable dialog.

Aftermath handles the consequences of your startActivityForResult calls.

Thirty different easing animation interpolators for Android.

Library that implements the floating action button to sheet transition from Google's Material Design documentation.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes