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

feat(bump): functionality to add build-metadata to version string #949

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

xeor
Copy link

@xeor xeor commented Dec 28, 2023

Description

A way to add build-metadata from the cli using parameters, including being able to change them at as you want without disturbing the other version-logic in commitizen.

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

Expected behavior

Should add additional functionality without disturbing anything.

Steps to Test This Pull Request

  1. cz bump --build-metadata a.b.c
  2. cz bump
  3. cz bump --build-metadata alongmetadatastring
  4. cz bump

Additional context

Closes: #945

Copy link

codecov bot commented Dec 29, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (120d514) 97.33% compared to head (916a0c6) 97.40%.
Report is 178 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #949      +/-   ##
==========================================
+ Coverage   97.33%   97.40%   +0.06%     
==========================================
  Files          42       55      +13     
  Lines        2104     2388     +284     
==========================================
+ Hits         2048     2326     +278     
- Misses         56       62       +6     
Flag Coverage Δ
unittests 97.40% <100.00%> (+0.06%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xeor
Copy link
Author

xeor commented Dec 29, 2023

I tried to not "disturb" anything already implemented with "local version" already, but I had to wrap some changelog version logic inside a strip_local_version because versions diffed too much from eachothers. I think stripping out everything after + where I did is fine..?

@woile
Copy link
Member

woile commented Dec 29, 2023

Looks good! I'll wait a bit more for reviews, probably next year I'll get to merge it

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.

Sorry for taking so long. This looks great! Let's merge it

@Lee-W
Copy link
Member

Lee-W commented Feb 10, 2024

@xeor I just noticed there's some conflict. Could you please help us rebase it and resolve the conflict? Once it's done, I think we're good to merge it.

@Lee-W Lee-W added pr-status: wait-for-modification pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check and removed pr-status: wait-for-review labels Feb 10, 2024
@xeor
Copy link
Author

xeor commented Feb 11, 2024

Tried to rebase, but there are some changes upstream that the formatter doesnt like and pre-commit hook changes.

diff --git a/commitizen/cz/base.py b/commitizen/cz/base.py
index 14d9e5a..d9bf5ea 100644
--- a/commitizen/cz/base.py
+++ b/commitizen/cz/base.py
@@ -37,9 +37,9 @@ class BaseCommitizen(metaclass=ABCMeta):
     change_type_order: list[str] | None = None

     # Executed per message parsed by the commitizen
-    changelog_message_builder_hook: None | (Callable[[dict, git.GitCommit], dict]) = (
-        None
-    )
+    changelog_message_builder_hook: None | (
+        Callable[[dict, git.GitCommit], dict]
+    ) = None

     # Executed only at the end of the changelog generation
     changelog_hook: Callable[[str, str | None], str] | None = None
diff --git a/commitizen/cz/exceptions.py b/commitizen/cz/exceptions.py
index d74f39a..2597b68 100644
--- a/commitizen/cz/exceptions.py
+++ b/commitizen/cz/exceptions.py
@@ -1,4 +1,6 @@
-class CzException(Exception): ...
+class CzException(Exception):
+    ...


-class AnswerRequiredError(CzException): ...
+class AnswerRequiredError(CzException):
+    ...
diff --git a/tests/test_changelog.py b/tests/test_changelog.py
index 879443f..8aef10a 100644
--- a/tests/test_changelog.py
+++ b/tests/test_changelog.py
@@ -1298,9 +1298,9 @@ def test_render_changelog_with_changelog_message_builder_hook(
     gitcommits, tags, any_changelog_format: ChangelogFormat
 ):
     def changelog_message_builder_hook(message: dict, commit: git.GitCommit) -> dict:
-        message["message"] = (
-            f"{message['message']} [link](github.com/232323232) {commit.author} {commit.author_email}"
-        )
+        message[
+            "message"
+        ] = f"{message['message']} [link](github.com/232323232) {commit.author} {commit.author_email}"
         return message

     parser = ConventionalCommitsCz.commit_parser
diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py
index 20a17b3..9f3556f 100644
--- a/tests/test_cz_customize.py
+++ b/tests/test_cz_customize.py
@@ -498,8 +498,7 @@ def test_answer_unicode(config_with_unicode):
     }
     message = cz.message(answers)
     assert (
-        message
-        == "✨ feature: this feature enables customization through a config file"
+        message == "✨ feature: this feature enables customization through a config file"
     )

     cz = CustomizeCommitsCz(config_with_unicode)
@@ -575,8 +574,7 @@ def test_commit_parser(config):
 def test_commit_parser_unicode(config_with_unicode):
     cz = CustomizeCommitsCz(config_with_unicode)
     assert (
-        cz.commit_parser
-        == "^(?P<change_type>✨ feature|🐛 bug fix):\\s(?P<message>.*)?"
+        cz.commit_parser == "^(?P<change_type>✨ feature|🐛 bug fix):\\s(?P<message>.*)?"
     )

shall I ignore them or wait for you guys to fix the formatting upstream?

@Lee-W
Copy link
Member

Lee-W commented Feb 13, 2024

Tried to rebase, but there are some changes upstream that the formatter doesnt like and pre-commit hook changes.

diff --git a/commitizen/cz/base.py b/commitizen/cz/base.py
index 14d9e5a..d9bf5ea 100644
--- a/commitizen/cz/base.py
+++ b/commitizen/cz/base.py
@@ -37,9 +37,9 @@ class BaseCommitizen(metaclass=ABCMeta):
     change_type_order: list[str] | None = None

     # Executed per message parsed by the commitizen
-    changelog_message_builder_hook: None | (Callable[[dict, git.GitCommit], dict]) = (
-        None
-    )
+    changelog_message_builder_hook: None | (
+        Callable[[dict, git.GitCommit], dict]
+    ) = None

     # Executed only at the end of the changelog generation
     changelog_hook: Callable[[str, str | None], str] | None = None
diff --git a/commitizen/cz/exceptions.py b/commitizen/cz/exceptions.py
index d74f39a..2597b68 100644
--- a/commitizen/cz/exceptions.py
+++ b/commitizen/cz/exceptions.py
@@ -1,4 +1,6 @@
-class CzException(Exception): ...
+class CzException(Exception):
+    ...


-class AnswerRequiredError(CzException): ...
+class AnswerRequiredError(CzException):
+    ...
diff --git a/tests/test_changelog.py b/tests/test_changelog.py
index 879443f..8aef10a 100644
--- a/tests/test_changelog.py
+++ b/tests/test_changelog.py
@@ -1298,9 +1298,9 @@ def test_render_changelog_with_changelog_message_builder_hook(
     gitcommits, tags, any_changelog_format: ChangelogFormat
 ):
     def changelog_message_builder_hook(message: dict, commit: git.GitCommit) -> dict:
-        message["message"] = (
-            f"{message['message']} [link](github.com/232323232) {commit.author} {commit.author_email}"
-        )
+        message[
+            "message"
+        ] = f"{message['message']} [link](github.com/232323232) {commit.author} {commit.author_email}"
         return message

     parser = ConventionalCommitsCz.commit_parser
diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py
index 20a17b3..9f3556f 100644
--- a/tests/test_cz_customize.py
+++ b/tests/test_cz_customize.py
@@ -498,8 +498,7 @@ def test_answer_unicode(config_with_unicode):
     }
     message = cz.message(answers)
     assert (
-        message
-        == "✨ feature: this feature enables customization through a config file"
+        message == "✨ feature: this feature enables customization through a config file"
     )

     cz = CustomizeCommitsCz(config_with_unicode)
@@ -575,8 +574,7 @@ def test_commit_parser(config):
 def test_commit_parser_unicode(config_with_unicode):
     cz = CustomizeCommitsCz(config_with_unicode)
     assert (
-        cz.commit_parser
-        == "^(?P<change_type>✨ feature|🐛 bug fix):\\s(?P<message>.*)?"
+        cz.commit_parser == "^(?P<change_type>✨ feature|🐛 bug fix):\\s(?P<message>.*)?"
     )

shall I ignore them or wait for you guys to fix the formatting upstream?

hmmm... just ignore the formating issue and let me resolve it 😄

@xeor
Copy link
Author

xeor commented Feb 15, 2024

I think it is ready now @Lee-W . There are 3 pr-status labels, but I guess it's back in the queue? :)

@Lee-W
Copy link
Member

Lee-W commented Feb 16, 2024

@xeor It seems there's a conflict between this branch and the main branch. We might need your help on that. You can do it with the following commands.

git remote add upstream https://github.com/commitizen-tools/commitizen
git checkout master
git pull upstream master
git checkout issue-945
git rebase -i master

@xeor
Copy link
Author

xeor commented Feb 16, 2024

Thanks @Lee-W , I think it is finally mergable 👍

@Lee-W
Copy link
Member

Lee-W commented Feb 17, 2024

Thanks @Lee-W , I think it is finally mergable 👍

Awesome work! Let's merge it!

@Lee-W Lee-W merged commit 981065e into commitizen-tools:master Feb 17, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check pr-status: wait-for-modification pr-status: wait-for-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify build metadata in tags
3 participants