Skip to content

Add reusable PR approved issue check workflow - #13

Merged
jeffcarp merged 6 commits into
keras-team:mainfrom
jeffcarp:add-pr-approved-issue
Sep 24, 2026
Merged

jeffcarp merged 6 commits into
keras-team:mainfrom
jeffcarp:add-pr-approved-issue

Conversation

@jeffcarp

@jeffcarp jeffcarp commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Extracts pr-approved-issue.yml and scripts/pr-approved-issue.js from keras-hub into keras-team/shared-workflows, adds unit tests in scripts/pr-approved-issue.test.js, and adds docs/pr_policy.md.

Summary of Changes

  1. Reusable Workflow (.github/workflows/pr-approved-issue.yml)

    • Accepts a ref input (default 'main') to check out keras-team/shared-workflows at a pinned SHA/ref.
    • Bypasses Bot accounts and OWNER / MEMBER / COLLABORATOR associations at the job if: level.
  2. Policy Documentation (docs/pr_policy.md)

    • Documents the Keras Pull Request Policy, automated enforcement rules, and FAQ, with a note directing policy feedback to keras#23601.
    • Serves as the canonical policy URL for PR templates and bot comments so every PR across Keras repos no longer triggers a GitHub cross-referenced timeline event on keras-team/keras#23601.
  3. First-Principles Improvements in scripts/pr-approved-issue.js

    • Fetch live PR state via github.rest.pulls.get: Fetches the live PR description and draft status from the GitHub API rather than reading the frozen webhook context.payload.pull_request snapshot, so re-running a failed workflow job after fixing the issue/PR picks up the latest state.
    • No PR description mutation: Removed SECTION_TEMPLATE and github.rest.pulls.update so the action never overwrites the PR body or triggers extra edited webhook runs.
    • No automatic promotion out of draft (markReadyForReview): Removed markReadyForReview and the unconditional convert-to-draft on opened. The script now validates issue references first and only converts non-draft PRs to draft (convertToDraft) when the check fails. Draft PRs remain in draft until the author marks them ready.
    • Simplified comment behavior: Removed upsertComment pagination/updating. When the check passes, it logs via core.info and exits cleanly without commenting. When the check fails, it converts non-draft PRs to draft, posts a comment via createComment (on opened or when converting a non-draft PR to draft), and fails the check via core.setFailed.
    • Strip HTML comments (<!-- ... -->) before scanning: Prevents findIssueNumbers from matching placeholder issue numbers (such as <!-- Fixes #123 -->) inside HTML comments.
    • Ignore keras-team/keras#23601: Explicitly ignores issue #23601 in keras-team/keras so PRs created with the legacy template link are not treated as linking issue #23601.
    • Bot & logging consistency: Skips [bot] login suffixes (author.toLowerCase().endsWith("[bot]")) in addition to type === "Bot" and uses core.info instead of console.log.
  4. Unit Tests (scripts/pr-approved-issue.test.js)

    • Added node:test suite covering non-PR payloads, bypassed roles/bots, live PR fetch via pulls.get on re-runs, draft conversion and commenting on failure, clean pass without draft/comment mutation, HTML comment & #23601 filtering, cross-repo & PR number filtering, and GraphQL error handling.

Closes #9

@laxmareddyp laxmareddyp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Comment thread scripts/pr-approved-issue.js Outdated
@jeffcarp

Copy link
Copy Markdown
Member Author

Ok I overhauled this entire PR to fix some edge cases and remove some behavior (like automatically returning PRs from draft to non-draft (this is unexpected behavior) and mutating the PR description to help users who deleted it from the template (that's their problem)). I also added canonical documentation about the PR policy in docs/pr_policy.md that we can point to instead of referencing the issue (which generates tons of cross-issue links). Can you do a quick re-review please? @laxmareddyp @SamanehSaadat

Comment thread scripts/pr-approved-issue.js Outdated
@jeffcarp
jeffcarp merged commit f89ada8 into keras-team:main Sep 24, 2026
8 checks passed
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.

Extract pr-approved-issue.yml and scripts/pr-approved-issue.js from keras-hub into shared-workflows

3 participants