Skip to content

Added script to tally and analyze GitHub issue comments from JSON data #64

Added script to tally and analyze GitHub issue comments from JSON data

Added script to tally and analyze GitHub issue comments from JSON data #64

name: Fetch Issue Comments
on:
workflow_dispatch:
inputs:
owner:
description: "Repository owner (organization or user). Defaults to this repo owner."
required: false
repo:
description: "Repository name (or owner/repo). Defaults to this repo name."
required: false
users:
description: "Comma-separated GitHub usernames to keep (use * for all)"
required: false
default: "JasonUranta,JackRichman,mgodoy2023,Zak234,anonymousanemone"
include_pr_reviews:
description: "Also fetch PR review comments (/pulls/comments)"
required: false
default: "false"
output_path:
description: "Output JSON path (defaults to data/issue_comments.json)"
required: false
full_resync:
description: "Ignore watermarks & ETags and backfill everything"
required: false
default: "false"
commit_to_repo:
description: "Commit the JSON to the repo (workflow_dispatch only)"
required: false
default: "false"
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
concurrency:
group: issue-comments-${{ github.repository }}
cancel-in-progress: false
permissions:
contents: write
issues: read
pull-requests: read
jobs:
fetch-comments:
runs-on: ubuntu-latest
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Resolve owner/repo fallbacks
id: derive
shell: bash
run: |
echo "OWNER=${GITHUB_REPOSITORY%%/*}" >> "$GITHUB_OUTPUT"
echo "REPO=${GITHUB_REPOSITORY##*/}" >> "$GITHUB_OUTPUT"
- name: Resolve output path
id: outpath
shell: bash
run: |
if [ -n "${{ github.event.inputs.output_path }}" ]; then
echo "VALUE=${{ github.event.inputs.output_path }}" >> "$GITHUB_OUTPUT"
else
echo "VALUE=data/issue_comments.json" >> "$GITHUB_OUTPUT"
fi
- name: Run comment fetcher
env:
INPUT_OWNER: ${{ github.event.inputs.owner || github.repository_owner || steps.derive.outputs.OWNER }}
INPUT_REPO: ${{ github.event.inputs.repo || github.event.repository.name || steps.derive.outputs.REPO }}
INPUT_USERS: ${{ github.event.inputs.users || 'JasonUranta,JackRichman,mgodoy2023,Zak234,anonymousanemone' }}
INPUT_INCLUDE_PR_REVIEWS: ${{ github.event.inputs.include_pr_reviews || 'false' }}
INPUT_OUTPUT_PATH: ${{ steps.outpath.outputs.VALUE }}
INPUT_FULL_RESYNC: ${{ github.event.inputs.full_resync || 'false' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: python scripts/fetch-issue-comments.py
- name: Gzip JSON for artifact (if exists)
shell: bash
run: |
if [ -f "${{ steps.outpath.outputs.VALUE }}" ]; then
gzip -c "${{ steps.outpath.outputs.VALUE }}" > "${{ steps.outpath.outputs.VALUE }}.gz"
else
echo "No output at ${{ steps.outpath.outputs.VALUE }}; skipping gzip."
fi
- name: Upload issue-comments artifact (gz)
uses: actions/upload-artifact@v4
with:
name: issue-comments-${{ github.run_id }}.json.gz
path: ${{ steps.outpath.outputs.VALUE }}.gz
if-no-files-found: ignore
retention-days: 90
- name: Commit JSON to repo (optional & safe)
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.commit_to_repo == 'true' }}
shell: bash
run: |
set -euo pipefail
OUT="${{ steps.outpath.outputs.VALUE }}"
if [ ! -f "$OUT" ]; then
echo "No output file to commit."
exit 0
fi
if ! git diff --quiet -- "$OUT"; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "$OUT"
git commit -m "Update issue comments [skip ci]"
git push
else
echo "No changes to commit."
fi