The way to connect Bitbucket to Slack

I wrote the code to push notification to Slack when someone create an issue, when someone created a comment, etc. in Bitbucket.

Story

The mechanism to send notification to Slack when some action is taken in Bitbucket, is prepared in Bitbucket, called webhooks. It can be turned on in each project setting page.

In Slack, we can connect to Bitbucket easily in setting page. But Slack can only receive push notification of Bitbucket, can’t receive comment or issue notification, at that time ().

I want to be notified issue and comment creation rather than push action, and created such code in Google Apps Script.

Code

Copy the following script to Google Apps Script, and deploy as web app, which is in “publish” menu. Then, it’s url would be shown and set it as webhook url in Bitbucket console panel.

Bitbucket で何らかの操作が行われるたびに Google Apps Script の処理が実行され、 Slack に 投稿されるようになります。

If I had had time, I would’ve create object model and factory, etc. But in real, the code is not so clean.

(And I put the code to Github Bitbucket To Slack Gas. Contribution is welcomed.)

First, Bitbucket send post request to the app and doPost will be executed. Then, it creates message to post to Slack in createSlackMessage function, from the data posted.

After that, it posts to Slack.

Caution

createSlackMessage では、 Issue の場合、 Pull Request の場合などパターン分けしていますが、 上で分けてある以上に 細かくパターンが分かれます。 今回は私の業務上必要だろうと思われる分岐にとどめています。 そのパターンを正確に判断するには Bitbucket から送信されるヘッダの中を確認するのがいいのですが、 Google Apps Script ではリクエストヘッダを確認することができないため ペイロード部分のデータで分岐を行っています。

実際のところ Pull Requestapproved のあたりはまだ検証中のため、 正しく判別できているという保証がないです。

If you can use Heroku or AWS or other hosting service, it would be good to create in PHP, Ruby, etc. which can handle request header.

Tsukiji-Shijo 500 yen Kiwami Chinese Noodle

I went to Kiwami Chinese Noodle, called “Kiwami Ramen”, located at Tsukiji Shijo, where we can eat Chinese Noodle (Ramen noodle) only for about 500 yen. The most reasonable noodle is only for 320 yen, about 2 or 3 dollars.

At that time, I ate ramen noodle in salt flavored soup, “Shio Ramen”, for 470 yen.

喜輪味ラーメンで食べた塩ラーメン。 こしょうと唐辛子をふりかけました。
喜輪味ラーメン の 塩ラーメン

Surprising Menu

I was surprised at ramen noodle in mayonnaise flavored soup, called mayonnaise ramen. 数少ない、 マヨネーズラーメンを提供しているお店です。

ラーメンだけでなく、カレーもあります。

System and Price

First, buy tickets on ticket vending machine. Second hand out it.

価格帯はだいたいが 500円 程度 です。 セットメニューもありますが、 それでもだいたい 500円 程度 です。

毎日11時から営業しています。

月曜は 350円 以上 なら 大盛無料 です。

Continue reading Tsukiji-Shijo 500 yen Kiwami Chinese Noodle

RSpec: Test Helper Method using current_user function

I’ll introduce the way to test rails helper code that uses current_user method provided by device gem.

Environment

  • Ruby 2.2.2
  • Rails 4.1.8
  • RSpec 3.1.0

Test Target

The function we are going to test is below. It compare the return value of current_user method and user_id given as argument, and check the argument user_id is of current login user or not.

Continue reading RSpec: Test Helper Method using current_user function

この一冊で「読む力」と「書く力」が面白いほど身につく!

Sorry, this entry is only available in 日本語.

この一冊で「読む力」と「書く力」が面白いほど身につく! (青春出版社)』を読みました。

読む力書く力に分けて合計120を超えるテクニックが紹介されています。 情報整理、速読・多読、ビジネス、企画書、メールと分野が多岐にわたるのですが、 その中でも 今の私に使えそうだと思ったテクニックを3つ紹介します。

資料として使いやすいノートは「1枚目」が違う

106ページに記載されているこの方法、とてもいいと思います。 ノートの最初の3ページほどを、目次として整えていきます。 さらに記号も使って見やすくわかりやすくします。

過去、アイディアをノートに書き溜めるということをやっていたのですが、どこになにを書いたかわからなくなって、使えるノートになりませんでした。 もしあのとき 最初の数ページで目次を作っていたら、 もっと有意義なノートになっていたと思います。

私が使っている B5 ノートは 35行60ページ あるので、 平均で 1ページにつき2行で目次に書き足すなら 最初の2ページを使えば済みます。

107、108、120、121ページのテクニック と合わせて使えば、 考える力も さらに伸びそうです。

好感度の高いメールは「締めのひと言」が違う

タイトルから考えて 「書き手の人間性」が垣間見えるような一文を追伸としていれる というのが、 筆者が最も言いたかったことだと思うのですが、 私が注目したポイントはそこではありません。

ビジネスメールでは、 わかりやすく的確な文章を書くことが求められます。 文章のわかりやすさは、 自分で自分の作った文章を読んで感覚的に推敲・改善していくものですが、 この本にはその基準となる文字数が記載されていました。

50文字を超える文は要チェックです。 改善の余地があります。

新聞でも、 要点は50文字以内でまとめられているそうです。

手帳に書くとモチベーションが上がる「10年計画表」

今後10年のプランを手帳に書くというテクニックです。 私は手帳を使わないので、ノートあるいはパソコンやスマートフォンの背景に応用します。

過去に、 企業研修等で 今後の人生プラン・キャリアプランを考えることがありました。 でも、 考えたのはそのときだけで、 しばらく見てもいませんでした。

でも 今後のプランは きっと役に立つと思います。 だから見えるところに 10年プランを置いておこうと思いました。 自分のゴールが念頭にあったほうが、 濃い時間が過ごせるに決まっています。