LoginSignup
54
52

More than 5 years have passed since last update.

hubot-scriptsを使おう!

Last updated at Posted at 2015-01-31

あなたはhubot をインストールしただけで満足していませんか?
それだけでも充分便利なのですが、もっと便利に使いこなす方法があります。
それが、hubot-scripts。

hubot-scriptsとは、hubotコミュニティの方々が作った様々なスクリプト郡のことです。
「hubot使って〜なことしたいなぁ。」と思った時、hubot-scripts を探せば、
実は簡単に実現できる場合があるので、要チェック!

どんなものがあるの?

スクリプトはコチラ
また、hubot-script-catalogに、スクリプトの簡単な紹介があります。
しかし見ると分かりますが、とにかく多い。。orz
なので、hubotを使ってやりたいことをイメージして、このページを検索しながら探すと良いでしょう。

インストール方法

実は hubot-scripts は、最初からhubotのソースに同梱されています!
(node_modules/hubot-scripts/src/scripts/ 以下)

ただし、hubotソース直下の hubot-scripts.json に記載することで、初めて利用可能になります。
今回の紹介範囲を全て追加すると、以下のようになりました。
※"redis-brain.coffee", "shipit.coffee" は、最初から記載されている。

hubot-scripts.json
["redis-brain.coffee", "shipit.coffee", "aws.coffee", "geocodeme.coffee", "github-activity.coffee", "github-commit-link.coffee", "github-commiters.coffee", "github-commits.coffee", "github-credentials.coffee", "github-issue-link.coffee", "github-issues.coffee", "github-merge.coffee", "github-pull-request-notifier.coffee", "github-pulls.coffee", "github-search.coffee", "github-status.coffee", "heroku-status.coffee", "jenkins-notifier.coffee", "jenkins.coffee", "jira-issues.coffee", "jira.coffee", "list-jira-bugs.coffee", "pomodoro.coffee", "pypi.coffee", "remind.coffee", "tasks.coffee", "time.coffee", "weather.coffee", "wikipedia.coffee"]

もう1点、呼び出すスクリプトによっては、外部モジュールに依存しているものがあるので注意。
その場合、事前にインストールしておかないと、hubotを起動時にエラーとなります。

# 例) aws.coffee の場合

以下のように、依存関係が存在するものは、helpコメントに記載があります。
# Dependencies:
# "aws2js": "0.6.12"
# "underscore": "1.3.3"
# "moment": "1.6.2"

この場合、依存モジュールをインストールしてあげれば起動できるようになります。
npm install aws2js --save
npm install underscore --save
npm install moment --save

おすすめhubot-scriptsの紹介

実用性が高そうなものをいくつか紹介していきます。(要は私が気になったやつ。。w)

GitHub連携

利用するには、下記の環境変数の登録が必要。

  • HUBOT_GITHUB_ORG="ORGANIZATION" ※githubのプライベートスペースを指定
  • HUBOT_GITHUB_REPO="ORGANIZATION/develop-repo" ※対象となるレポジトリを指定
  • HUBOT_GITHUB_TOKEN="xxx" ※githubの設定で取得したTOKEN
  • HUBOT_GITHUB_USER:="foo"

また、以下の外部モジュールのインストールが必要だった。

sudo npm install githubot --save
npm install date-utils --save
sudo npm install gitio2 --save
npm install underscore.string --save
github-activity.coffee
指定したレポジトリの最新5件のコミット履歴を表示

(以下の外部モジュールのインストールが必要)

(実行例)
hubot repo show レポジトリ名

[09/01 13:09 -> Hirotaka Sato] Merge pull request #31 from feature/messages_cleanup

       Feature/messages cleanup
[09/01 12:58 -> Hirotaka Sato] Merge pull request #32 from feature/README

     README修正、gitignoreに追加
[09/01 12:27 -> Foo] build event/css/styles_spのファイルを追加したけど gitignoreに定義されていなかったので追加
[09/01 12:31 -> Foo] README 修正
[09/01 12:32 -> Bar] add 'git flow init' step
github-commit-link.coffee
コミットのリビジョン番号がチャットに流れると、対応するコミット情報とリンクを表示する。

(実行例)
c4379d7

Commit: Merge pull request #32 from feature/README
       https://github.com/ORGANIZATION/develop-repo/commit/c4379d789474bfa519f356786916ed781a408144
github-commiters.coffee
1. 対象レポジトリのコミッター一覧を表示
2. 対象レポジトリのトップコミッターを表示

(実行例)
hubot repo commiters レポジトリ名

[foo] 2790
[bar] 3213

(実行例)
hubot repo top-commiters レポジトリ名

[xxx] 6462 :trophy:
https://api.github.com/レポジトリ名
github-commits.coffee
githubへのpushに連動した通知

(実行例)
なし
github-credentials.coffee
チャットユーザとgithub上のユーザを紐付ける

(実行例)
hubot i am hirosat
[03:32] Lemonade Hubot: Ok, you are hirosat on GitHub
hubot who am i
[03:32] Lemonade Hubot: @Hirotaka You are known as hirosat on GitHub
hubot who do you know
[03:32] Lemonade Hubot: Here is who I know:      Hirotaka S is hirosat
hubot forget me
[03:40] Lemonade Hubot: @Hirotaka Ok, I have no idea who you are anymore.
hubot who do you know
[03:40] Lemonade Hubot: Here is who I know:
github-issue-link.coffee
説明

(実行例)
#22

Issue 22: Feature/hoge https://github.com/ORGANIZATION/develop-repo/issues/22

ORGANIZATION/another-repo#33

(結果は一緒。環境変数で指定したレポジトリ以外を指定できる。)

user/repo#44

(結果は一緒。ユーザのレポジトリも指定できる。)
github-issues.coffee
Github issuesを表示

(実行例)
hubot show me issues

[5] commit message  = https://github.com/ORGANIZATION/develop-repo/pull/5

hubot show foo's issues for ORGANIZATION/another-repo
↓
No issues found.
github-merge.coffee
未検証。hubot merge project_name/<head> into <base> - merges the selected branches or SHA commits
github-pull-request-notifier.coffee
未検証。プルリクエストのWebフックぽい。
github-pulls.coffee
プルリクエストの確認。

(実行例)
hubot show me ORGANIZATION/develop-repo pulls

There's only one open pull request for ORGANIZATION/develop-repo:
commit message. - hirosat: https://github.com/ORGANIZATION/develop-repo/pull/49

hubot show org-pulls for ORGANIZATION
↓
I found 2 open pull requests for ORGANIZATION:
develop-repo: commit message.. (hirosat) -> https://github.com/ORGANIZATION/develop-repo/pull/49
another-repo: commit message.. (foo) -> https://github.com/ORGANIZATION/another-repo/pull/4
github-search.coffee
対象レポジトリ内のコードを検索

(実行例)
hubot github search ORGANIZATION/develop-repo hoge

Searched for "hoge" in repo ORGANIZATION/develop-repo and found 20 results, first 5: 
- tests.py: https://github.com/ORGANIZATION/develop-repo/blob/xxxxxxxx/apps/...
- README.md: https://github.com/ORGANIZATION/develop-repo/blob/xxxxxxxx//READ...
github-status.coffee
現在のGithubのステータスを表示

(実行例)
hubot github status

Status: good (6 seconds ago)

hubot github status last

Status: good
Message: Everything operating normally.
Date: Fri Jan 16 2015 06:26:38 GMT+0900 (JST)

hubot github status messages

??(Returns the most recent human communications with status and timestamp.)

JIRA連携

利用するには、下記の環境変数の登録が必要。

  • HUBOT_JIRA_URL="https://hoge.atlassian.net/" ※利用するJIRAサイトのドメイン名
  • HUBOT_JIRA_USER="foo" ※JIRAユーザのログイン名。
  • HUBOT_JIRA_PASSWORD="xxx" ※JIRAユーザのパスワード。環境変数が見える環境の場合、hubot用に別ユーザを作ろう。
jira-issues.coffee
会話上の XX-??? (JIRAissue番号)を検知して、イシューリンクを貼ってくれる。

(実行例)
CC-111

[CC-111] JIRA Issueのタイトル
Status: In Progress, assigned to Hirotaka Sato, rep. by Hirotaka Sato, fixVersion: NONE, priority: Major
https://hoge.atlassian.net/browse/CC-111
jira.coffee
(未検証)JIRAJQLを使って、フィルタの検索や保存、表示などなどできるぽい。

(実行例)
hubot show watchers for <Issue Key> - Shows watchers for the given JIRA issue
hubot search for <JQL> - Search JIRA with JQL
hubot save filter <JQL> as <name> - Save JIRA JQL query as filter in the brain
hubot use filter <name> - Use a JIRA filter from the brain
hubot show filter(s) - Show all JIRA filters
hubot show filter <name> - Show a specific JIRA filter
list-jira-bugs.coffee
(未検証)HUBOT-JIRA_USERassignされているチケットをすべて表示
hubot用のJIRAユーザがどのチケットもassignされてないので未検証。。。

(実行例)
(※、下記全てのコマンド共通で、'my' is optional とのこと。)
hubot list my bugs - Retrieve the list of all a user's bugs from JIRA
hubot list my bugs about <searchterm> - Retrieve list of all a user's bugs from JIRA where the summary or description field contains <phrase>
hubot list my <priority> priority bugs  - Retrieve the list of a user's <priority> priority bugs from JIRA
hubot list my <priority> priority bugs about <phrase> - Retrieve list of all a user's <priority> priority bugs from JIRA where the summary or description field contains <phrase>

Jenkins連携

利用するには、下記の環境変数の登録が必要。

  • HUBOT_JENKINS_URL="https://jenkins.your.domain" ※利用するJenkinsサイト
  • HUBOT_JENKINS_AUTH="hirotaka:xxx" ※”ログインユーザ:パスワード"のフォーマット
jenkins.coffee
コマンドからjenkinsの操作が可能になる。

(実行例)
hubot jenkins list

[1] PASS build mysql
[2] PASS deploy_web-dev
[3] PASS deploy_web-prod

hubot jenkins b 2

dev環境へdeployするjenkinsジョブが実行される。

hubot jenkins build deploy_web-dev

"b 2"のコマンドと同意)

hubot jenkins describe deploy_web-dev

JOB: deploy_web-dev
URL: https://jenkins.your.domain/job/deploy_web-dev/
DESCRIPTION: Deployment for development environment
ENABLED: true
STATUS: blue
HEALTH: 
  安定したビルド: 最近のビルドは失敗してません。
LAST JOB: SUCCESS, Wed Jan 28 2015 19:46:33 GMT+0900 (JST)

hubot jenkins last deploy_web-dev

NAME: deploy_web-dev #3244
URL: https://jenkins.your.domain/job/deploy_web-dev/3244/
BUILDING: false

AWS連携

利用するには、下記の環境変数の登録が必要。

  • HUBOT_AWS_ACCESS_KEY_ID="xxxx" ※AWSのアクセスキー
  • HUBOT_AWS_SECRET_ACCESS_KEY="xxxx" ※AWSのシークレットアクセスキー
aws.coffee
EC2SQSの稼働状況が確認できる。

(以下の外部モジュールのインストールが必要)
npm install underscore --save
npm install moment --save
npm install aws2js --save

(実行例)
hubot ec2 status

Found 0 instances for region us-east-1...
Found 0 instances for region us-west-2...
Found 1 instances for region us-west-1...
 [running] - hoge-m1.small / m1.small [ebs x86_64] / ec2-XX-XX-XXX-XXX.us-west-1.compute.amazonaws.com / us-west-1 / i-XXXXXXXX - started Fri, 10/04/2013 8:44 PM
Found 0 instances for region sa-east-1...
Found 0 instances for region ap-northeast-1...
Found 0 instances for region ap-southeast-1...
Found 0 instances for region eu-west-1...

hubot sqs status

(EC2と同様のフォーマット)

その他

geocodeme.coffee
Google Map の検索結果と、その緯度経度を返答してくれます。

(実行例)
hubot where is 新宿 ('hubot geocode me 新宿' でも同じ結果が得られる。)

@Hirotaka That's somewhere around 35.6938401,139.7035494 - https://maps.google.com/maps?q=35.6938401,139.7035494
heroku-status.coffee
Herokuの稼働状況・トラブル状況の確認

(実行例)
hubot heroku status

Production:  green
Development: yellow

hubot heroku status issues 3

[#710] DNS Propagation Delays (unresolved)
[#708] Issues with Scheduler Jobs (resolved)
[#707] DNS Propagation Delays (resolved)

hubot heroku status issue 710

Title:    DNS Propagation Delays
Resolved: false
Created:  2015-01-31T01:22:26Z
Updated:  2015-01-31T01:22:27Z
URL:      https://status.heroku.com/incidents/710
pomodoro.coffee
Pomodoroタイマー (※参考:http://idea-cloud.com/wp/diary/pomodoro.html)

(実行例)
hubot start pomodoro 1

Pomodoro started!
Pomodoro completed! (※ 1 と指定したので 1分後に出る)

hubot start pomodoro

Pomodoro started! (※ 時間を指定しない場合は25分後に完了する)

hubot pomodoro?

There are still 25 minutes in this pomodoro (※残り時間の表示)

hubot stop pomodoro

Pomodoro stopped! (※途中でキャンセルされる)

hubot total pomodoros

You have completed 1 pomodoros (※完了したpomodoro数を表示)
pypi.coffee
pypiパッケージ情報

(以下の外部モジュールのインストールが必要)
npm install pypi --save

(実行例)
hubot show latest from pypi for pylint

Latest version of pylint is 1.4.1

hubot show total downloads from pypi for pylint

Total downloads of pylint: 42923
python_library.coffee
pythonライブラリのリンクを表示

※そのままでは使えなかったので、scriptsにコピーしてurlを直した。
cp node_modules/hubot-scripts/src/scripts/python_library.coffee scripts
vi scripts/python_library.coffee
(20行目:httphttpsに変更。)

(実行例)
hubot python2 library datetime

https://docs.python.org/2/library/datetime.html
remind.coffee
自分に対してリマインドを送る。
(フォーマット:week(s)|day(s)|hour(s)|hr(s)|minute(s)|min(s)|second(s)|sec(s)

(実行例)
hubot remind me in 10 seconds to 宿題!

I'll remind you to 宿題! on Sat Jan 31 2015 16:43:25 GMT+0900 (JST)
(※↓10秒後に表示)
@Hirotaka you asked me to remind you to 宿題!
tasks.coffee
簡易ToDo

(実行例)
hubot task list tasks

There are no tasks

hubot task add 牛乳を買う

Task added: #1 - 牛乳を買う

hubot task add 7時にTVを見る

Task added: #2 - 7時にTVを見る

hubot task list tasks

#1 - 牛乳を買う
#2 - 7時にTVを見る

hubot task delete 1

Task deleted: #1 - 牛乳を買う

hubot task list tasks

#2 - 7時にTVを見る
time.coffee
WorldWeatherOnlineAPIを利用して、各都市の現在時刻を表示(要APIキーの取得)

(実行例)
hubot time in london

Current time in London, United Kingdom ==> 08:16

hubot time in 26.2124013,127.6809317

Current time in Lat 26.21 and Lon 127.68 ==> 17:22
weather.coffee
Forecast.ioAPIを利用して、現在の天気と予報を表示(要APIキーの取得)

(実行例)
hubot weather tokyo

It is currently 7ºC Breezy, 41% humidity

hubot forecast tokyo

The weather for:
1/31 - High of 10ºC, low of: 3ºC Partly cloudy in the morning and breezy throughout the day. 59% humidity
2/1 - High of 9ºC, low of: 1ºC Breezy until afternoon. 50% humidity
2/2 - High of 9ºC, low of: 1ºC Clear throughout the day. 51% humidity
wikipedia.coffee
Wikipediaで調べる

(以下の外部モジュールのインストールが必要)
sudo npm install soupselect --save
npm install htmlparser --save

(実行例)
hubot wiki me 任天堂

Nintendo Co., Ltd. is a Japanese multinational consumer electronics company headquartered in Kyoto, Japan. Nintendo is the world's largest video game company by revenue. Founded on September 23, 1889 by Fusajiro Yamauchi, it originally produced handmade hanafudaplaying cards. By 1963, the company had tried several small niche businesses, such as cab services and love hotels.
https://en.wikipedia.org/wiki/%E4%BB%BB%E5%A4%A9%E5%A0%82
54
52
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
52