Module: MnoeCli::Commands::GenerateVersionLog
- Defined in:
- lib/mnoe_cli/commands/generate_version_log.rb
Overview
Generate a changelog of different components for an enterprise project TODO:
-
dynamic config (in progress)
-
ARGS commits or default to HEAD/UPSTREAM
Constant Summary collapse
- GEMFILE_LOCK =
Constants
'Gemfile.lock'
- YARN_LOCK =
'yarn.lock'
- YARN_PKGS =
%w(mno-enterprise-angular mnoe-admin-panel impac-angular)
- NO_TOKEN_PROVIDED =
"Warning: No token provided. Please set the $CHANGELOG_GITHUB_TOKEN variable."
Class Method Summary collapse
- .compare(repo, old, new) ⇒ Object
-
.configure ⇒ Object
Configure Octokit and the faraday middleware.
- .diff_gem(log, gem) ⇒ Object
-
.diff_yarn_package(log, package) ⇒ Object
Return compare URL for the given package.
- .run(args, opts) ⇒ Object
Class Method Details
.compare(repo, old, new) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/mnoe_cli/commands/generate_version_log.rb', line 97 def self.compare(repo, old, new) log = Octokit.compare(repo, old, new) log.commits.each do |c| msg = c.commit. next unless msg =~ /Merge pull request/ puts "* #{msg.lines.last}" end end |
.configure ⇒ Object
Configure Octokit and the faraday middleware
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mnoe_cli/commands/generate_version_log.rb', line 74 def self.configure # Github Authentication Token Octokit.configure do |client| client.access_token = ENV.fetch('CHANGELOG_GITHUB_TOKEN', nil) say(NO_TOKEN_PROVIDED) unless client.access_token end # Add some cache middleware_opts = { serializer: Marshal, store: ActiveSupport::Cache::FileStore.new("/tmp/mno-changelog-http-cache"), logger: Logger.new("/tmp/mno-changelog-logger.log"), shared_cache: false } Octokit.middleware = Faraday::RackBuilder.new do |builder| builder.use Faraday::HttpCache, middleware_opts builder.use Octokit::Response::RaiseError builder.adapter Faraday.default_adapter # builder.response :logger end end |
.diff_gem(log, gem) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/mnoe_cli/commands/generate_version_log.rb', line 123 def self.diff_gem(log, gem) pattern = %r{ remote:\s+https://github.com/maestrano/mno-enterprise(?:.git)?\s+ -\s+revision:\s+(\S*)\s+ \+\s+revision:\s+(\S*) }x puts "\n# mno-enterprise" if log =~ pattern old_version = Regexp.last_match(1)[0..8] new_version = Regexp.last_match(2)[0..8] puts "https://github.com/maestrano/mno-enterprise/compare/#{old_version}...#{new_version}" compare('maestrano/mno-enterprise', old_version, new_version) else puts "No changes" end end |
.diff_yarn_package(log, package) ⇒ Object
Return compare URL for the given package
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mnoe_cli/commands/generate_version_log.rb', line 108 def self.diff_yarn_package(log, package) pattern = %r{\s*resolved "git\+https://[email protected]/maestrano/#{package}.git#(\S*)"} puts "\n# #{package}:" if log =~ %r{-#{pattern}} old_version = Regexp.last_match(1)[0..8] log =~ %r{\+#{pattern}} new_version = Regexp.last_match(1)[0..8] puts "https://github.com/maestrano/#{package}/compare/#{old_version}...#{new_version}" compare("maestrano/#{package}", old_version, new_version) else puts "No change" end end |
.run(args, opts) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mnoe_cli/commands/generate_version_log.rb', line 44 def self.run(args, opts) self.configure @current = opts.current @next = opts.next workdir = Dir.getwd project = File.basename(workdir) current_branch = %x(git rev-parse --abbrev-ref HEAD).chomp! # say "Generating change for '#{project}##{current_branch}'" say "Generating change for #{project} #{@current} -> #{@next}" say "https://github.com/maestrano/#{project}/compare/#{@current}...#{@next}" begin self.compare("maestrano/#{project}", @current.gsub(%r{(origin|upstream)/}, ''), @next.gsub(%r{(origin|upstream)/}, '')) rescue say "Cannot find branches" end log = %x(git diff #{@current}...#{@next} -- #{YARN_LOCK}) YARN_PKGS.each do |pkg| self.diff_yarn_package(log, pkg) end log = %x(git diff #{@current}...#{@next} -- #{GEMFILE_LOCK}) self.diff_gem(log, 'mno-enteprise') end |