Code Insight
Code Insights では、ユーザーとそのチームが、コード レビュー プロセス全体を通してプル リクエストにおけるコード品質を改善できるように、レポート、アノテーション、評価基準を提供します。利用できる Code Insights として、静的分析レポート、セキュリティ スキャン結果、アーティファクト リンク、ユニット テスト、ビルド ステータスがあります。
前提条件
Bitbucket Cloud アカウントが必要です。
1 つ以上のプル リクエストまたはパイプラインが必要です。
If you are using pipelines, you have to use an integration.
サードパーティ プロバイダーの場合は、Bitbucket Cloud にレポートを追加すると、コード カバレッジ、コード品質、デプロイ情報などの情報をプル リクエストに取得できます。既存の統合機能をお探しの場合は、Bitbucket Cloud にレポートを投稿するツールが Marketplace にすでに多数提供されています。
レポート
プル リクエストでレポートを表示する
プル リクエストに移動します。
Select Reports on the left navigation sidebar. You can also view your reports via the right sidebar.
If you haven’t set up a pipe or an integration, you won’t be able to view any reports. Check the list of available pipes, or learn how to write a pipe.
注釈付きレポートを差分表示で表示する
If you have reports, annotations are enabled by default, so you will be able to see annotated reports displayed within a line or per file. To see an aggregated view of the available annotations, select the Report section (card) on the right sidebar.
レポートの注釈を無効または非表示にする
差分表示から注釈を無効にするには、プル リクエストの右上隅にある [設定] ボタンを選択して、[表示] にリストされている [注釈] チェックボックスをチェックします。
To hide annotations on a specific pull request, select the More options (), then Hide annotations.
パイプラインでレポートを表示する
左側のナビゲーション サイドバーで [Pipelines] を選択します。
レポートを表示するパイプラインを選択します。
Select the # reports link at the bottom of the pipeline modal to see the detailed reports.
Reports-API を使用してレポートをアップロードする
サードパーティ プロバイダは REST-API を使用してレポートを直接アップロードすることもできます。レポートは 1 つのコミットに基づきます。
The full Open API documentation of the REST API for code reports can be found at the following link: https://developer.atlassian.com/bitbucket/api/2/reference/search?q=tag:reports
レポートの作成
レポートを作成する場合は、必ずそのコミットのすべてのレポートで一意となる ID を生成してください。自社システムにすでに存在する ID を使用する場合は、競合を防ぐためにシステム名を先頭に追加することをお勧めします (例: mySystem-001)。
cURL リクエストの例
curl --request PUT 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repository-name>/commit/<commit-hash>/reports/mySystem-001' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "Security scan report",
"details": "This pull request introduces 10 new dependency vulnerabilities.",
"report_type": "SECURITY",
"reporter": "mySystem",
"link": "http://www.mySystem.com/reports/001",
"result": "FAILED",
"data": [
{
"title": "Duration (seconds)",
"type": "DURATION",
"value": 14
},
{
"title": "Safe to merge?",
"type": "BOOLEAN",
"value": false
}
]
}'
title、details、および report_type のみがペイロードの必須フィールドです。データ配列の下の要素は自由に定義できます。それらの要素で、ユーザーに伝える任意の情報を表せます。レポート データは必須であり、最大 10 件の要素を含められます。その配列に含まれる情報は、ペイロードのその他のフィールドと共にレポートの先頭に表示されます。
The same endpoint can also be used to update existing reports. The URL is also available as a GET and a DELETE endpoint. Once created, a report can be addressed with the generated UUID instead of the external id. Additionally, a GET for …/<commit-hash>/reports without an ID returns all reports belonging to this commit.
Jira ユーザーのみ: Jira でリモート リンクが利用できるようになりました。レポートにリモート リンクを追加するには、create ペイロードで "remote-link-enabled" フィールドを「true」に設定します。これらのレポートは、Jira の [その他のリンク] タブと Bitbucket のレポートに表示されます。
アノテーション
脆弱性を表すコード行など、注釈は個別の所見であり、レポートの一部として認識されます。これらの注釈は、特定のファイルやファイル内の特定の行に添付できますが、オプションの機能です。注釈は必須ではありませんが、レポートには最大 1,000 件の注釈を含められます。
Just as reports, annotation needs to be uploaded with a unique ID that can later be used to identify the report as an alternative to the generated UUID.
cURL リクエストの例:
curl --request PUT 'https://api.bitbucket.org/2.0/repositories/<workspace>/<reposity-name>/commit/<commit-hash>/reports/mySystem-001/annotations/mySystem-annotation001' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "Security scan report",
"annotation_type": "VULNERABILITY",
"summary": "This line represents a security thread.",
"severity": "HIGH",
"path": "my-service/src/main/java/com/myCompany/mySystem/logic/Main.java",
"line": 42
}' |
annotation_type と summary のみがペイロードの必須フィールドです。
また、同じエンドポイントを使用して既存のレポートを更新できます。URL は、GET および DELETE エンドポイントとして使用できます。さらに、POST …/annotations は一括オプションを提供します。このエンドポイントでは、最大 100 件の注釈を一度に作成または更新できます。ペイロードには、注釈オブジェクトの JSON 配列を含める必要があります。
認証
Bitbucket Pipelines を使用することで、追加の認証を行わずに Reports-API を使用できます。これを行うには、各パイプラインと共に実行される、「localhost:29418」のプロキシ サーバーにリクエストを送信する必要があり、有効な Auth-Header がリクエストに自動で追加されます。
cURL リクエストの例
curl --proxy 'http://localhost:29418' --request PUT "http://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/commit/$BITBUCKET_COMMIT/reports/mySystem-001/annotations/mySystem-annotation001"カスタム パイプを開発する場合も、同じプロキシ サーバーを使用できますが、パイプは Docker コンテナ内で実行されるために URL が少し異なります。
cURL リクエストの例
curl --proxy 'http://host.docker.internal:29418' --request PUT "http://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/commit/$BITBUCKET_COMMIT/reports/mySystem-001/annotations/mySystem-annotation001"For calls from outside of Bitbucket, see Bitbucket API developer doc for Authentication methods. For the Reports-API, you will need to have access to the repository and use the repository scopes. See the Scopes for the Bitbucket Cloud REST API section in the Bitbucket API developer doc for Authentication methods.
この内容はお役に立ちましたか?