[アップデート] GitHub Dependabot alerts で「修正パッチが提供済みのアラート」を API でフィルター可能になりました

[アップデート] GitHub Dependabot alerts で「修正パッチが提供済みのアラート」を API でフィルター可能になりました

Clock Icon2025.06.08

こんにちは、製造ビジネステクノロジー部の若槻です。

先々月ですが GitHub Dependabot API で新しく機能が GA されたというアナウンスがありました。

https://github.blog/changelog/2025-04-29-dependabot-api-now-contains-haspatch-in-general-availability/

This new improvement allows users to quickly identify dependencies with the has:patch filter using the Dependabot REST API. This streamlines the process of addressing vulnerabilities and staying up-to-date.

To learn more, check out our REST API endpoints for Dependabot alerts documentation.

このアナウンスブログの記述だけだとどんなアップデートなのか最初私はピンと来なかったのですが、結論としては、Dependabot アラートのうち「修正パッチが提供済みのアラート」を API でフィルターできるようになったということです。

GitHub.com から確認してみる

まずは GitHub.com の Dependabot アラート一覧画面から確認してみます。一覧画面では利用可能なフィルターがサジェストされるようになっているためです。

一覧のフィルターで has まで入力すると、has:patch というフィルターがちゃんと選択できるようになっていますね。

has:patch かつ is:open でフィルターをした結果、オープン中のすべてのアラートはパッチが提供済みの模様でした。

ちなみにパッチが提供されているかどうかは、アラート詳細でバッチ提供済みバージョンが表示されているかどうかで確認できます。これが無ければ has:patch フィルターの対象にならないはず。

逆に -has:patch フィルターを使うと、パッチが提供されていないアラートのみが表示されるようで、今回だと該当するアラートはありませんでした。

GitHub Dependabot API で確認してみる

一方 has:patch フィルターが使える GitHub Dependabot API のエンドポイントは以下の 3 つでした。

説明としては下記のようにありました。現状では has クエリパラメーターでは patch のみがサポートされているようです。

has

Filters the list of alerts based on whether the alert has the given value. If specified, only alerts meeting this criterion will be returned. Multiple has filters can be passed to filter for alerts that have all of the values. Currently, only patch is supported.

先ほどと同じリポジトリで、GitHub CLI を使って Dependabot アラートを取得してみます。結果をすべて出力すると長くなるので、jq コマンドでアラート数のみを確認しています。

# has:patch フィルターなし
$ gh api --method GET /repos/${OWNER}/${REPO}/dependabot/alerts -F per_page=100 --header 'Accept: application/vnd.github+json' | jq "length"
33

# has:patch フィルターあり
$ gh api --method GET /repos/${OWNER}/${REPO}/dependabot/alerts -F per_page=100 -F has=patch --header 'Accept: application/vnd.github+json' | jq "length"
33

# has:patch フィルターなしかつ is:open フィルターあり
$ gh api --method GET /repos/${OWNER}/${REPO}/dependabot/alerts -F state=open -F per_page=100 --header 'Accept: application/vnd.github+json' | jq "length"
31

前述の通り今回試したリポジトリではオープン中のアラートはすべてパッチが提供済みのため、has:patch フィルターを使っても結果は変わらないのですが、上記のようにクエリパラメーターとして使えば良いようです。

その他

GitHub CLI ではクエリパラメーターの付け方に注意

ドキュメントには GitHub CLI でのクエリパラメーターの付け方として以下のように書かれています。

# Example
gh api --method GET /events -F per_page=2 -F page=1
--header 'Accept: application/vnd.github+json' \

直感的に下記のように書きたくなるのですが、これだと上手く動かないので注意が必要です。

# これだと上手く動かない
$ gh api \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  "/repos/${OWNER}/${REPO}/dependabot/alerts?state=open&has=patch"

最初これに気づかずクエリパラメーターが思った通りに動いてくれなくてハマってしまいました。

おわりに

GitHub Dependabot alerts で「修正パッチが提供済みのアラート」を API でフィルター可能になっていたのでご紹介しました。

この機能により「オープン中かつパッチが提供済みのアラート」を取得して、パッチ提供を促すように通知を送るなどの活用ができるかも知れないです。自動化においては下記のブログなどで紹介されている実装が参考になると思います。

https://zenn.dev/tsukulink/articles/c4a204897930a9

以上

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.