jmongard / Git.SemVersioning.Gradle

Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.
https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin
Apache License 2.0
38 stars 4 forks source link

printChangeLog configuration causing error #59

Closed j-choi1 closed 2 months ago

j-choi1 commented 3 months ago

Without printChangeLog configuration, the task is working fine. But with any kind of printChangeLog configuration, it is causing errors. I copied the exact printChangeLog configuration from the docs.

Using the latest plugin version: 0.12.6

Example 1:

build.gradle:

semver {
    groupVersionIncrements = false
}

semver {
    changeLogTexts = PlainChangeLogTexts
}

error:

A problem occurred evaluating root project 'semantic-test'.
> Could not get unknown property 'PlainChangeLogTexts' for extension 'semver' of type git.semver.plugin.gradle.GitSemverPluginExtension.

Example 2:

build.gradle:

semver {
    groupVersionIncrements = false
}

semver {
    changeLogTexts {
        headerTexts = mutableMapOf(
            "fix" to "### Bug Fixes \uD83D\uDC1E",
            "feat" to "### New Features \uD83C\uDF89",
            "test" to "### Tests ✅",
            "docs" to "### Documentation \uD83D\uDCD6",
            "deps" to "### Dependency Updates \uD83D\uDE80",
            "build" to "### Build \uD83D\uDC18 & CI ⚙\uFE0F",
            "ci" to "### Build \uD83D\uDC18 & CI ⚙\uFE0F",
            "chore" to "### Chores \uD83D\uDD27",
            "perf" to "### Performance Enhancements ⚡",
            "refactor" to "### Refactorings \uD83D\uDE9C"
        )
        header = "## What's Changed" // Set your custom header text
        breakingChange = "### Breaking Changes 🛠" // Set your custom breaking change text
        otherChange = "### Other Changes \uD83D\uDCA1" // Set your custom other change text
    }
}

error:

A problem occurred evaluating root project 'semantic-test'.
> No signature of method: java.lang.String.to() is applicable for argument types: (String, String) values: [### Bug Fixes ?, feat] 
  Possible solutions: tr(java.lang.CharSequence, java.lang.CharSequence), trim(), toURI(), md5(), toSet(), toURI()
jmongard commented 3 months ago

Hi, The PlainChangeLogTexts is in the git.semver.plugin.changelog package. To use it add an import to the top of the buildfile:

import git.semver.plugin.changelog.PlainChangeLogTexts
...
semver {
    changeLogTexts = PlainChangeLogTexts
}

or use qualified name:

semver {
    changeLogTexts = git.semver.plugin.changelog.PlainChangeLogTexts
}

I will clarify this in the documentation

For the second case headerTexts is set as readonly. To replace all texts you can replace all values using putAll:

semver {
    changeLogTexts {
       //Replace many texts (kotlin syntax):
       headerTexts.putAll(mapOf(
            "fix" to "### Bug Fixes",
            "feat" to "### New Features",
            "test" to "### Tests",
            "docs" to "### Documentation",
            "deps" to "### Dependency Updates",
            "build" to "### Build & CI",
            "ci" to "### Build & CI",
            "chore" to "### Chores",
            "perf" to "### Performance Enhancements",
            "refactor" to "### Refactorings"
        ))

        //Replace many texts (groovy syntax):
        it.headerTexts.putAll([
            "fix": "### Bug Fixes",
            "feat": "### New Features",
            "test": "### Tests",
            "docs": "### Documentation",
            "deps": "### Dependency Updates",
            "build": "### Build",
            "ci": "### Build",
            "chore": "### Chores ",
            "perf": "### Performance Enhancements",
            "refactor": "### Refactorings"
        ])

        //Or a single text:
        headerTexts["fix"] = "### Fixes"
  }
}
j-choi1 commented 3 months ago

I have tried doing both the PlainChangeLogTexts import and qualified name but I get the error below:

A problem occurred evaluating root project 'semantic-test'.
> Cannot cast object 'class git.semver.plugin.changelog.PlainChangeLogTexts' with class 'java.lang.Class' to class 'git.semver.plugin.changelog.ChangeLogTexts'

I am also still having issue with headerTexts. I have tried the kotlin syntax, groovy syntax, and also the single text you provided but I am getting the error below:

A problem occurred evaluating root project 'semantic-test'.
  > Could not get unknown property 'headerTexts' for extension 'semver' of type git.semver.plugin.gradle.GitSemverPluginExtension.
jmongard commented 3 months ago

Ok, The syntax in the documentation only works using Kotlin DSL.

I think this works from Groovy DSL:

semver {
    changeLogTexts = git.semver.plugin.changelog.PlainChangeLogTexts.INSTANCE
    changeLogTexts.header = "New Header"
    changeLogTexts.headerTexts.putAll([
        "fix" : "## FIX"
    ])

    //Using it also works:
    changeLogTexts {
        it.header = "# Release"
        it.headerTexts["wip"]="### Work in progress"
        it.headerTexts.putAll([
                "fix" : "## FIX",
                "feat" : "## FEATURE"
        ])
    }
}
jmongard commented 3 months ago

Yes, You can set the header text to empty string and it will skip the category e.g.

semver { changeLogTexts { it.headerTexts["wip"]="" it.headerTexts["test"]="" it.headerTexts["deps"]="" it.headerTexts["build"]="" it.headerTexts["refactor"]="" } }

j-choi1 commented 3 months ago

Thanks that worked except for the "Other Changes" section. I have the following below and the Other Changes header text got removed but the commits for that are still in the changelog:

semver {
    changeLogTexts {
        it.otherChange = ""
    }
}
jmongard commented 3 months ago

The change log can be customized in many ways but it is probably not that easy. It would be a good idea be able to exclude the other changes in the same way. I will look into it.

There are a simple changelog defined that you can use that does not include other changes. It does not include hashes so it might be too simple.

import git.semver.plugin.changelog.ChangeLogFormat

semver {
    changeLogFormat = ChangeLogFormat.INSTANCE.simpleChangeLog

    // Add any type you want to include (fix/feat/breaking changes is the only ones included by default)
    changeLogTexts.typesOrder.addAll(["build", "ci"]) 
}
jmongard commented 3 months ago

in version 0.12.9 you can now remove "Other changes" from the default changelog template by setting the header to "":

semver {
    changeLogTexts.otherChange = ""
}