This is a CLI tool to submit files to both Gist and Slack.
When I discuss about developing scripts, I often use Slack. When I submitted a script to Slack, I had saved the script to Gist as a backup. I had done manually this on my browser. Namely, I wanted to be saving the revision of script while I'm discussing about the script at Slack. Recently, I wished this process had been able to be automatically run. So I created this tool.
By this, the local environment for developing Google Apps Script (GAS) became more convenient.
-
Submits files to both Gist and Slack, simultaneously.
-
Submits, gets, updates and deletes files for Gist.
-
Submits, gets and deletes files for Slack.
-
Retrieves access token from client ID and client secret for Gist and Slack.
This is a demonstration for submitting a GAS written by CoffeeScript to both Gist and Slack using Sublime Text. You can confirm that the revision of script uploaded to gist increases. The Google Apps Script is run by ggsrun.
Download an executable file of gislack from the release page and import to a directory with path.
or
Use go get.
$ go get -u github.com/tanaikech/gislack
If you want to compile this on your PC, please also get a library https://github.com/tanaikech/getcode.
If you want to use gislack on Sublime Text 3, you can download the plugin for Sublime Text 3 from https://github.com/tanaikech/gislacks You can see how to install there.
By using plugin for Sublime Text, you can use gislack as shown at the above demo.
In order to use gislack, at first, please retrieve client ID and client secret from GitHub and Slack.
- Login to GitHub.
- Open Developer applications page. https://github.com/settings/developers
- Click Register new application button.
- Input Application name, Homepage URL, Application description, Authorization callback URL. Authorization callback URL is
http://localhost:8080
. - After inputted the information, click register application.
- Copy Client ID and Client Secret.
- Login to Slack.
- Open Your Apps page. https://api.slack.com/apps
- Click Create New App button.
- Input App Name and Development Slack Team.
- After inputted the information, click Create App.
- Click OAuth & Permissions at left side or Permissions at Add features and functionality.
- Click Add a new Redirect URL.
- Input
http://localhost:8080
as a new Redirect URL. - Click Save URLs
- Click Basic Information at left side.
- Copy Client ID and Client Secret at App Credentials. When you see Client Secret, click the show button.
If you want to submit your scripts developing on Sublime Text to Gist and Slack, you can use plugin for Sublime Text. Please check https://github.com/tanaikech/gislacks.
If you have already had client ID and client secret for both, you can submit your script using Sublime Text soon.
Following explanations are for terminal base. In order to prevent miss for using shortcuts, the delete commands cannot be used at Sublime Text.
In order to use Gist and Slack, at first, please retrieve access token as following flow.
- Launch your terminal.
- Run following code. Please run following commands for GitHub and Slack.
For GitHub
$ gislack auth -gi [client ID of GitHub] -gs [client secret of Github]
For Slack
$ gislack auth -si [client ID of Slack] -ss [client secret of Slack]
Following flow is the same to GitHub and Slack.
- When above is run, your browser is launched and waits for login to GitHub (or Slack).
- Please login to GitHub (or Slack).
- It opens authorization page. If the authorization button appears, please authorize it. If the button cannot be seen, a page with authorization code is opened.
- The authorization code can be retrieved automatically. And
Done
. is displayed on your terminal.- If your browser isn't launched or spends for 30 seconds from the wait of authorization, it becomes the input work queue. This is a manual mode. Please copy displayed URL and paste it to your browser, and login to GitHub (or Slack). A code is displayed on the browser. Please copy it and paste it to your terminal during the input work queue. If you cannot find the code on your browser, please check the URL of your browser.
- When
Done
is displayed on your terminal, the authorization is completed andgislack.cfg
is created on a directory you currently stay. (If you setcfgdirectory
as an option,gislack.cfg
is created to the directory set bycfgdirectory
.) - The priority of directory for
gislack.cfg
is as follows.- Option
--cfgdirectory=#####
or-cfgdir #####
. - Environment variable :
GISLACK_CFG_PATH
(For example, you can write this for.bashrc
asexport GISLACK_CFG_PATH=#####
.) - Current working directory.
- Option
Retrieved access tokens from GitHub and Slack have no limitation time. So the authorization process is only one time.
Congratulation! Here, the preparation for using gislack was completed.
Following command submits both Gist and Slack, simultaneously
$ gislack d -f [file] \
-fn [filename] \
-t [title] \
-p \
-ft [file type for Slack(e.g. javascript)] \
-ch [channel for Slack(e.g. general)] \
-ic [initial comment for Slack]
-f
: A file for submitting.-fn
: File name on Gist. If this is not used, it's no problem. If this is not used, the file name is used as the file name of submitted file.-t
: Title on Gist and Slack.-p
: This is a boolean. If you want to submit as a public for Gist, please use this. If you use-p
, the file is submitted as a secret.-ft
: File type for submitting. (e.g. javascript) If you don't use this, the file type is decided from the submitted file. If the extension is.js
, it judges as Javascript. If this is not used, it's no problem.-ch
: Channel name for Slack. (e.g. general) You are not necessary to use "#" for channel name.-ic
: You can give initial comment using this. If this is not used, it's no problem.
When you want to use this command, at first, please run above "New Submission for Slack and Gist" and retrieve Gist ID. At the plugin of Sublime Text, these are automatically run.
$ gislack d -uo or -ua [Gist ID]
-f [file] \
-fn [filename] \
-t [title] \
-p \
-ft [file type for Slack(e.g. javascript)] \
-ch [channel for Slack(e.g. general)] \
-ic [initial comment for Slack]
-uo
: Updated by overwriting a file. In this case, you can see the history of a file. This is the same to above demo.-ua
: Updated by adding a file. In this case, you can see increasing files.
$ gislack g -f [files] -t [title] -fn [filename] -p
--anonymous
: If you want to submit asAnonymous
, please use this option.-f
: You can submit several files as a gist. For example,$ gislack g -f file1.js,file2.js,file3.html -t sample -fn sample1.js,sample2.js,sample3.html -p
- At above sample, when options
-f
and-fn
has the same number of file name, file1.js, file2.js and file3.html are used sample1.js, sample2.js and sample3.html as file name, respectively.
When file is submitted as Anonymous, it cannot be deleted. So please be careful.
The detail explanation of options are as shown here.
$ gislack g -uo [Gist ID] f [file] -t [title] -fn [filename] -p
The detail explanation of options are as shown here.
$ gislack g -ua [Gist ID] f [file] -t [title] -fn [filename] -p
The detail explanation of options are as shown here.
$ gislack g -l
-l
: Get gist list.
$ gislack g -g [Gist ID]
-l
: Get gist. This is for retrieving the latest gist from gist ID.
$ gislack g -gh [Gist ID]
-gv
: Get gist's history. This is for retrieving a version list.
$ gislack g -gv [URL for a version]
-gv
: Get gist's version. This is for retrieving file at the version from the history. The value of[URL for a version]
can be retrieved by the option-gv
. When this is used, at first, please run "Get Gist's History" and retrieve "URL for a version".
$ gislack g -d [Gist ID]
-dv
: Delete a gist of gist ID.
$ gislack g --deleteall
--deleteall
: Delete all gists from your account. When this is used, gislack shows a message for confirming this. When you put "y", this is run.
When you use this option, please be careful.
Following command is for submitting a file.
$ gislack s -f [file] -ti [title] -ch [channel] -ft [file type] -ic [initial comment]
Following command is for submitting data directly inputted strings to the command.
$ gislack s -co [strings] -ti [title] -ch [channel] -ft [file type] -ic [initial comment]
-co
: You can input directly strings to command line using this option.
The detail explanation of options are as shown here.
$ gislack s -fl
-fl
: Get file list on Slack Team you registered.
$ gislack s -gf [File ID]
-gf
: Get a file using file ID. The file ID can be retrieved using "Get File List".
$ gislack s -df [File ID]
-df
: Delete a file. The file ID can be retrieved from "Get File". If you are not owner of the team, you can delete only a file that you submitted.
$ gislack s -dfs
-dfs
: Delete all files. If you are owner, by this command, all files are deleted.
When you use this, please be careful.
$ gislack s -hi -ch [Channel name]
-gf
: Get channel history.
$ gislack s -dh [History ID] -ch [Channel name]
-dh
: Delete a history. The history ID can be retrieved from "Get Channel History". If you are not owner of the team, you can delete only a file that you submitted.
$ gislack s -dhs [Number of histories you want to delete. Max is 50.] -ch [Channel name]
-dhs
: Delete all histories. But the MAX is 50. If the channel has a lot of histories over 50, please use this command repeatedly, because of the limitation for using APIs. If you are owner, by this command, all histories are deleted.
When you use this, please be careful.
- Gist API document https://developer.github.com/v3/gists/
- Slack API document https://api.slack.com/methods
gislack can be controlled by JSON data. Using this, gislack may be used except for Sublime Text. The parameters for JSON can be seen at useJSON()
in handler.go
on https://github.com/tanaikech/gislack.
-
v1.0.0 (June 22, 2017)
Initial release.
-
v1.0.1 (June 30, 2017)
Some modifications related to error handling.
-
v1.0.2 (June 30, 2017)
Some modifications related to displaying results.
-
v1.0.3 (January 3, 2020)
- It seems that the specification of
github.com/urfave/cli
was changed by the update of https://github.com/urfave/cli. By this, whengo get -u github.com/tanaikech/gislack
is run, an error occurred. So this error was removed.
- It seems that the specification of
-
v1.0.4 (February 27, 2021)
-
I noticed that this application uses the duplicated methods of Slack API. Ref By this, the duplicated methods were updated to the new methods as follows.
- From "channels.list" to "conversations.list".
- From "channels.history" to "conversations.history".
-