Skip to content

feat: Add Pre-Commit Copyright Date Check & Fix Automation#583

Open
SteinGabriel wants to merge 4 commits intodevelopfrom
copyright-date-automation
Open

feat: Add Pre-Commit Copyright Date Check & Fix Automation#583
SteinGabriel wants to merge 4 commits intodevelopfrom
copyright-date-automation

Conversation

@SteinGabriel
Copy link
Contributor

Summary

Automates Ping-owned copyright year updates so developers no longer need
to hand-edit headers. A pre-commit hook fixes and re-stages any staged
files with stale Ping copyright years before lint and build checks run.

Adds a pre-commit hook that automatically keeps Ping-owned copyright
year headers up-to-date in staged files, removing the need for manual
year updates on every change.

Changes

File Change
tools/copyright/sync-header-years.mjs New script — fix/check logic
tools/copyright/sync-header-years.test.mjs 9 unit tests (Node built-in runner)
.husky/pre-commit Prepend copyright sync step
package.json Add copyright:sync and copyright:check scripts

How it works

  1. On git commit, the pre-commit hook reads the list of staged files.
  2. For each file it finds a stale Ping copyright year, it rewrites the
    header in place and re-stages the file.
  3. If any staged file has a Ping copyright header with no recognisable
    year at all
    , the commit is aborted with an error listing the incorrect files.
  4. All other files (non-Ping headers, binary, unreadable) are skipped.

Supported formats updated automatically:

Copyright 2020 Ping Identity.Copyright 2020 - 2026 Ping Identity.
Copyright 2020-2024 Ping Identity.Copyright 2020 - 2026 Ping Identity.
Copyright 2020-2026 Ping Identity.Copyright 2020 - 2026 Ping Identity.
© Copyright 2020 - 2024 PingIdentity.© Copyright 2020 - 2026 Ping Identity.
Copyright (c) 2023 - 2024 Ping Identity Corporation.Copyright (c) 2023 - 2026 Ping Identity Corporation.

Testing

  node --test tools/copyright/sync-header-years.test.mjs

Known gaps / follow-ups

  • CI enforcement (copyright:check on PRs) deferred to a follow-up.

Rollout notes

  • No CI step added — pre-commit only for now.
  • Removing the hook does not break anything; it is additive only.

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

⚠️ No Changeset found

Latest commit: b780c49

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the root label Mar 17, 2026
@nx-cloud
Copy link

nx-cloud bot commented Mar 17, 2026

View your CI Pipeline Execution ↗ for commit b780c49

Command Status Duration Result
nx affected -t build lint test docs e2e-ci ✅ Succeeded <1s View ↗
nx-cloud record -- nx format:check --verbose ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-18 19:01:22 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 17, 2026

Open in StackBlitz

pnpm add https://pkg.pr.new/ForgeRock/forgerock-javascript-sdk/@forgerock/javascript-sdk@583
pnpm add https://pkg.pr.new/ForgeRock/forgerock-javascript-sdk/@forgerock/ping-protect@583
pnpm add https://pkg.pr.new/ForgeRock/forgerock-javascript-sdk/@forgerock/token-vault@583

commit: b780c49

Copy link
Contributor

@ancheetah ancheetah left a comment

Choose a reason for hiding this comment

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

This is amazing. Thank you for doing this Gabriel! Will save us a lot of time. Just left a comment on the tests.

Comment on lines +7 to +9
const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */';
const actual = updateCopyrightYears(input, 2026);
assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */');
Copy link
Contributor

Choose a reason for hiding this comment

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

In a lot of these tests the input looks identical to the value being asserted. For example, in this test shouldn't the input have something like years 2020 - 2025 before it is updated?

Copy link
Contributor Author

@SteinGabriel SteinGabriel Mar 18, 2026

Choose a reason for hiding this comment

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

I could swear I had this right and I was loosing my mind wondering why my input date updates weren't showing up, until I realized that the pre-commit script was actually "fixing" the input date header in the test files, making it the same as the value being asserted. lol
Anyways, I added a check to prevent it from running on specific paths, such as test files. Thanks for pointing it out!

@SteinGabriel SteinGabriel force-pushed the copyright-date-automation branch from 57fc8b5 to 2c7f8b3 Compare March 18, 2026 16:17
Copy link
Contributor

@ryanbas21 ryanbas21 left a comment

Choose a reason for hiding this comment

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

This is cool. I'd like us to weigh this approach versus https://www.npmjs.com/package/eslint-plugin-license-header as an eslint rule with auto fixing.

Could you, when available to, maybe present the differences / overlap / benefits to each approach? Maybe theres a better eslint rule out there also, I just happened to find this one and it seems up to date / maintained.

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

Labels

Development

Successfully merging this pull request may close these issues.

3 participants