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

Change scope with commit_parsers #50

Closed
tlackemann opened this issue Jan 21, 2022 · 5 comments · Fixed by #94
Closed

Change scope with commit_parsers #50

tlackemann opened this issue Jan 21, 2022 · 5 comments · Fixed by #94
Assignees
Labels
feature/request New feature or request good first issue Good for newcomers

Comments

@tlackemann
Copy link

tlackemann commented Jan 21, 2022

Is your feature request related to a problem? Please describe.
In a monorepo, I that have a folder with the name "www", however, since I am using git-cliff to generate a public-facing changelog, I would wish for this to be displayed as "Application" when generated.

I am using template replace functions to replace "www" with "Application" but would like the ability to change this in the commit_parsers.

Describe the solution you'd like
commit_parsers should allow changing of the scope on-demand. For example:

commit_parsers = [
  { message = "(www)", scope = "Application" }
]

Describe alternatives you've considered
N/A

Additional context
Thanks for an awesome project!

@tlackemann tlackemann added the feature/request New feature or request label Jan 21, 2022
@tlackemann
Copy link
Author

I took a look through the code and have an idea of how this might be implemented. Are you interested in a PR to address this? I'm open to advice/guidance on how you might like to see this implemented.

@orhun
Copy link
Owner

orhun commented Jan 23, 2022

Hello, thanks for the nice suggestion! It definitely makes sense to support overriding the scope of commits.

I took a look through the code and have an idea of how this might be implemented. Are you interested in a PR to address this? I'm open to advice/guidance on how you might like to see this implemented.

Sure, that'd be nice. The current workflow is:

  1. If a commit parser matches a commit, it sets the group and scope (default_scope):

self.group = parser.group.as_ref().cloned();
self.scope = parser.default_scope.as_ref().cloned();

  1. While serializing, scope is used if conventional commit parser returns an empty (None) scope:

&conv.scope().map(|v| v.as_str()).or(self.scope.as_deref()),

So first, I'd rename Commit::scope to Commit::default_scope to avoid confusion in the future 😄 Then add scope: Option<String> to both Commit and CommitParser structs and set the scope in Commit::parse.

And then while serializing, you can construct a logic like this:

commit.serialize_field(
    "scope",
    &self.scope.as_deref().or_else(|| conv.scope().map(|v| v.as_str())).or(self.default_scope.as_deref())
)?;

This will first check if there is a custom scope set, then tries to get the scope from conventional parser and then uses the default scope as a last resort.

This is how I'd implement it. Unfortunately, having default_scope makes things a bit complicated since everything is handled during the serialization. Let me know if you have any other ideas and feel free to submit a PR! 🐻

@tlackemann
Copy link
Author

Thanks for the thoughtful reply! No promises on a timeline but I'll take a crack at this soon and see if I can't get something pushed and reviewed.

Thank you again!

@orhun
Copy link
Owner

orhun commented Jan 29, 2022

No problem! Let me know if there is something that I can help with.

@orhun
Copy link
Owner

orhun commented Jun 9, 2022

I will be working on this for the upcoming release if no one wants to dive into it 🐻 LMK

@orhun orhun added the good first issue Good for newcomers label Jun 9, 2022
ofsahof added a commit to ofsahof/git-cliff that referenced this issue Jun 14, 2022
ofsahof added a commit to ofsahof/git-cliff that referenced this issue Jun 14, 2022
@orhun orhun closed this as completed in #94 Jun 22, 2022
orhun added a commit that referenced this issue Jun 22, 2022
* fix: issue #50

* chore: Check some lints and styles

* docs: add scope example

* chore: fix some typos in cargo docs

* style: rerun cargo fmt and cargo lint

* style(config): update wording in the comment

* test(config): add tests about specifying the scope

* test(fixture): add test fixture for custom scope

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/request New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants