Skip to content

Instantly share code, notes, and snippets.

@matshou
Last active March 20, 2021 09:07
Show Gist options
  • Save matshou/540f0c59633cd0f857a74848be7ccfc3 to your computer and use it in GitHub Desktop.
Save matshou/540f0c59633cd0f857a74848be7ccfc3 to your computer and use it in GitHub Desktop.
Generates project changelog using github-changelog-generator.
/**
* Generates project changelog using github-changelog-generator
* https://github.com/github-changelog-generator/github-changelog-generator
*/
tasks.register("generateChangelog", Exec.class) {
it.description 'Generate a project changelog.'
it.group 'documentation'
def commandArgs = [
// owner of target GitHub repository
'-u', project.ext.get('repo.owner'),
/*
* name of project on GitHub */
'-p', project.ext.get('repo.name'),
/*
* only issues with the specified labels will be included in the changelog
* this means that issues that are included HAVE to have at least one of these labels */
'--include-labels', project.ext.has('cg.includeLabels') ?
project.ext.get('includeLabels') : 'bug,enhancement,breaking,deprecated',
/*
* define all labels you want excluded from the changelog */
'--exclude-labels', project.ext.has('cg.excludeLabels') ?
project.ext.get('excludeLabels') : 'dev,wontfix,workflow,question,documentation,invalid',
/*
* do not include issue without labels */
'--no-issues-wo-labels', 'false'
]
// Changelog will start after specified tag
if (project.ext.has('cg.sinceTag')) {
commandArgs += [ '--since-tag', project.ext.get('cg.sinceTag') ]
}
// Output file. To print to STDOUT instead, use blank as path.
// Default value: CHANGELOG.md
if (project.ext.has('cg.output')) {
commandArgs += [ '--output', project.ext.get('cg.output') ]
}
// Generate log from unreleased closed issues only or
// add to log unreleased closed issues. Default is 'true'
if (project.ext.has('cg.unreleased')) {
commandArgs += [project.ext.get('cg.unreleased') as boolean ? '--unreleased' : '--no-unreleased']
}
else commandArgs += ['--no-unreleased' ]
// Set up custom header label. Default is "# Changelog".
if (project.ext.has('cg.header')) {
commandArgs += [ '--header-label', project.ext.get('cg.header') ]
}
// this args will be displayed in log (avoid showing token)
def displayArgs = commandArgs.toListString()
// generator will first check for token in environment variables
if (!providers.environmentVariable('CHANGELOG_GITHUB_TOKEN').forUseAtConfigurationTime().present)
{
def githubToken = project.ext.has('cg.token') ? project.ext.get('cg.token') : null
if (githubToken != null) {
commandArgs += [ '--token', githubToken ]
}
}
//noinspection GroovyAssignabilityCheck
def command = new ArrayList<String>([ 'bundle', 'exec', 'github_changelog_generator' ] + commandArgs)
it.commandLine = (project.ext.osName == "Windows") ? ['cmd', '/c' ] + command : command
it.doFirst {
logger.info('Generating changelog with arguments: ' + displayArgs)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment