gislack

command module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2021 License: MIT Imports: 23 Imported by: 0

README

gislack

Build Status MIT License

Overview

This is a CLI tool to submit files to both Gist and Slack.

Description

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.

Features of "gislack" are as follows.

  1. Submits files to both Gist and Slack, simultaneously.

  2. Submits, gets, updates and deletes files for Gist.

  3. Submits, gets and deletes files for Slack.

  4. Retrieves access token from client ID and client secret for Gist and Slack.

Demo

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.

How to Install

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.

Plugin for Sublime Text

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.

Retrieve Client ID and Client Secret

In order to use gislack, at first, please retrieve client ID and client secret from GitHub and Slack.

1. Gist (GitHub)

  1. Login to GitHub.
  2. Open Developer applications page. https://github.com/settings/developers
  3. Click Register new application button.
  4. Input Application name, Homepage URL, Application description, Authorization callback URL. Authorization callback URL is http://localhost:8080.
  5. After inputted the information, click register application.
  6. Copy Client ID and Client Secret.

2. Slack

  1. Login to Slack.
  2. Open Your Apps page. https://api.slack.com/apps
  3. Click Create New App button.
  4. Input App Name and Development Slack Team.
  5. After inputted the information, click Create App.
  6. Click OAuth & Permissions at left side or Permissions at Add features and functionality.
  7. Click Add a new Redirect URL.
  8. Input http://localhost:8080 as a new Redirect URL.
  9. Click Save URLs
  10. Click Basic Information at left side.
  11. Copy Client ID and Client Secret at App Credentials. When you see Client Secret, click the show button.

Plugin for Sublime Text?

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.


Usage

Following explanations are for terminal base. In order to prevent miss for using shortcuts, the delete commands cannot be used at Sublime Text.

Authorization

In order to use Gist and Slack, at first, please retrieve access token as following flow.

  1. Launch your terminal.
  2. 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 and gislack.cfg is created on a directory you currently stay. (If you set cfgdirectory as an option, gislack.cfg is created to the directory set by cfgdirectory.)
  • The priority of directory for gislack.cfg is as follows.
    1. Option --cfgdirectory=##### or -cfgdir #####.
    2. Environment variable : GISLACK_CFG_PATH (For example, you can write this for .bashrc as export GISLACK_CFG_PATH=#####.)
    3. Current working directory.

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.

Double Submission

New Submission for Slack and Gist

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.
New Submission for Slack and Submission with Revision for Gist

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.

For Gist

1. Submit to Gist
$ gislack g -f [files] -t [title] -fn [filename] -p
  • --anonymous : If you want to submit as Anonymous, 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.

2. Update Gist as Overwriting
$ gislack g -uo [Gist ID] f [file] -t [title] -fn [filename] -p

The detail explanation of options are as shown here.

3. Update Gist as Adding
$ gislack g -ua [Gist ID] f [file] -t [title] -fn [filename] -p

The detail explanation of options are as shown here.

4. Get Gist List
$ gislack g -l
  • -l : Get gist list.
5. Get Gist
$ gislack g -g [Gist ID]
  • -l : Get gist. This is for retrieving the latest gist from gist ID.
6. Get Gist's History
$ gislack g -gh [Gist ID]
  • -gv : Get gist's history. This is for retrieving a version list.
7. Get Gist's Version
$ 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".
8. Delete Gist
$ gislack g -d [Gist ID]
  • -dv : Delete a gist of gist ID.
9. Delete All Gists
$ 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.

For Slack

1. Submit to Slack

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.

2. Get File List
$ gislack s -fl
  • -fl : Get file list on Slack Team you registered.
3. Get File
$ gislack s -gf [File ID]
  • -gf : Get a file using file ID. The file ID can be retrieved using "Get File List".
4. Delete File
$ 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.
5. Delete All files
$ 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.

6. Get Channel History
$ gislack s -hi -ch [Channel name]
  • -gf : Get channel history.
7. Delete 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.
8. Delete All Histories
$ 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.

References

APIs

Controlling gislack by JSON

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.

Update History

  • 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)

    1. It seems that the specification of github.com/urfave/cli was changed by the update of https://github.com/urfave/cli. By this, when go get -u github.com/tanaikech/gislack is run, an error occurred. So this error was removed.

  • v1.0.4 (February 27, 2021)

    1. 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".

TOP

Documentation

Overview

Package main (auth.go) : Get access token

Package main (doc.go) : This is a CLI tool to submit files to both Gist and Slack.

When I submitted a script to Slack, I had saved the script to Gist as a backup. I have done manually this. Recently, I wished this process could be automatically run. So I created this tool.

Features of "gislack" are as follows.

1. Submits files to both Gist and Slack, simultaneously.

2. Submits, updates and deletes files for Gist.

3. Submits and deletes files for Slack.

4. Retrieves access token from client ID and client secret for Gist and Slack.

You can see the release page https://github.com/tanaikech/gislack/releases

More information is https://github.com/tanaikech/gislack

# APIs Gist api document https://developer.github.com/v3/gists/

Slack api document https://api.slack.com/methods

---------------------------------------------------------------

# How to use gislack At first, please retrieve client ID and client secret from GitHub and Slack. Please set `http://localhost:8080` for each redirect_uri. If you cannot port 8080, you can change it.

GitHub -> https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/about-authorization-options-for-oauth-apps/ Slack -> https://api.slack.com/apps

After retrieved them, please run as follows.

A1. Retrieves access token for Gist $ gislack auth -gi {client_id of GitHub} -gs {client_secret of GitHub} -p {port(default is 8080.)}

A2. Retrieves access token for Slack $ gislack auth -si {client_id of Slack} -ss {client_secret of Slack} -p {port(default is 8080.)}

By this, you can see `gislack.cfg` file on your current working directory.

In the case of submitting a file to both Gist and Slack,

$ gislack d -f {file} -t {title} -p -ft {file type for Slack(e.g. javascript)} -ch {channel for Slack(e.g. general)} -ic {initial comment for Slack}

-p : This is a boolean. If you want to submit as a public for Gist, please use this. -ic : You can give initial comment using this.

In the case of submitting a file to Gist,

$ gislack g -f {file} -t {title} -p

In the case of submitting a file to Slack,

$ gislack s -f {file} -ti {title} -ch {channel} -ft {file type} -ic {initial comment}

gislack has more commands, please check it here. ( https://github.com/tanaikech/gislack )

---------------------------------------------------------------

Package main (gistslack.go) : This file is included all commands and options.

Package main (handler.go) : Handler for gistslack

Package main (jsoncontrol.go) : Control gistslack by JSON data

Package main (materials_double.go) : Materials for doubleSubmit.

Package main (materials_gist.go) : Materials for gist.

Package main (materials_slack.go) : Materials for slack.

Directories

Path Synopsis
Package utl (fetcher.go) : These methods are for retrieving data from URL.
Package utl (fetcher.go) : These methods are for retrieving data from URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL