Skip to content

feat(groq): GitHub Action that posts a whimsical quote as a comment on new pull requests. - #6393

Open
polsala wants to merge 1 commit into
mainfrom
ai/groq-20261114-0047
Open

polsala wants to merge 1 commit into
mainfrom
ai/groq-20261114-0047

Conversation

@polsala

@polsala polsala commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Implementation Summary

  • Utility: nightly-pr-quote-commenter
  • Provider: groq
  • Location: github-actions/nightly-nightly-pr-quote-commenter
  • Files Created: 4
  • Description: GitHub Action that posts a whimsical quote as a comment on new pull requests.

Rationale

  • Automated proposal from the Groq generator delivering a fresh community utility.
  • This utility was generated using the groq AI provider.

Why safe to merge

  • Utility is isolated to github-actions/nightly-nightly-pr-quote-commenter.
  • README + tests ship together (see folder contents).
  • No secrets or credentials touched.
  • All changes are additive and self-contained.

Test Plan

  • Follow the instructions in the generated README at github-actions/nightly-nightly-pr-quote-commenter/README.md
  • Run tests located in github-actions/nightly-nightly-pr-quote-commenter/tests/

Links

  • Generated docs and examples committed alongside this change.

Mock Justification

  • Not applicable; generator did not introduce new mocks.

@polsala

polsala commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

🤖 Review by GROQ Agent

✅ What's solid

  • Self‑contained implementation – the action only relies on bash, jq, and curl, all of which are pre‑installed in the GitHub Actions runner. No extra runtime or Docker image is required.
  • Deterministic quote selection – using PR_NUMBER % ${#QUOTES[@]} guarantees the same PR always receives the same quote, which makes the behaviour predictable and testable.
  • Graceful no‑op for non‑PR events – the script exits with status 0 when pull_request.number is missing, avoiding unnecessary failures on unrelated events.
  • Composite action wrapper – action.yml correctly declares a composite action and forwards the environment token, keeping the entry‑point simple.
  • Clear README – the documentation explains the purpose, usage, and how to run the test locally, which is helpful for contributors unfamiliar with the utility.

🧪 Tests

Observation Recommendation
The test script creates a temporary GITHUB_EVENT_PATH, injects a mock curl, runs the entrypoint, and greps the log for the expected quote. ✅ Good baseline coverage for the happy‑path.
The test only covers a single PR number (7) and the “happy” path. • Add a test for a non‑PR payload (e.g., an issue event) to verify the early‑exit logic.
• Add a test for missing GITHUB_EVENT_PATH to ensure the script fails with a clear error message.
• Add a test for missing GITHUB_TOKEN – the script should abort before calling curl.
The test validates the presence of the expected quote string in the curl arguments, but does not verify the full JSON payload or the HTTP method. • Use a more precise assertion, e.g. grep -E '"body":"Keep calm and code on."' to ensure the payload is correctly formed.
• Verify that -X POST is present, confirming the request method.
The test script writes the mock curl log to the repository root (curl_log.txt). • Run the test in a temporary directory (e.g., mktemp -d) and clean up with trap to avoid polluting the repo.
• Example:
bash\nTMPDIR=$(mktemp -d)\nexport CURL_CMD=\"$TMPDIR/mock_curl.sh\"\n... # run action\nrm -rf \"$TMPDIR\"\n
No test framework is used, so failures are reported via exit 1. • Consider adopting a lightweight Bash test framework such as Bats or shunit2. This provides richer output (pass/fail counts) and built‑in assertions (assert_equal, assert_success).
The test does not check the exit status of the entrypoint. • After invoking the script, capture $? and assert it is 0. This guards against silent failures.

Suggested test snippet (Bats)

#!/usr/bin/env bats

setup() {
  export GITHUB_REPOSITORY="owner/repo"
  export GITHUB_TOKEN="dummy-token"
  export GITHUB_EVENT_PATH="$(mktemp)"
  export CURL_CMD="$(pwd)/mock_curl.sh"
  cat > mock_curl.sh <<'EOF'
#!/usr/bin/env bash
printf "%s\n" "$@" >> curl_log.txt
EOF
  chmod +x mock_curl.sh
  rm -f curl_log.txt
}

teardown() {
  rm -f "$GITHUB_EVENT_PATH" mock_curl.sh curl_log.txt
}

@test "posts correct quote for PR #7" {
  cat > "$GITHUB_EVENT_PATH" <<'EOF'
{ "pull_request": { "number": 7 } }
EOF

  run bash ../src/entrypoint.sh
  [ "$status" -eq 0 ]
  grep -q '"body":"Keep calm and code on."' curl_log.txt
}

🔒 Security

  • Token leakage – the script passes $GITHUB_TOKEN directly to curl via the Authorization header. Since set -euo pipefail is used and there are no echo $GITHUB_TOKEN statements, the token is not logged. Still, consider adding --silent (-s) and --show-error (-S) to surface HTTP errors without echoing the token.

  • JSON encoding – the payload is built with printf '{"body":"%s"}' "$SELECTED". If a quote ever contains a double‑quote or backslash, the JSON would become malformed. Use jq -Rs . to safely encode the string:

    PAYLOAD=$(jq -n --arg body "$SELECTED" '{body: $body}')
  • Error handling for API failures – the current curl call does not use --fail. Adding it will cause the script to exit with a non‑zero status on HTTP errors, which is useful for CI visibility:

    $CURL_CMD -sS --fail -X POST \
      -H "Authorization: token $GITHUB_TOKEN" \
      -H "Accept: application/vnd.github.v3+json" \
      -d "$PAYLOAD" \
      "$API_URL"
  • Input validation – although the action has no inputs, it still reads environment variables (GITHUB_REPOSITORY, GITHUB_EVENT_PATH). Adding explicit checks (e.g., [[ -z "$GITHUB_REPOSITORY" ]] && { echo "GITHUB_REPOSITORY not set"; exit 1; }) makes failure modes clearer.

🧩 Docs/DX

  • README enhancements

    • Add a “Permissions” section clarifying that the GITHUB_TOKEN needs contents: read and pull_requests: write (or repo scope) to post comments.
    • Document how to override the quote list (e.g., via an environment variable) for teams that want custom messages.
    • Provide a quick CI badge (e.g., test status) to surface test health directly in the repo.
  • Action metadata – action.yml currently lists inputs: {}. Adding a description for the action itself and a branding block (icon/color) improves discoverability in the GitHub Marketplace.

    branding:
      icon: 'message-square'
      color: 'purple'
  • Contribution guide – mention that new quotes should be added to the QUOTES array in entrypoint.sh and that the test suite must be updated accordingly.

  • Versioning – consider tagging the action (e.g., v1) and referencing it in the README usage snippet (uses: ./github-actions/nightly-pr-quote-commenter@v1). This helps downstream users pin a stable version.

🧱 Mocks/Fakes

  • Mock curl implementation – the current mock_curl.sh simply appends its arguments to curl_log.txt. This works, but it does not simulate HTTP status codes or error messages. Enhancing the mock to return a non‑zero exit code on demand can be used to test failure handling:

    # mock_curl.sh
    # Return 1 if payload contains the word "error"
    if grep -q "error" <<<"$@"; then
      exit 1
    fi
    printf "%s\n" "$@" >> curl_log.txt
    exit 0
  • Isolation – the test currently modifies global environment variables (GITHUB_REPOSITORY, GITHUB_TOKEN, etc.). Wrapping the test execution in a subshell or using env -i can guarantee a clean environment and prevent accidental leakage into the host shell.

    env -i GITHUB_REPOSITORY="owner/repo" GITHUB_TOKEN="dummy-token" \
      GITHUB_EVENT_PATH="$EVENT_PATH" CURL_CMD="./mock_curl.sh" \
      bash ../src/entrypoint.sh
  • Future mock needs – if the action ever expands to support additional inputs (e.g., custom quote source), consider abstracting the HTTP client behind a function (post_comment) that can be stubbed more easily in tests.


Overall, the utility is well‑scoped, easy to understand, and includes a functional test harness. The suggestions above aim to tighten security, broaden test coverage, and improve developer experience for future contributors.

@polsala

polsala commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

🤖 Review by GEMINI Agent

✅ What's solid

  • The action's purpose is clear and well-defined, providing a self-contained utility.
  • The set -euo pipefail directive in entrypoint.sh is excellent for robust shell scripting, ensuring early exit on errors and undefined variables.
  • The deterministic quote selection based on the PR number (PR_NUMBER % ${#QUOTES[@]}) is a thoughtful feature, ensuring consistency for repeated PR views.
  • The action demonstrates minimal external dependencies, relying only on standard GitHub Actions environment tools (bash, curl, jq).
  • The CURL_CMD environment variable override in entrypoint.sh provides a clean and effective mechanism for testing the curl command without making actual API calls.
  • The action.yml correctly uses a composite run, which is appropriate for encapsulating a simple shell script.
  • The README.md is comprehensive, providing clear usage instructions, feature highlights, and an explanation of the action's internal workings.

🧪 Tests

  • The test_action.sh script provides a solid foundation for testing, effectively mocking the GitHub environment variables and the curl command.

  • The mock_curl.sh script is a simple yet effective way to capture and inspect the arguments passed to curl.

  • Actionable feedback:

    • Add a test case to verify the action's behavior when GITHUB_EVENT_PATH is not set. The entrypoint.sh explicitly checks for this and should exit with an error.
    • Include a test case for events that are not pull requests (e.g., a push event payload). The action should gracefully exit without attempting to post a comment, as handled by the PR_NUMBER check.
    • Enhance the curl_log.txt verification to be more robust. Instead of just checking for the presence of the quote, verify the full curl command, including the API_URL, Authorization header, Accept header, and the complete JSON payload structure.
    # Example for more robust curl_log.txt verification in test_action.sh
    # (after running entrypoint.sh)
    if ! grep -q "https://api.github.com/repos/owner/repo/issues/7/comments" curl_log.txt; then
      echo "Test failed: API URL incorrect."
      exit 1
    fi
    if ! grep -q "Authorization: token dummy-token" curl_log.txt; then
      echo "Test failed: Authorization header missing or incorrect."
      exit 1
    fi
    if ! grep -q "Accept: application/vnd.github.v3+json" curl_log.txt; then
      echo "Test failed: Accept header missing or incorrect."
      exit 1
    fi
    if ! grep -q "{\"body\":\"Keep calm and code on.\"}" curl_log.txt; then
      echo "Test failed: Payload body incorrect."
      exit 1
    fi
    echo "Test passed: expected curl command verified."

🔒 Security

  • The action correctly uses GITHUB_TOKEN for authentication, passed via the env block in action.yml, which is the standard and secure method for GitHub Actions.

  • The absence of external runtime dependencies (beyond standard shell tools) minimizes supply chain risks.

  • Actionable feedback:

    • While the current hard-coded quotes are safe, the JSON payload construction using printf '{"body":"%s"}' "$SELECTED" could be vulnerable if the $SELECTED quote ever contained unescaped double quotes or backslashes. For maximum robustness and future-proofing, consider using jq to construct the JSON payload, as it handles proper escaping automatically.
    # In src/entrypoint.sh, replace:
    # PAYLOAD=$(printf '{"body":"%s"}' "$SELECTED")
    # with:
    PAYLOAD=$(jq -n --arg quote "$SELECTED" '{"body": $quote}')

🧩 Docs/DX

  • The README.md is exceptionally clear, providing a complete usage example and a detailed "How it works" section that explains the logic, including the deterministic quote selection.
  • The testing instructions are straightforward and easy to follow.
  • Actionable feedback:
    • The folder name github-actions/nightly-nightly-pr-quote-commenter contains a repeated "nightly". Aligning this with the action's name in action.yml ("PR Quote Commenter") and the README.md ("Nightly PR Quote Commenter") for consistency would improve discoverability and reduce potential confusion. Consider renaming the folder to github-actions/nightly-pr-quote-commenter.

🧱 Mocks/Fakes

  • The mock_curl.sh script is an effective and simple mock for the curl command, enabling isolated testing of the action's core logic without making actual network requests.
  • The strategy of overriding the CURL_CMD environment variable is a clean and idiomatic way to inject the mock during testing.
  • Actionable feedback:
    • For more complex actions, a mock might need to simulate specific API responses (e.g., returning a JSON payload or a particular HTTP status code) rather than just logging arguments. While not strictly necessary for this action, it's a consideration for future enhancements or more intricate API interactions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant