LoginSignup
1
3

More than 5 years have passed since last update.

Code Climateの結果をSlackに通知する

Last updated at Posted at 2016-01-05

SlackとCode ClimateにIntegrationを設定して、SlackにCode Climateの結果を通知するようにする。

Code ClimateをPythonリポジトリに適用する - Qiita
でCode Climate連携を設定したリポジトリが対象。

SlackとCode ClimateのIntegration設定

Code Climate公式に設定手順がある。
Slack Integration · Code Climate Platform

  1. In Slack, click the "Team Settings" arrow in the upper-left hand corner of the screen and select Configure Integrations.

上記の最初の手順はSlackのUIが変更になったのか、微妙に違った。
Configure Integrationsではなく、Apps & Custom Integrationsだった。

00_slack.png

後は手順通りに設定して、連携テストまで実施すると、
以下の通りCode Climateのアイコンでメッセージが表示される。

01.png

Code Climateの結果通知を確認

本題。
前述のSlack Integrationの説明によると

By using our Slack integration, Code Climate will automatically post notifications directly to your Slack room. Notifications will be posted whenever important events occur during our analysis (e.g., your code or test coverage gets better or worse). Here are some examples of notifications we'll post in Slack:

  • An area of your codebase increases from a D or F to any other grade. For example, from a D to an A.
  • An area of your codebase decreases to a D or F from any other grade. For example, from a B to an F.
  • New code is added to your codebase and its initial grade is a D or F.
  • Test coverage improves or declines.

コード評価(GPA)またはコードカバレッジが大きく増減すると通知される。

Pythonでは現状ではコードカバレッジ集計は対応していないため、GPAに変化があった場合のみ通知される。
GPAの値を意図的に変化させて、どう通知されるかを見てみる。

実験

実験:D評価のファイルをA評価にしてみる

  • An area of your codebase increases from a D or F to any other grade. For example, from a D to an A.

上記の通知条件を試してみる。

  • 元のスコア
    • GPA.png

上記の評価となっているリポジトリの中から、D評価のファイル(writer.py)
02_before.png
の中身をA評価になるように書き換える(リファクタリングではなく、何もしないコード、ファイル名は不変)。

  • ファイル置き換え後のGPA
    • 03.png

結果

このとき、Slackには通知されなかった。

実験:A評価のファイルをD評価にしてみる

  • An area of your codebase decreases to a D or F from any other grade. For example, from a B to an F.

上記の通知条件を試してみる。
前述で差し替えたファイル(writer.py)を元に戻す(スコアAのファイルをスコアDのファイルに戻す)。

  • New code is added to your codebase and its initial grade is a D or F.

ついでに上記の通知条件も試す。
スコアDのファイル(codeclimatetest.py)を新規追加する。

2ファイルの修正/追加をコミットする。

結果

今度はSlackのチャンネルに通知された。

04_slack.png

Compareをクリックすると、Code Climateのページに飛べて、コミット間での変化点を示してくれる。

05_codeclimate.png

1
3
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
1
3