Skip to content

Clean up / improve: commit-safety-checks.js #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025

Conversation

GrantBirki
Copy link
Member

This pull request cleans up the commit-safety-checks file a bit and add some more guardrails / tests.

@Copilot Copilot AI review requested due to automatic review settings May 12, 2025 05:40
@GrantBirki GrantBirki added the enhancement New feature or request label May 12, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR cleans up the commit-safety-checks.js logic by adding defensive guards around timestamp fields and enhancing the commit verification branch, and it extends the test suite with new failure and edge-case tests.

  • Introduced comment_created_at, commit_created_at, and verified_at variables and added checks to throw if required timestamps are missing.
  • Added a guardrail for inputs.commit_verification === true when verified_at is not present, and exported isTimestampOlder for reuse.
  • Expanded tests to cover missing comment/commit dates, missing verified_at, and edge cases of isTimestampOlder.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/functions/commit-safety-checks.js Added defensive timestamp existence checks, guard for missing verified_at, and exported isTimestampOlder.
tests/functions/commit-safety-checks.test.js Added tests for missing timestamps, missing verified_at, and isTimestampOlder error cases.
Comments suppressed due to low confidence (3)

src/functions/commit-safety-checks.js:12

  • [nitpick] Variable names in JavaScript typically use camelCase. Consider renaming comment_created_at to commentCreatedAt (and similarly for other timestamp variables) to align with project conventions.
const comment_created_at = context?.payload?.comment?.created_at

src/functions/commit-safety-checks.js:33

  • Add a unit test for the branch where the commit is authored after the trigger comment (i.e., when isTimestampOlder(commentCreatedAt, commitCreatedAt) returns true) to ensure the early return with the correct error message.
if (isTimestampOlder(comment_created_at, commit_created_at)) {

src/functions/commit-safety-checks.js:75

  • Add a unit test for the scenario where the commit signature was verified after the comment (i.e., when isTimestampOlder(commentCreatedAt, verifiedAt) returns true under inputs.commit_verification === true) to cover that guardrail.
isTimestampOlder(comment_created_at, verified_at)

@GrantBirki GrantBirki merged commit ba3af59 into main May 12, 2025
4 checks passed
@GrantBirki GrantBirki deleted the fixup/commit-safety-checks branch May 12, 2025 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant