|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require 'bundler' |
4 | | -require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? |
| 4 | +require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus' |
5 | 5 | require 'puppetlabs_spec_helper/rake_tasks' |
6 | 6 | require 'puppet-syntax/tasks/puppet-syntax' |
7 | | -require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? |
8 | | -require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? |
| 7 | +require 'github_changelog_generator/task' if Gem.loaded_specs.key? 'github_changelog_generator' |
| 8 | +require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' |
9 | 9 |
|
10 | 10 | def changelog_user |
11 | | - return unless Rake.application.top_level_tasks.include? 'changelog' |
12 | | - |
13 | | - returnVal = nil || JSON.parse(File.read('metadata.json'))['author'] |
14 | | - raise 'unable to find the changelog_user in .sync.yml, or the author in metadata.json' if returnVal.nil? |
15 | | - |
| 11 | + return unless Rake.application.top_level_tasks.include? "changelog" |
| 12 | + returnVal = nil || JSON.load(File.read('metadata.json'))['author'] |
| 13 | + raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? |
16 | 14 | puts "GitHubChangelogGenerator user:#{returnVal}" |
17 | 15 | returnVal |
18 | 16 | end |
19 | 17 |
|
20 | 18 | def changelog_project |
21 | | - return unless Rake.application.top_level_tasks.include? 'changelog' |
| 19 | + return unless Rake.application.top_level_tasks.include? "changelog" |
22 | 20 |
|
23 | 21 | returnVal = nil |
24 | 22 | returnVal ||= begin |
25 | | - metadata_source = JSON.parse(File.read('metadata.json'))['source'] |
26 | | - metadata_source_match = metadata_source&.match(%r{.*/([^/]*?)(?:\.git)?\Z}) |
| 23 | + metadata_source = JSON.load(File.read('metadata.json'))['source'] |
| 24 | + metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) |
27 | 25 |
|
28 | 26 | metadata_source_match && metadata_source_match[1] |
29 | 27 | end |
30 | 28 |
|
31 | | - raise 'unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json' if returnVal.nil? |
| 29 | + raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? |
32 | 30 |
|
33 | 31 | puts "GitHubChangelogGenerator project:#{returnVal}" |
34 | 32 | returnVal |
35 | 33 | end |
36 | 34 |
|
37 | 35 | def changelog_future_release |
38 | | - return unless Rake.application.top_level_tasks.include? 'changelog' |
39 | | - |
40 | | - returnVal = format('v%s', JSON.parse(File.read('metadata.json'))['version']) |
41 | | - raise 'unable to find the future_release (version) in metadata.json' if returnVal.nil? |
42 | | - |
| 36 | + return unless Rake.application.top_level_tasks.include? "changelog" |
| 37 | + returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] |
| 38 | + raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? |
43 | 39 | puts "GitHubChangelogGenerator future_release:#{returnVal}" |
44 | 40 | returnVal |
45 | 41 | end |
46 | 42 |
|
47 | | -PuppetLint.configuration.send(:disable_relative) |
| 43 | +PuppetLint.configuration.send('disable_relative') |
48 | 44 |
|
49 | | -if Bundler.rubygems.find_name('github_changelog_generator').any? |
50 | | - GitHubChangelogGenerator::RakeTask.new :changelog do |config| |
51 | | - raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include?('changelog') && ENV['CHANGELOG_GITHUB_TOKEN'].nil? |
52 | 45 |
|
53 | | - config.user = changelog_user.to_s |
54 | | - config.project = changelog_project.to_s |
55 | | - config.future_release = changelog_future_release.to_s |
| 46 | +if Gem.loaded_specs.key? 'github_changelog_generator' |
| 47 | + GitHubChangelogGenerator::RakeTask.new :changelog do |config| |
| 48 | + raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? |
| 49 | + config.user = "#{changelog_user}" |
| 50 | + config.project = "#{changelog_project}" |
| 51 | + config.future_release = "#{changelog_future_release}" |
56 | 52 | config.exclude_labels = ['maintenance'] |
57 | 53 | config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." |
58 | 54 | config.add_pr_wo_labels = true |
59 | 55 | config.issues = false |
60 | | - config.merge_prefix = '### UNCATEGORIZED PRS; LABEL THEM ON GITHUB' |
| 56 | + config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" |
61 | 57 | config.configure_sections = { |
62 | | - 'Changed' => { |
63 | | - 'prefix' => '### Changed', |
64 | | - 'labels' => ['backwards-incompatible'] |
| 58 | + "Changed" => { |
| 59 | + "prefix" => "### Changed", |
| 60 | + "labels" => ["backwards-incompatible"], |
65 | 61 | }, |
66 | | - 'Added' => { |
67 | | - 'prefix' => '### Added', |
68 | | - 'labels' => %w[enhancement feature] |
| 62 | + "Added" => { |
| 63 | + "prefix" => "### Added", |
| 64 | + "labels" => ["enhancement", "feature"], |
| 65 | + }, |
| 66 | + "Fixed" => { |
| 67 | + "prefix" => "### Fixed", |
| 68 | + "labels" => ["bug", "documentation", "bugfix"], |
69 | 69 | }, |
70 | | - 'Fixed' => { |
71 | | - 'prefix' => '### Fixed', |
72 | | - 'labels' => %w[bug documentation bugfix] |
73 | | - } |
74 | 70 | } |
75 | 71 | end |
76 | 72 | else |
77 | 73 | desc 'Generate a Changelog from GitHub' |
78 | 74 | task :changelog do |
79 | | - raise <<~EOM |
80 | | - The changelog tasks depends on recent features of the github_changelog_generator gem. |
81 | | - Please manually add it to your .sync.yml for now, and run `pdk update`: |
82 | | - --- |
83 | | - Gemfile: |
84 | | - optional: |
85 | | - ':development': |
86 | | - - gem: 'github_changelog_generator' |
87 | | - version: '~> 1.15' |
88 | | - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" |
89 | | - EOM |
| 75 | + raise <<EOM |
| 76 | +The changelog tasks depends on recent features of the github_changelog_generator gem. |
| 77 | +Please manually add it to your .sync.yml for now, and run `pdk update`: |
| 78 | +--- |
| 79 | +Gemfile: |
| 80 | + optional: |
| 81 | + ':development': |
| 82 | + - gem: 'github_changelog_generator' |
| 83 | + version: '~> 1.15' |
| 84 | + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" |
| 85 | +EOM |
90 | 86 | end |
91 | 87 | end |
| 88 | + |
0 commit comments