Skip to content

Add hasNonStaleLgtm and hasHumanOverride helper #43

@jdelfino

Description

@jdelfino

Summary

Add the core library functions for LGTM comment override support. hasNonStaleLgtm is a pure function that checks PR comments for non-stale LGTM. hasHumanOverride is an async helper that fetches all needed data and checks both override mechanisms (approval + LGTM).

Files to modify

  • .github/agent-workflow/scripts/lib/approval.js
  • .github/agent-workflow/scripts/lib/override.js (new)
  • tests/lib/approval.test.js
  • tests/lib/override.test.js (new)

Implementation steps

  1. Add hasNonStaleLgtm(comments, headCommitDate) to approval.js:

    • Check if any comment body (trimmed, uppercased) starts with "LGTM"
    • Check if comment created_at is after headCommitDate
    • Export alongside hasNonStaleApproval
  2. Create override.js with hasHumanOverride({ github, owner, repo, prNumber, headSha }):

    • Fetch reviews, comments, and commit in parallel via Promise.all
    • Return true if hasNonStaleApproval(reviews, headSha) OR hasNonStaleLgtm(comments, headCommitDate)
    • Export hasHumanOverride
  3. Add tests to approval.test.js for hasNonStaleLgtm:

    • LGTM posted after head commit → true
    • LGTM posted before head commit (stale) → false
    • Lowercase "lgtm" → true
    • "LGTM, looks good" (extra text) → true
    • No LGTM comments → false
    • Empty array → false
  4. Create override.test.js for hasHumanOverride:

    • Approval present → true (short-circuits, no comment check needed)
    • No approval, LGTM present → true
    • Neither present → false
    • Mock GitHub API calls

Acceptance criteria

  • hasNonStaleLgtm correctly identifies non-stale LGTM comments
  • hasNonStaleLgtm is case-insensitive and allows trailing text
  • hasHumanOverride checks both mechanisms and returns true if either matches
  • hasHumanOverride fetches reviews, comments, and commit in parallel
  • All tests pass: node --test tests/lib/approval.test.js tests/lib/override.test.js

Dependencies

None — this is the foundation for the other tasks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    taskImplementation work item

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions