Skip to content
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

Insert __copyright_year into cookiecutter.json #46

Merged
merged 1 commit into from
Jan 11, 2023
Merged

Conversation

seanh
Copy link
Contributor

@seanh seanh commented Jan 11, 2023

This is needed to prevent the cookiecutter from updating the copyright year in the LICENSE file to the current year every new year. See: hypothesis/cookiecutters#105


I automated the creation of these PRs using Commando. I first created a script at /tmp/insert_copyright_year.py that, when run in the root directory of a project, inserts __copyright_year into the project's cookiecutter.json file:

#!/usr/bin/env python
import json

settings = json.loads(open(".cookiecutter/cookiecutter.json", "r").read())
settings["extra_context"]["__copyright_year"] = "2022"
open(".cookiecutter/cookiecutter.json", "w").write(json.dumps(settings, indent=2))

I then ran Commando like this to create the PRs:

$ commando \
  --repos $(gh api -X GET search/repositories --paginate -f 'q=cookiecutter.json in:readme org:hypothesis archived:false' -q '.items | .[] | .full_name' | xargs) \
  --command /tmp/insert_copyright_year.py \
  --branch insert-copyright-year \
  --commit-message-file /tmp/commit_message.txt \
  --pr-title 'Insert `__copyright_year` into `cookiecutter.json`' \
  --pr-body-file /tmp/pr_body.md

Rather than typing out the long gh api command you can instead just call the bin/find_repos script from the cookiecutter repo, assuming you want to send PRs to all cookiecuttered projects: commando --repos $(bin/find_repos) --command ...

You can also run the same command on just one repo first in order to test it before sending loads of PRs. Just run commando --repos hypothesis/tox-envfile --command ....

Unfortunately there may be some incidental reformatting of cookiecutter.json (with no functional effect) due to rewriting the previously hand-edited file from Python.

This is needed to prevent the cookiecutter from updating the copyright year in
the LICENSE file to the current year every new year. See:

hypothesis/cookiecutters#105
@seanh seanh merged commit 2af98e4 into main Jan 11, 2023
@seanh seanh deleted the insert-copyright-year branch January 11, 2023 15:01
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.

None yet

1 participant