Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

feat(bump): added support for running arbitrary hooks during bump #644

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 3 commits into from
Feb 8, 2023

Conversation

skoef
Copy link
Contributor

@skoef skoef commented Dec 21, 2022

Description

To make commitizen integrate even better, new configuration keys hooks_pre_bump and hooks_post_bump were added to allow to run arbitrary commands prior to and right after running bump.

I've backported the work done by @janw and slightly adjusted it:

  • updated the patch to apply against the latest version of commitizen
  • run hooks_pre_bump hooks after the versions have been updated but before they are committed and tagged, so additional documentation can be generated with the new version or other generators can be run and staged.
  • I couldn't think of a usecase why you would want to hook into the process of generating the changelog so I completely removed this part.

Checklist

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Steps to Test This Pull Request

  1. Add something like this in your commitizen config file:
[tool.commitizen]
hooks_pre_bump = [
  "touch foo.bar",
  "git add foo.bar"
]
  1. Run cz bump and notice the Running hook output
  2. Run git show HEAD to see foo.bar is part of the latest release

Additional context

Closes: #292
Thanks to @janw to do the heavy lifting here.

@skoef skoef force-pushed the add-hooks-for-bump-command branch 2 times, most recently from 5ea9ba7 to 36d184a Compare December 21, 2022 15:52
@codecov
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Base: 97.92% // Head: 98.01% // Increases project coverage by +0.09% 🎉

Coverage data is based on head (e26293c) compared to base (619e2d2).
Patch coverage: 90.90% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #644      +/-   ##
==========================================
+ Coverage   97.92%   98.01%   +0.09%     
==========================================
  Files          35       40       +5     
  Lines        1252     1715     +463     
==========================================
+ Hits         1226     1681     +455     
- Misses         26       34       +8     
Flag Coverage Δ
unittests 98.01% <90.90%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
commitizen/commands/init.py 87.93% <84.00%> (-3.74%) ⬇️
commitizen/hooks.py 95.45% <95.45%> (ø)
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/cmd.py 100.00% <100.00%> (ø)
commitizen/commands/bump.py 97.41% <100.00%> (+0.10%) ⬆️
commitizen/commands/check.py 100.00% <100.00%> (ø)
commitizen/defaults.py 100.00% <100.00%> (ø)
commitizen/exceptions.py 100.00% <100.00%> (ø)
commitizen/__init__.py 100.00% <0.00%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Hi @skoef thanks for your contribution! I left a few questions. Also I like the name pre_bump_hooks a bit better

@@ -73,6 +83,8 @@
"version_files": ["commitizen/__version__.py", "pyproject.toml"],
"style": [["pointer", "reverse"], ["question", "underline"]],
"changelog_file": "CHANGELOG.md",
"hooks_pre_bump": ["scripts/generate_documentation.sh"],
"hooks_post_bump": ["scripts/slack_notification.sh"],
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better for us to add at least one run-able test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Lee-W I fully agree, but I'm not a real python dev myself and am not familiar with the pytest framework. If it wouldn't be too much work, could you perhaps pitch in here?

Copy link
Member

Choose a reason for hiding this comment

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

yep, I'll take a deeper look later and see how I can help on this :)

Copy link
Member

Choose a reason for hiding this comment

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

just added a test case to verify it

@skoef
Copy link
Contributor Author

skoef commented Jan 13, 2023

@Lee-W I'm not sure why specifically the windows check failed, but do you know if it has something to do with passing env to subprocess?

@skoef skoef force-pushed the add-hooks-for-bump-command branch from 103def9 to 24f0f27 Compare January 18, 2023 22:20
@Lee-W Lee-W self-assigned this Jan 19, 2023
@Lee-W Lee-W force-pushed the add-hooks-for-bump-command branch from 24f0f27 to 90bed7c Compare January 21, 2023 02:32
@Lee-W
Copy link
Member

Lee-W commented Jan 21, 2023

@Lee-W I'm not sure why specifically the windows check failed, but do you know if it has something to do with passing env to subprocess?

It seems to be something related to type annotation. I just fixed it and rebase the latest master to your branch.

@ysndr
Copy link

ysndr commented Jan 23, 2023

@Lee-W
https://github.com/commitizen-tools/commitizen/compare/103def9d6c290afe1b0daca359581cefadce11ce..24f0f27ad7ecf1216d309ff8d7d1690528fbf4e7

this got lost in your rebase, breaking environment support again
@skoef can you cherry pick this in again?

@skoef
Copy link
Contributor Author

skoef commented Jan 23, 2023

@ysndr should be fixed now

@Lee-W
Copy link
Member

Lee-W commented Jan 23, 2023

@skoef would it be possible for you to do rebase from the master branch (i.e. using git rebase -i master)? Otherwise, we won't be able to merge it. Thanks!

To make commitizen integrate even better, new configuration keys pre_bump_hooks and post_bump_hooks were added to allow to run arbitrary commands prior to and right after running bump

Closes: commitizen-tools#292
@skoef skoef force-pushed the add-hooks-for-bump-command branch from 70494a3 to 26b38be Compare January 23, 2023 17:25
@skoef
Copy link
Contributor Author

skoef commented Jan 23, 2023

@Lee-W done!

ysndr added a commit to flox/runix that referenced this pull request Jan 26, 2023
Uses PR'd fork with support for `post_bump_hooks` [1]

[1]: commitizen-tools/commitizen#644
ysndr added a commit to flox/runix that referenced this pull request Jan 26, 2023
Uses PR'd fork with support for `post_bump_hooks` [1]

[1]: commitizen-tools/commitizen#644
@Lee-W Lee-W added wait-for-merge and removed needs: test-case new to add test case to prove the functionality pr-status: wait-for-modification labels Jan 28, 2023
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Thanks @skoef for your contribution! @woile I've added a few test cases to this PR and I plan to merge it these days. Let me know if you want to check. Thanks~

@skoef
Copy link
Contributor Author

skoef commented Feb 8, 2023

@woile could you please take a look?

@woile
Copy link
Member

woile commented Feb 8, 2023

LGTM

@Lee-W Lee-W merged commit da0ea0e into commitizen-tools:master Feb 8, 2023
skoef added a commit to skoef/commitizen that referenced this pull request Feb 23, 2023
During development of commitizen-tools#644, merging the hook environment variables with existing OS variables broke. This commit fixes that.
skoef added a commit to skoef/commitizen that referenced this pull request Feb 23, 2023
During development of commitizen-tools#644, merging the hook environment variables with existing OS variables broke. This commit fixes that.
skoef added a commit to skoef/commitizen that referenced this pull request Feb 23, 2023
During development of commitizen-tools#644, merging the hook environment variables with existing OS variables broke. This commit fixes that.
skoef added a commit to skoef/commitizen that referenced this pull request Feb 23, 2023
During development of commitizen-tools#644, merging the hook environment variables with existing OS variables broke.
skoef added a commit to skoef/commitizen that referenced this pull request Feb 23, 2023
During development of commitizen-tools#644, merging the hook environment variables with existing OS variables broke.
Lee-W pushed a commit that referenced this pull request Feb 25, 2023
During development of #644, merging the hook environment variables with existing OS variables broke.
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.

Add ability to run arbitrary hooks pre/post version bump
4 participants