2 # Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Generates NEWS, NEWS.atom, and NEWS.html files using release emails
5 # this uses unstable internal APIs of public-inbox, and this script
6 # needs to be updated if they change.
10 use PublicInbox::Hval qw(fmt_ts);
11 use PublicInbox::MsgTime qw(msg_datestamp);
12 use PublicInbox::MID qw(mids mid_escape);
13 END { $INC{'Plack/Util.pm'} and warn "$0 should not have loaded Plack::Util\n" }
14 my $dst = shift @ARGV or die "Usage: $0 <NEWS|NEWS.atom|NEWS.html>";
18 my $dir = 'Documentation/RelNotes';
19 my $base_url = 'https://public-inbox.org/meta';
20 my $html_url = 'https://public-inbox.org/NEWS.html';
21 my $atom_url = 'https://public-inbox.org/NEWS.atom';
22 my $addr = 'meta@public-inbox.org';
24 my $latest = shift(@releases) or die 'no releases?';
26 my $mime_latest = release2mime($latest, \$mtime);
30 open $out, '>:encoding(utf8)', $tmp or die;
31 mime2txt($out, $mime_latest);
32 for my $v (@releases) {
33 print $out "\n" or die;
34 mime2txt($out, release2mime($v));
36 } elsif ($dst eq 'NEWS.atom' || $dst eq 'NEWS.html') {
37 open $out, '>', $tmp or die;
38 my $ibx = My::MockObject->new(
39 description => 'public-inbox releases',
41 search => 1, # for WwwStream::html_top
42 base_url => "$base_url/",
44 $ibx->{-primary_address} = $addr;
47 -upfx => "$base_url/",
50 if ($dst eq 'NEWS.html') {
51 html_start($out, $ctx);
52 mime2html($out, $mime_latest, $ctx);
53 while (defined(my $v = shift(@releases))) {
54 mime2html($out, release2mime($v), $ctx);
57 } elsif ($dst eq 'NEWS.atom') {
58 my $astream = atom_start($out, $ctx, $mtime);
59 for my $v (reverse(@releases)) {
60 mime2atom($out, $astream, release2mime($v), $ctx);
62 mime2atom($out, $astream, $mime_latest, $ctx);
63 print $out '</feed>' or die;
65 die "BUG: Unrecognized $dst\n";
68 die "Unrecognized $dst\n";
72 utime($mtime, $mtime, $tmp) or die;
73 rename($tmp, $dst) or die;
77 my ($release, $mtime_ref) = @_;
78 my $f = "$dir/$release.eml";
79 open(my $fh, '<', $f) or die "open($f): $!";
80 my $mime = PublicInbox::Eml->new(\(do { local $/; <$fh> }));
81 # Documentation/include.mk relies on mtimes of each .eml file
82 # to trigger rebuild, so make sure we sync the mtime to the Date:
84 my $mtime = msg_datestamp($mime->header_obj);
85 utime($mtime, $mtime, $fh) or warn "futimes $f: $!";
86 $$mtime_ref = $mtime if $mtime_ref;
91 my ($out, $mime) = @_;
92 my $title = $mime->header('Subject');
93 $title =~ s/^\s*\[\w+\]\s*//g; # [ANNOUNCE] or [ANN]
94 my $dtime = msg_datestamp($mime->header_obj);
95 $title .= ' - ' . fmt_ts($dtime) . ' UTC';
96 print $out $title, "\n" or die;
97 my $uline = '=' x length($title);
98 print $out $uline, "\n\n" or die;
100 my $mid = mids($mime)->[0];
101 print $out 'Link: ', $base_url, '/', mid_escape($mid), "/\n\n" or die;
102 print $out $mime->body_str or die;
106 my ($out, $eml, $ctx) = @_;
107 my $smsg = $ctx->{smsg} = bless {}, 'PublicInbox::Smsg';
108 $smsg->populate($eml);
109 $ctx->{msgs} = [ 1 ]; # for <hr> in eml_entry
110 print $out PublicInbox::View::eml_entry($ctx, $eml) or die;
114 my ($out, $ctx) = @_;
115 require PublicInbox::WwwStream;
116 $ctx->{www} = My::MockObject->new(style => '');
117 my $www_stream = PublicInbox::WwwStream::init($ctx);
118 print $out $www_stream->html_top, '<pre>' or die;
122 print $out <<EOF or die;
123 git clone $PublicInbox::WwwStream::CODE_URL
129 my ($out, $ctx, $mtime) = @_;
130 require PublicInbox::WwwAtomStream;
131 # WwwAtomStream stats this dir for mtime
132 my $astream = PublicInbox::WwwAtomStream->new($ctx);
133 delete $astream->{emit_header};
134 my $ibx = $ctx->{-inbox};
135 my $title = PublicInbox::WwwAtomStream::title_tag($ibx->description);
136 my $updated = PublicInbox::WwwAtomStream::feed_updated($mtime);
137 print $out <<EOF or die;
138 <?xml version="1.0" encoding="us-ascii"?>
140 xmlns="http://www.w3.org/2005/Atom"
141 xmlns:thr="http://purl.org/syndication/thread/1.0">$title<link
144 href="$html_url"/><link
146 href="$atom_url"/><id>$atom_url</id>$updated
152 my ($out, $astream, $eml, $ctx) = @_;
153 my $smsg = bless {}, 'PublicInbox::Smsg';
154 $smsg->populate($eml);
155 if (defined(my $str = $astream->feed_entry($smsg, $eml))) {
156 print $out $str or die;
159 package My::MockObject;
164 my ($class, %values) = @_;
165 bless \%values, $class;
170 my $attr = (split(/::/, $AUTOLOAD))[-1];