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

org.jetbrains.changelog.Changelog.Item.plus doesn't keep withHeader and other boolean flags #179

Closed
rybak opened this issue Jul 7, 2023 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@rybak
Copy link

rybak commented Jul 7, 2023

Describe the bug
I'm trying to add additional list items to <change-notes> in the Gradle task patchPluginXml of Gradle IntelliJ Plugin. I'm trying to modify output of the Changelog Plugin. Unfortunately, function org.jetbrains.changelog.Changelog.Item.plus loses the value of withHeader and other boolean flags, which were set up in the call chain before plus() is invoked.

Below is a minimal example that doesn't require Gradle IntelliJ Plugin.

To Reproduce
This is code, slightly modified from IntelliJ Platform Plugin Template. Two methods withHeader and withEmptySections are used as an example – these are just the two boolean flags that I've checked, others are probably affected in the same way.

  1. Put the following code at the top level of the build.gradle.kts, for simplicity:
with(project.changelog) {
	val extraItems = mapOf(
		"Extra section" to setOf("[Extra link](https://example.org)")
	)
	println(renderItem(
		getUnreleased()
			.withHeader(false)
			.withEmptySections(true)
			.plus(Changelog.Item("", "", "", false, extraItems, "", "")),
		Changelog.OutputType.MARKDOWN
	))
}
  1. Put the following Markdown text in CHANGELOG.md:
# Changelog

## [Unreleased]

### Added
- Example added item, "Changed" is empty

### Changed

## [0.2.0-alpha]

[Unreleased]: https://github.com/rybak/intellij-copy-commit-reference/compare/v0.2.0-alpha...HEAD
[0.2.0-alpha]: https://github.com/rybak/intellij-copy-commit-reference/compare/v0.1.0-alpha.1...v0.2.0-alpha
  1. Run ./gradlew

Actual behavior
Header ## [Unreleased] is printed in the log, empty section is absent:

## [Unreleased]

### Added
- Example added item, "Changed" is empty

### Extra section
- [Extra link](https://example.org)

[Unreleased]: https://github.com/rybak/intellij-copy-commit-reference/compare/v0.2.0-alpha...HEAD

Expected behavior
Header is not printed in the log, empty section is present:

### Added
- Example added item, "Changed" is empty

### Changed

### Extra section
- [Extra link](https://example.org)

[Unreleased]: https://github.com/rybak/intellij-copy-commit-reference/compare/v0.2.0-alpha...HEAD

Environment:

  • Gradle Changelog Plugin Version 2.1.0
  • Gradle Version 8.1.1

Additional context

  • Workaround – call with* functions after the plus function:
with(project.changelog) {
	val extraItems = mapOf(
		"Extra section" to setOf("[Extra link](https://example.org)")
	)
	println(renderItem(
		getUnreleased()
			.plus(Changelog.Item("", "", "", false, extraItems, "", ""))
			.withHeader(false)
			.withEmptySections(true),
		Changelog.OutputType.MARKDOWN
	))
}
@rybak rybak added the bug Something isn't working label Jul 7, 2023
@hsz
Copy link
Member

hsz commented Jul 7, 2023

Thanks for reporting, @rybak!
Indeed, an incorrect copy was picked. Fixed with this workaround: 992281e

@hsz hsz closed this as completed Jul 7, 2023
@hsz hsz added this to the 2.1.1 milestone Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants