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

Allow replacing part of changelogs or commit message using replace_command #611

Open
1 task done
Cyclonit opened this issue Apr 13, 2024 · 6 comments
Open
1 task done
Assignees
Labels
feature/request New feature or request

Comments

@Cyclonit
Copy link

Cyclonit commented Apr 13, 2024

Is there an existing issue or pull request for this?

  • I have searched the existing issues and pull requests

Feature description

Currently the behaviour of replace and replace_command are inconsistent. replace will replace all matches of pattern with a given string, whereas replace_command replaces the entire string as long as at least one match was found.

See TextProcessor.run:228 for references.

For example, the following changelog.postprocessor will replace the entire changelog instead of only the matched occurrences of <REPO>.

postprocessors = [
  { pattern = '<REPO>', replace_command = 'echo "https://github.com/orhun/git-cliff"' }
]

Desired solution

This issue is intended to serve as a place to discuss possible solutions.

Alternatives considered

None

Additional context

No response

@Cyclonit Cyclonit added the feature/request New feature or request label Apr 13, 2024
@Cyclonit
Copy link
Author

The inconsistent behaviour in TextProcessor.run:228 makes coming up with a non-breaking and clean solution difficult. Thus I think we need to decide whether we are willing to do a breaking change. If we are, we could change replace_command to replace each match like replace does.

The switch between the old and new behaviour could be reintroduced by having an alternative match to the current pattern. If pattern is used, the entire string is replaced. If match is used, only the matches are replaced.

@orhun orhun changed the title allow replacing part of changelogs or commit message using replace_command Allow replacing part of changelogs or commit message using replace_command Apr 13, 2024
@orhun
Copy link
Owner

orhun commented Apr 13, 2024

Let's not make a breaking change with this one. Can you share some config snippets / usage examples about how the new match option will look like? I would say let's agree on something simple and document both behaviors.

@davidwallis3101
Copy link

definitely interested in this functionality as I would like to be able to switch out the repo url dynamically from our build system and would rather not have to call another script post changelog generation. I understand the desire to not to introduce a breaking change but surely that's the point of semver. Alternatively adding an additional parameter, or a different replace_ option makes it non breaking but allows introduction of the requested functionality?

And obv supporting env var / shell commands as replace_command does would be key too.

@Cyclonit
Copy link
Author

Cyclonit commented Apr 29, 2024

I've done some more thinking on this since opening the issue, and I strongly believe that a breaking change would be the best cause of action. The inconsistent behaviour of replace and replace_command is difficult to reason for. Any attempts I have made to introduce additional parameters that would allow replacing just part of the changelog using external commands were unsuccessful.

The current behaviour of replace_command is needed for use cases like running the entire changelog through external tools like typos. This functionality could easily be achieved by changing the pattern used from .* to (?s:.*). The flag s allows . to match newlines, thus making the pattern match the entire string.

@Cyclonit
Copy link
Author

Cyclonit commented May 3, 2024

@orhun, could you chime in on this? If a breaking changes is permissible, I'd give implementing it a shot.

@orhun
Copy link
Owner

orhun commented May 6, 2024

I gave this another thought and I guess making a breaking change is tolerable for the sake of having a more consistent functionality. @Cyclonit sure, go ahead!

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
Projects
None yet
Development

No branches or pull requests

3 participants