changelog-format-blog-post 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/perl -w
  2. # This script reads the ChangeLog.txt file and outputs it to stdout
  3. # in the format for the blog post.
  4. use strict;
  5. use FindBin;
  6. sub version_type {
  7. return $_[0] =~ 'a' ? 'alpha' : 'release';
  8. }
  9. my ($changelog, $current_tbversion, $last_tbversion);
  10. if (!open(CHANGELOG, '<', "$FindBin::Bin/../ChangeLog.txt")) {
  11. print STDERR "Error opening changelog file\n";
  12. exit 1;
  13. }
  14. foreach (<CHANGELOG>) {
  15. if (m/^Tor Browser ([^\s]+) -/) {
  16. if ($current_tbversion) {
  17. $last_tbversion = $1;
  18. last if version_type($current_tbversion) eq version_type($last_tbversion);
  19. next;
  20. }
  21. $current_tbversion = $1;
  22. next;
  23. }
  24. next if $last_tbversion;
  25. # Remove one space at the begining of all lines
  26. s/^\s//;
  27. # Replace '*' by '-'
  28. s/^(\s*)\*/$1-/;
  29. s/&/&amp;/; s/</&lt;/; s/>/&gt;/;
  30. # Change bug numbers to links
  31. s|Bug (\d+): ([^\[]+) \[([^\]]+)\]|[Bug $3#$1](https://gitlab.torproject.org/tpo/applications/$3/-/issues/$1): $2|;
  32. $changelog .= $_;
  33. }
  34. my $changelog_branch = 'master';
  35. if (! ( $current_tbversion =~ m/a/ ) ) {
  36. my @v = split(/\./, $current_tbversion);
  37. $changelog_branch = "maint-$v[0].$v[1]";
  38. }
  39. print "The full changelog since [Tor Browser $last_tbversion](https://gitweb.torproject.org/builders/tor-browser-build.git/plain/projects/tor-browser/Bundle-Data/Docs/ChangeLog.txt?h=$changelog_branch) is:\n\n";
  40. print $changelog;