All posts by Kenji

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