【小ネタ】特定期間の GitHub Issue/Pull Request コメントを洗い出すghスクリプト (macOS)
GitHub Project (および Issue, Pull Request) を使ったプロジェクト推進、タスク管理を実施しています。 数人のメンバー内でうまく回るようにIssue/PRを管理しています。

GitHub Project 活用イメージ
このような運用をしていると、会議でのファシリテーション時に「特定期間にどんなコメントがなされていたか」を把握したいニーズが出てきます。 手で各Issue/PRを確認していくのは時間がかかるため、効率化したいです。
そこで、この把握作業を効率化するために「GitHub CLI(gh) を使ったコメント棚卸しスクリプト」を作成してみました。 ※ Claude Code を一緒に作ってみました。
前提: 必要なツール
スクリプトを実行するには、以下のツールが必要です。
- jq
- GitHub CLI(gh)
- gdate
- coreutils をインストールすることで取得できます (
brew install coreutils)
- coreutils をインストールすることで取得できます (
作ったスクリプト
以下、作成したスクリプトです。
使い方
リポジトリのディレクトリに移動して、以下のように実行します。
cd ${path_to_your_repo}
bash ./inventory-github-comments.sh "2025-10-14 09:00" "2025-10-17 18:00"
引数には日本時間(JST)で開始日時と終了日時を指定します。 スクリプト内にて自動的にUTCに変換して、GitHub APIに問い合わせます。
以下、出力サンプルです。
## コメントログ
取得範囲: 2025-10-14 09:00 - 2025-10-17 18:00
### Issue: API仕様の改善 #42
💬 octocat 2025-10-15 10:30
> 新しいエンドポイントの仕様について検討しました
> レスポンス形式は JSON Schema で定義する方向で進めます
>
> -- https://github.com/octocat/Hello-World/issues/42#issuecomment-1234567890
### Issue: 週次タスクまとめ #85
💬 octocat 2025-10-15 14:20
> ## 今週の進捗
>
> API実装: 完了 #42
> ↓
> ドキュメント作成 #88 by octocat
> ↓
> CI/CD改善 #90 by octocat **レビュー中**
> ↳ デプロイ自動化 #91 → 本番適用 #92
>
> -- https://github.com/octocat/Hello-World/issues/85#issuecomment-1234567891
### PR: ディレクトリ構成の整理 #164
💬 octocat 2025-10-16 11:00
> @octocat レビューお願いします 🙏
>
> -- https://github.com/octocat/Hello-World/pull/164#issuecomment-1234567892
💬 octocat 2025-10-16 15:30
> @octocat LGTM です!
>
> -- https://github.com/octocat/Hello-World/pull/164#issuecomment-1234567893
使用しているghコマンド
gh issue/pr list で一覧を取得
gh issue list および gh pr list で更新日時が指定期間内のIssue/PRを絞り込みます。
gh issue list --limit 500 --state all \
--search "updated:>=2025-10-14T00:00:00Z" \
--json number,title,updatedAt
# [
# {
# "number": 85,
# "title": "週次タスクまとめ",
# "updatedAt": "2025-10-15T05:20:00Z"
# },
# {
# "number": 42,
# "title": "API仕様の改善",
# "updatedAt": "2025-10-15T01:30:00Z"
# },
# ...以下略
gh issue/pr view でコメントを取得
gh issue view および gh pr view に --comments オプションを付与して、 コメント一覧を取得します。
gh issue view 42 --comments --json comments
# {
# "comments": [
# {
# "id": "1",
# "author": {
# "login": "octocat"
# },
# "authorAssociation": "MEMBER",
# "body": "新しいエンドポイントの仕様について検討しました\nレスポンス形式は JSON Schema で定義する方向で進めます",
# "createdAt": "2025-10-15T01:30:00Z",
# "includesCreatedEdit": false,
# "isMinimized": false,
# "minimizedReason": "",
# "reactionGroups": [],
# "url": "https://github.com/octocat/Hello-World/issues/42#issuecomment-1234567890",
# "viewerDidAuthor": true
# },
# {
# "id": "1",
# "author": {
# "login": "octocat"
# },
# ...以下略
jq でフィルタリング・整形
取得したコメントJSONから、期間内のコメントだけを抽出し、読みやすい形式に整形します。 (※ github-actions によるコメントは除外)
jq -r --arg start "$START_UTC_ISO" --arg end "$END_UTC_ISO" \
'.comments[] |
select(.createdAt >= $start and .createdAt < $end) |
select(.author.login != "github-actions") |
{
login: .author.login,
createdAt: .createdAt,
body: .body,
url: .url
} | @json'
おわりに
gh CLIとjqを組み合わせてGitHub上のコメントを抽出するスクリプトを紹介しました。 議事メモ作成やチーム活動のふりかえりなど、定期的な報告作業の効率化に活用できます。
以上、参考になれば幸いです。






