From 40786774c78f24b946a3265de552a37cafdd3b26 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Fri, 21 Sep 2018 22:26:30 -0700 Subject: [PATCH] Save in separate file for ecah release for update-changelog.p6 - Also make the view options a bit more object oriented. - Fix a few assorted bugs - Add the ability to save at the end, instead of magically quitting without saving - Fixed it so commit info is actually configurable in the interface --- tools/update-changelog.p6 | 155 ++++++++++++++++++++++++-------------- 1 file changed, 99 insertions(+), 56 deletions(-) diff --git a/tools/update-changelog.p6 b/tools/update-changelog.p6 index ef286fe38b..f0f12789bc 100755 --- a/tools/update-changelog.p6 +++ b/tools/update-changelog.p6 @@ -30,6 +30,40 @@ class ViewOptions { has Bool:D $.subject-origin is rw = True; has Bool:D $.subject is rw = True; has Bool:D $.author is rw = False; + has Bool:D $.dropped is rw = True; + method format-output ($thing) { + my @text; + if self.commit { + my @all = $thing; + @all.append: $thing{$merged-into} if $thing{$merged-into}; + @text.push: '[' ~ @all».substr(0, 8).join(',') ~ ']'; + } + if self.dropped && $thing { + @text.push: ''; + } + @text.push: '{' ~ ($thing // $thing // "???") ~ '}' if self.category; + if self.subject-origin { + if $thing { + @text.push: '(Custom)'; + } + elsif $thing { + @text.push: '(Auto)'; + } + else { + @text.push: '(Commit)'; + } + } + @text.push: ($thing // $thing // $thing); + if $thing && self.modified-files { + @text.push: '|'; + @text.push: $thing.»..join(", "); + } + if self.author { + @text.push: '|'; + @text.push: $thing; + } + @text.join(' '); + } } # @keywords is used to help the categorizer. Keyword is checked first, then # the directory (which can be either a string or an array of strings) is checked. @@ -49,6 +83,10 @@ my @keywords = ChangelogClassifier.new(title => 'Core', directory => 'src/core'), ChangelogClassifier.new(title => 'GC', directory => 'src/gc') ; +sub format-output ($thing, :$author = False, :$print-modified-files = False, :$print-commit = False, :$print-category = False, :$print-subject-origin = False) { + my $viewopts = ViewOptions.new(:$author, :modified-files($print-modified-files), :commit($print-commit), :category($print-category), :subject-origin($print-subject-origin)); + $viewopts.format-output($thing); +} sub git (*@args) { my $cmd = run 'git', @args, :out, :err; my $out = $cmd.out.slurp; @@ -79,38 +117,8 @@ sub is-expr-jit (Str:D $text) { } @result; } -multi sub format-output ($thing, ViewOptions:D $viewopts) { - format-output($thing, :author($viewopts.author), :print-modified-files($viewopts.modified-files), :print-commit($viewopts.commit), :print-category($viewopts.category), :print-subject-origin($viewopts.subject-origin)); -} -multi sub format-output ($thing, :$author = False, :$print-modified-files = False, :$print-commit = False, :$print-category = False, :$print-subject-origin = False) { - my @text; - if $print-commit { - my @all = $thing; - @all.append: $thing{$merged-into} if $thing{$merged-into}; - @text.push: '[' ~ @all».substr(0, 8).join(',') ~ ']'; - } - @text.push: '{' ~ ($thing // $thing // "???") ~ '}' if $print-category; - if $print-subject-origin { - if $thing { - @text.push: '(Custom)'; - } - elsif $thing { - @text.push: '(Auto)'; - } - else { - @text.push: '(Commit)'; - } - } - @text.push: ($thing // $thing // $thing); - if $thing && $print-modified-files { - @text.push: '|'; - @text.push: $thing.»..join(", "); - } - if $author { - @text.push: '|'; - @text.push: $thing; - } - @text.join(' '); +sub print-message(Str:D $text, :$status) { + say "{' ' if $status }$text"; } sub get-subject ($item) { $item // $item // $item; @@ -118,12 +126,10 @@ sub get-subject ($item) { sub get-category ($item) { $item // $item // "???"; } -my $dat-file = "updatechangelog.dat"; sub get-folder-name (Str:D $str) { my @split = $str.split('/'); my $result = ((@split - 1 < 2) ?? @split[0] !! @split[0..1]).join('/'); $result = $str if $result eq 'src'; - #say "in: $str out: $result"; return $result; } use Test; @@ -140,15 +146,16 @@ sub get-main-dir ($thing) { my $folder = get-folder-name($change); %folders{$folder} += $addition-weight * $change + $remove-weight * $change; } - #say "\%folders.perl: «" ~ %folders.perl ~ "»"; %folders.sort(-*.value).first.key; } # TODO remove %categories -sub do-item ($item, $viewopts, @loggy, %categories, Bool:D :$deep = False) { +sub do-item ($item, $viewopts, @loggy, %categories, Str:D $output-filename, Bool:D :$deep = False) { my $not-done = True; while ($not-done) { - say format-output($item, $viewopts); - my $response = prompt "MODIFY (e)dit/(d)rop/(c)ategory/d(o)ne/(T)itlecase/[(m)erge into other commit]/[change (v)iew opts]; PRINT (b)ody/d(i)ff/num-(l)eft/(D)ump/(C)omplete/(U)uncomplete; GOTO (n)ext/(G)oto commit ID; (Q)uit and save or (s)ave: "; + say $viewopts.format-output($item); + my $response = prompt "MODIFY (e)dit/(d)rop/(c)ategory/d(o)ne/(T)itlecase/[(m)erge into other commit]/[change (v)iew opts]; " ~ + "PRINT (b)ody/d(i)ff/num-(l)eft/(D)ump/(C)omplete/(U)uncomplete; " ~ + "GOTO (n)ext/(G)oto commit ID; (Q)uit and save or (s)ave: "; given $response { when 'v' { say "Toggle view options. (m)odified files, (c)ommit, (C)ategory, subject (o)rigin, (a)uthor, (q)uit this menu and go back"; @@ -207,7 +214,7 @@ sub do-item ($item, $viewopts, @loggy, %categories, Bool:D :$deep = False) { } when 'D' { - say "Dumping this commit:\n"; + print-message "Dumping this commit:\n", :status; say $item.perl; say ""; } @@ -218,6 +225,9 @@ sub do-item ($item, $viewopts, @loggy, %categories, Bool:D :$deep = False) { if !$need { say "\nERROR: Can't find commit $need\n"; } + elsif $item.lc.starts-with($merge-into.lc) { + say "\nCannot merge a commit into itself!\n"; + } elsif $item{$merged-to} && $item{$merged-to}.first(*.starts-with($merge-into.trim)) { say "\nERROR: This has already been merged into that one\n"; } @@ -231,7 +241,14 @@ sub do-item ($item, $viewopts, @loggy, %categories, Bool:D :$deep = False) { } when 'd' { - $item = "User"; + if $item { + print-message "UNdropped commit", :status; + $item:delete; + } + else { + $item = "User"; + print-message "DROPped commit", :status; + } $not-done = False; } when 'i' { @@ -253,7 +270,7 @@ sub do-item ($item, $viewopts, @loggy, %categories, Bool:D :$deep = False) { for @loggy -> $ite { %hash{$ite} = $ite; } - spurt "updatechangelog.dat", to-json(%hash); + spurt $output-filename, to-json(%hash); if $response ~~ /Q/ { exit; } @@ -276,16 +293,16 @@ sub do-item ($item, $viewopts, @loggy, %categories, Bool:D :$deep = False) { next if !$item; } if $response.contains('s') { - %categories{get-category($item)}.push: $item; + %categories{ get-category($item) }.push: $item; } else { - $proc.in.say(format-output($item, $viewopts)); + $proc.in.say: $viewopts.format-output($item); } } if $response.contains('s') { for %categories.keys.sort -> $key { for %categories{$key}.list -> $item { - $proc.in.say(format-output($item, $viewopts)); + $proc.in.say($viewopts.format-output($item)); } } } @@ -298,7 +315,7 @@ sub do-item ($item, $viewopts, @loggy, %categories, Bool:D :$deep = False) { if $need { if !$deep { while ($need) { - $need = do-item $need, $viewopts, @loggy, %categories, :deep; + $need = do-item $need, $viewopts, @loggy, %categories, $output-filename, :deep; } } # We are already one deep so return it to continue @@ -337,16 +354,36 @@ sub prompt-it (Str:D $pretext = '') { } } } +sub next-tag (Str:D $tag) { + my ($year, $month) = $tag.split('.'); + if $month == 12 { + $year++; + $month = 1; + } + else { + $month++; + } + sprintf "%i.%.2i", $year, $month; +} +class OutputFile { + has IO::Path $.filename; + method parse { + } +} sub MAIN (Bool:D :$print-modified-files = False, Bool:D :$print-commit = False) { + my $last-tag = last-tag(); + my $next-tag = next-tag($last-tag); + my $output-filename = $next-tag ~ "-changelog.json"; my @loggy = git-log '--topo-order', "{last-tag()}..master", :get-changes; my %categories; - if $dat-file.IO.f { + my $dat = OutputFile.new(:filename($output-filename.IO)); + if $output-filename.IO.f { my $answer = 'y'; while $answer ne 'y' && $answer ne 'n' { $answer = prompt "Load saved changelog info file? y/n: "; } if $answer eq 'y' { - my %hash = from-json $dat-file.IO.slurp; + my %hash = from-json $output-filename.IO.slurp; for @loggy <-> $logone { if %hash{$logone} { $logone = %hash{$logone}; @@ -354,6 +391,9 @@ sub MAIN (Bool:D :$print-modified-files = False, Bool:D :$print-commit = False) } } } + else { + say "file isn't here"; + } for @loggy -> $change { my $has-pushed = False; next if !$change; @@ -406,19 +446,22 @@ sub MAIN (Bool:D :$print-modified-files = False, Bool:D :$print-commit = False) } # Remove the expr jit op additions so we can combine them into one entry my @new-expr-jit-ops; - #for %categories.list <-> $item { - # my $result = is-expr-jit($item); - # if $result { - # @new-expr-jit-ops.append: $result.list; - # $item = 'auto'; - # $item:delete; - # } - #} my $viewopts = ViewOptions.new; for @loggy.reverse -> $item { next if $item; next if $item; - do-item($item, $viewopts, @loggy, %categories); + do-item($item, $viewopts, @loggy, %categories, $output-filename); + } + my $prompt-result; + while !$prompt-result || $prompt-result ne 'y'|'n' { + $prompt-result = prompt "Should we save y/n?: "; + } + if $prompt-result eq 'y' { + my %hash; + for @loggy -> $ite { + %hash{$ite} = $ite; + } + spurt $output-filename, to-json(%hash); } my $has-outputted-expr-jit-ops = False; for %categories.keys.sort -> $key {