From e13163ce0a16e2af0d17abf091d2bca083dfa472 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 1 Jan 2025 15:07:57 -0700 Subject: [PATCH] Add markdown mode for use with the sudo web site. --- scripts/log2cl.pl | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/scripts/log2cl.pl b/scripts/log2cl.pl index 8be892d8df..67a78cef2f 100755 --- a/scripts/log2cl.pl +++ b/scripts/log2cl.pl @@ -32,7 +32,7 @@ # Parse options and build up "git log" command my @cmd = ( "git" ); my %opts; -getopts('b:R:', \%opts); +getopts('b:mR:', \%opts); push(@cmd, "-b", $opts{"b"}) if exists $opts{"b"}; push(@cmd, "--git-dir", $opts{"R"}) if exists $opts{"R"}; push(@cmd, "log", "--log-size", "--name-only", "--date=short", "--format=$format", @ARGV); @@ -45,6 +45,7 @@ my $key_date = ""; my $log_size = 0; my @lines; +my $hash_link = "https://git.sudo.ws/sudo/commit/?id="; # Wrap like "hg log --template=changelog" $Text::Wrap::columns = 77; @@ -72,6 +73,9 @@ # Check for continued entry (duplicate Date + Author) $_ = shift(@lines); + # Strip author email address for markdown + s/\s*<[^>]+>$// if exists $opts{'m'}; + if ($_ ne $key_date) { # New entry print "$_\n\n"; @@ -106,6 +110,15 @@ exit(0); sub print_entry +{ + if (exists $opts{'m'}) { + print_entry_markdown(@_); + } else { + print_entry_plain(@_); + } +} + +sub print_entry_plain { my $hash = shift; my $body = shift; @@ -115,3 +128,24 @@ sub print_entry print fill("\t", "\t", $body) . "\n"; print "\t[$hash]\n\n"; } + +sub print_entry_markdown +{ + my $hash = shift; + my $body = shift; + my $files = ": * " . join(", ", @_) . ": "; + + # Obfuscate email addresses in body + $body =~ s/([^@ ]+@)[\w\.-]+\.(com|org|edu|ws|io)/$1.../g; + + # Escape email chars in body + $body =~ s/([@<>])/\\$1/g; + + # Expand GitHub issue and bugzilla links + $body =~ s@(GitHub issue #)(\d+)@[$1$2](https://github.com/sudo-project/sudo/issues/$2)@; + $body =~ s@(Bug #)(\d+)@[$1$2](https://bugzilla.sudo.ws/show_bug.cgi?id=$2)@; + + print wrap("", " ", $files) . "\n"; + print fill(" ", " ", $body) . "\n"; + print " [[${hash}]](${hash_link}${hash})\n\n"; +}