Commit c92605cc authored by Niklaus Giger's avatar Niklaus Giger
Browse files

[21759] Emit first fixed version

parent 3e1c45b4
Pipeline #22727 passed with stages
in 4 minutes and 26 seconds
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
require 'bundler/inline' require 'bundler/inline'
puts "It may take some time for bundler/inline to install the dependencies" puts "It may take some time for bundler/inline to install the dependencies"
$argv_copy = ARGV.clone
gemfile do gemfile do
source 'https://rubygems.org' source 'https://rubygems.org'
...@@ -28,6 +27,8 @@ require 'csv' ...@@ -28,6 +27,8 @@ require 'csv'
require 'fileutils' require 'fileutils'
require 'active_support/all' require 'active_support/all'
DATE_FORMAT = '%Y.%m.%d'
AUFRUF = "# Generated by #{File.basename(__FILE__)} #{ARGV} on #{Time.now.strftime(DATE_FORMAT)}".gsub("[", '').gsub("]", '').gsub('"','')
ISSUE_URL = 'https://redmine.medelexis.ch/issues' ISSUE_URL = 'https://redmine.medelexis.ch/issues'
CACHE_FILE = File.join(Dir.home, '.cache/redmine_issues.yaml') CACHE_FILE = File.join(Dir.home, '.cache/redmine_issues.yaml')
IGNORE_ISSUE_STATUS = /Abgewiesen|erledigt|zur*ckgestell/i IGNORE_ISSUE_STATUS = /Abgewiesen|erledigt|zur*ckgestell/i
...@@ -58,7 +59,6 @@ end ...@@ -58,7 +59,6 @@ end
require 'rugged' require 'rugged'
MAX_ID = 999 MAX_ID = 999
FORCE_TAG_NUMERIC = (MAX_ID.to_s*4).to_i FORCE_TAG_NUMERIC = (MAX_ID.to_s*4).to_i
DATE_FORMAT = '%Y.%m.%d'
MEDIAWIKI_FILE = 'Changelog.mediawiki' MEDIAWIKI_FILE = 'Changelog.mediawiki'
Issue = Struct.new(:id, :subject, :fixed_version, :git_version, :status, :project, :last_api_fetch) Issue = Struct.new(:id, :subject, :fixed_version, :git_version, :status, :project, :last_api_fetch)
CommitInfo = Struct.new(:repo, :ticket, :author_date, :committer_date, :text) CommitInfo = Struct.new(:repo, :ticket, :author_date, :committer_date, :text)
...@@ -176,8 +176,13 @@ def get_history(old_id, newer_id, git_version) ...@@ -176,8 +176,13 @@ def get_history(old_id, newer_id, git_version)
walker.each do |commit| walker.each do |commit|
author = commit.author[:name] author = commit.author[:name]
ticket_id = (m = /^\[(\d*)\]/.match(commit.message)) && m[1] ticket_id = (m = /^\[(\d*)\]/.match(commit.message)) && m[1]
ticket = ticket_id ? read_issue(ticket_id) : Issue.new ticket = ticket_id ? read_issue(ticket_id) : Issue.new(ticket_id)
ticket.git_version = git_version if ticket # Handle cases like Issue 19635 not found
ticket ||= Issue.new(ticket_id)
ticket.id ||= ticket_id
ticket.fixed_version ||= "Keine Zielversion"
ticket.subject ||= "Keine Titel"
ticket.git_version = git_version
line = "#{commit.oid} #{commit.author[:time]} #{sprintf('%20s', author)} #{commit.message.split("\n").first}" line = "#{commit.oid} #{commit.author[:time]} #{sprintf('%20s', author)} #{commit.message.split("\n").first}"
info.commits << CommitInfo.new(File.basename(File.dirname(@repo.path)), ticket, commit.author[:time].strftime(DATE_FORMAT), commit.committer[:time].strftime(DATE_FORMAT), line) info.commits << CommitInfo.new(File.basename(File.dirname(@repo.path)), ticket, commit.author[:time].strftime(DATE_FORMAT), commit.committer[:time].strftime(DATE_FORMAT), line)
info.authors[author] ||= 0 info.authors[author] ||= 0
...@@ -186,7 +191,6 @@ def get_history(old_id, newer_id, git_version) ...@@ -186,7 +191,6 @@ def get_history(old_id, newer_id, git_version)
info info
end end
def read_issue(id = 5760) def read_issue(id = 5760)
@nr_loaded ||= 0 @nr_loaded ||= 0
unless ENV['REDMINE_MEDEXIS_API'] unless ENV['REDMINE_MEDEXIS_API']
...@@ -235,7 +239,9 @@ def emit_mediawiki_changelog(all_commits, file) ...@@ -235,7 +239,9 @@ def emit_mediawiki_changelog(all_commits, file)
short_version = /[\d\.]+$/.match(@options[:to])[0] short_version = /[\d\.]+$/.match(@options[:to])[0]
mediawiki.puts "= Changelog für Elexis #{short_version} ab #{@options[:from]} bis #{@options[:to]} =" mediawiki.puts "= Changelog für Elexis #{short_version} ab #{@options[:from]} bis #{@options[:to]} ="
mediawiki.puts "" mediawiki.puts ""
mediawiki.puts AUFRUF.sub('# ','')
mediawiki.puts "Die Zahlen in Klammern beziehen sich auf das nicht öffentlich zugängliche Ticket-System der Firma Medelexis AG" mediawiki.puts "Die Zahlen in Klammern beziehen sich auf das nicht öffentlich zugängliche Ticket-System der Firma Medelexis AG"
mediawiki.puts " gefolgt von der Version in der das Problem zuerst geflickt, resp. zurückportiert wurde. Leer falls keine Zielversion erfasst"
mediawiki.puts "" mediawiki.puts ""
if @options[:by_week] if @options[:by_week]
sorted = all_commits.sort{|left, right| left.committer_date <=> right.committer_date} sorted = all_commits.sort{|left, right| left.committer_date <=> right.committer_date}
...@@ -258,18 +264,23 @@ def emit_mediawiki_changelog(all_commits, file) ...@@ -258,18 +264,23 @@ def emit_mediawiki_changelog(all_commits, file)
mediawiki.puts "" mediawiki.puts ""
end end
else else
to_sort = all_commits.find_all{|x| x.ticket&.fixed_version.eql?(short_version)} to_sort = all_commits.find_all{|x| x.ticket&.fixed_version.eql?(short_version) || x.ticket&.git_version.sub(/.*\//,'').eql?(short_version) }
if to_sort if to_sort
to_sort.sort{|left, right| left.committer_date <=> right.committer_date} to_sort.sort{|left, right| left.committer_date <=> right.committer_date}
sorted_by_ticket = to_sort.sort{|left, right| left.ticket.id <=> right.ticket.id} sorted_by_ticket = to_sort.sort{|left, right| left.ticket.id.to_i <=> right.ticket.id.to_i}
emitted_ids = [] emitted_ids = []
sorted_by_ticket.each do|commit| sorted_by_ticket.each do|commit|
next if emitted_ids.index(commit.ticket.id) next if emitted_ids.index(commit.ticket.id)
proprietary = !sorted_by_ticket.find_all{|x| x.ticket.id == commit.ticket.id}.collect{|x| x.repo}.uniq.find{ |x| x.match(/^elexis/)} proprietary = !sorted_by_ticket.find_all{|x| x.ticket.id == commit.ticket.id}.collect{|x| x.repo}.uniq.find{ |x| x.match(/^elexis/)}
line = "* #{proprietary ? 'Medelexis:' : 'OpenSource'} #{sprintf("%14s", "'''([https://redmine.medelexis.ch/issues/" + commit.ticket.id + ' ' + commit.ticket.id + "])'''")}#{commit.ticket.subject.gsub(/\n|\r\n/, ',').strip}" commit_id = commit.ticket.id ? commit.ticket.id : "unkown"
binding.pry unless commit.ticket.subject
line = "* #{proprietary ? 'Medelexis:' : 'OpenSource'} #{sprintf("%14s", "'''([https://redmine.medelexis.ch/issues/" + commit_id + ' ' + commit_id + "])'''")}" +
" #{commit.ticket.fixed_version}" +
" #{commit.ticket.subject.gsub(/\n|\r\n/, ',').strip}"
mediawiki.puts line mediawiki.puts line
emitted_ids << commit.ticket.id emitted_ids << commit.ticket.id
end end
puts "Emitted #{emitted_ids.size} tickets for #{short_version}"
end end
end end
mediawiki.close mediawiki.close
...@@ -315,7 +326,7 @@ def emit_history(filename, from = nil, to = nil) ...@@ -315,7 +326,7 @@ def emit_history(filename, from = nil, to = nil)
walk = @history walk = @history
filename += "-#{from.sub(/(release|origin)\//,'')}-#{to.sub(/(origin|release)\//,'')}" if from && to filename += "-#{from.sub(/(release|origin)\//,'')}-#{to.sub(/(origin|release)\//,'')}" if from && to
File.open(filename, 'w+') do |ausgabe| File.open(filename, 'w+') do |ausgabe|
ausgabe.puts "# Generated by #{File.basename(__FILE__)} #{$argv_copy} on #{Time.now.strftime(DATE_FORMAT)}".gsub("[", '').gsub("]", '').gsub('"','') ausgabe.puts AUFRUF
ausgabe.puts "# similar to git log --date=iso --pretty=format:'%H %ad %an %s' release/3.0.25..release/3.1.0" ausgabe.puts "# similar to git log --date=iso --pretty=format:'%H %ad %an %s' release/3.0.25..release/3.1.0"
if from && to if from && to
emit_changes(ausgabe, from, to) emit_changes(ausgabe, from, to)
...@@ -361,7 +372,7 @@ if @options[:mediawiki] ...@@ -361,7 +372,7 @@ if @options[:mediawiki]
from_id = from_tag.commit_id from_id = from_tag.commit_id
else else
from_tag ||= @repo.branches[@options[:from]] from_tag ||= @repo.branches[@options[:from]]
from_id = from_tag&.target.oid from_id = from_tag&.target&.oid
end end
unless from_tag unless from_tag
puts "Skipping #{repo} as there is no tag #{@options[:from]}" puts "Skipping #{repo} as there is no tag #{@options[:from]}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment