Giter Site home page Giter Site logo

xxfast / gradle-changelog-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jetbrains/gradle-changelog-plugin

0.0 2.0 0.0 246 KB

Plugin for parsing and managing the Changelog in a "keep a changelog" style.

License: Apache License 2.0

Kotlin 100.00%

gradle-changelog-plugin's Introduction

Gradle Changelog Plugin

official JetBrains project Twitter Follow Gradle Plugin Build Slack

This project requires Gradle 5.4.1 or newer

TIP: Upgrade Gradle Wrapper with ./gradlew wrapper --gradle-version 6.6.1

A Gradle plugin that provides tasks and helper methods to simplify working with a changelog that is managed in the keep a changelog style.

Table of contents

Usage

Kotlin:

import org.jetbrains.changelog.closure
import org.jetbrains.changelog.date

plugins {
    id("org.jetbrains.changelog") version "0.6.2"
}

tasks {
    // ...

    patchPluginXml {
        changeNotes(closure { changelog.getUnreleased().toHTML() })
    }
}

changelog {
    version = "${project.version}"
    path = "${project.projectDir}/CHANGELOG.md"
    header = closure { "[${project.version}] - ${date()}" }
    headerParserRegex = """\d+\.\d+""".toRegex()
    itemPrefix = "-"
    keepUnreleasedSection = true
    unreleasedTerm = "[Unreleased]"
    groups = listOf("Added", "Changed", "Deprecated", "Removed", "Fixed", "Security")
}

Groovy:

import org.jetbrains.changelog.date

plugins {
    id 'org.jetbrains.changelog' version '0.6.2'
}

apply plugin: 'org.jetbrains.changelog'

intellij {
    // ...

    patchPluginXml {
        changeNotes({ changelog.getUnreleased().toHTML() })
    }
}

changelog {
    version = "${project.version}"
    path = "${project.projectDir}/CHANGELOG.md"
    header = { "[${project.version}] - ${date()}" }
    headerParserRegex = ~/\d+\.\d+/
    itemPrefix = "-"
    keepUnreleasedSection = true
    unreleasedTerm = "[Unreleased]"
    groups = ["Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"]
}

Note: closure is a wrapper for the KotlinClosure0 class and can be used directly as following:

import org.gradle.kotlin.dsl.KotlinClosure0

changeNotes(KotlinClosure0({ changelog.getUnreleased() }))

Configuration

Plugin can be configured with the following properties set in the changelog {} closure:

Property Description Default value
groups List of groups created with a new Unreleased section. ["Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"]
header Closure that returns current header value. { "[${project.version}]" }
headerParserRegex Regex/Pattern/String used to extract version from the header string. null, fallbacks to Changelog#semVerRegex
itemPrefix Single item's prefix, allows to customise the bullet sign. "-"
keepUnreleasedSection Add Unreleased empty section after patching. true
patchEmpty Patches changelog even if no release note is provided. true
path Path to the changelog file. "${project.projectDir}/CHANGELOG.md"
unreleasedTerm Unreleased section text. "[Unreleased]"
version Current project's version. "${project.version}"

Tasks

The plugin introduces the following tasks:

Task Description
getChangelog Retrieves changelog for the specified version.
initializeChangelog Creates new changelog file with Unreleased section and empty groups.
patchChangelog Updates the unreleased section to the given version. Requires unreleased section to be present in the changelog file.

initializeChangelog

Examples

$ ./gradlew initializeChangelog
$ cat CHANGELOG.md

## [Unreleased]
### Added
- Example item

### Changed

### Deprecated

### Removed

### Fixed

### Security

getChangelog

Options

Option Description
--no-header Skips the first version header line in the output.
--unreleased Returns Unreleased change notes.

Examples

$ ./gradlew getChangelog --console=plain -q --no-header

### Added
- Initial project scaffold
- GitHub Actions to automate testing and deployment
- Kotlin support

Extension Methods

All the methods are available via the changelog extension and allow for reading the changelog file within the Gradle tasks to provide the latest (or specific) change notes.

Note: Following methods depend on the changelog extension, which is set in the Configuration build phase. To make it running properly, it's required to place the configuration before the fist usage of such a method. Alternatively, you can pass the Gradle closure to the task, which will postpone the method invocation.

get

The method returns a Changelog.Item object for the specified version. Throws MissingVersionException if the version is not available.

It is possible to specify the unreleased section with setting the ${changelog.unreleasedTerm} value.

Parameters

Parameter Type Description Default value
version String Change note version. ${changelog.version}

Examples

Kotlin:

tasks {
    patchPluginXml {
        changeNotes(closure { changelog.get("1.0.0").toHTML() })
    }
}

Groovy:

tasks {
    patchPluginXml {
        changeNotes({ changelog.get("1.0.0").toHTML() })
    }
}

getUnreleased

The method returns a Changelog.Item object for the unreleased version.

Examples

Kotlin:

tasks {
    patchPluginXml {
        changeNotes(closure { changelog.getUnreleased().toHTML() })
    }
}

Groovy:

tasks {
    patchPluginXml {
        changeNotes({ changelog.getUnreleased().toHTML() })
    }
}

getLatest

The method returns the latest Changelog.Item object (first on the list).

Examples

Kotlin:

tasks {
    patchPluginXml {
        changeNotes(closure { changelog.getLatest().toHTML() })
    }
}

Groovy:

tasks {
    patchPluginXml {
        changeNotes({ changelog.getLatest().toHTML() })
    }
}

getAll

The method returns all available Changelog.Item objects.

Examples

Kotlin:

extension.getAll().values.map { it.toText() }

Groovy:

extension.getAll().values().each { it.toText() }

has

The method checks if the given version exists in the changelog.

Examples

Kotlin:

tasks {
    patchPluginXml {
        closure { changelog.has("1.0.0") }
    }
}

Groovy:

tasks {
    patchPluginXml {
        { changelog.has("1.0.0") }
    }
}

Changelog.Item

Methods described in the above section return Changelog.Item object, which is a representation of the single changelog section for the specific version. It provides a couple of properties and methods that allow altering the output form of the change notes:

Properties

Name Type Description
version String Change note version.

Methods

Name Description Returned type
noHeader() Excludes header part. this
noHeader(Boolean) Includes/excludes header part. this
getHeader() Returns header text. String
toText() Generates Markdown output. String
toPlainText() Generates Plain Text output. String
toString() Generates Markdown output. String
toHTML() Generates HTML output. String

Gradle Closure in Kotlin DSL

To produce Gradle-specific closure in Kotlin DSL, required by some third-party plugins, like gradle-intellij-plugin it is required to wrap the Kotlin Unit with KotlinClosure0 class:

KotlinClosure0({ changelog.get() })

There is also a neater method available:

import org.jetbrains.changelog.closure

closure { changelog.get() }

Helper Methods

Name Description Returned type
closure(function: () -> T) Produces Gradle-specific Closure for Kotlin DSL. Closure<T>
date(pattern: String = "yyyy-MM-dd") Shorthand for retrieving the current date in the given format. String
markdownToHTML(input: String) Converts given Markdown content to HTML output. String
markdownToPlainText(input: String) Converts given Markdown content to Plain Text output. String

Usage Examples

gradle-changelog-plugin's People

Contributors

actions-user avatar alexpl292 avatar citizenmatt avatar firsttimeinforever avatar hsz avatar louiscad avatar yanncebron avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.