general_assembly.pl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/usr/bin/env perl
  2. use warnings;
  3. use strict;
  4. use POSIX qw(strftime);
  5. use Encode qw(decode);
  6. use Data::Dumper;
  7. use Getopt::Long;
  8. use Digest::SHA;
  9. use utf8;
  10. use DateTime;
  11. use DateTime::Format::ISO8601;
  12. my @extra_members = (
  13. # entries should be of the format
  14. # [ <name>, <email>, <date elected> ],
  15. # ['Foo Bar', 'foo@bar', DateTime->new(year => 8613, month => 5, day => 22)],
  16. ['Ronald Bultje', 'rsbultje@gmail.com', DateTime->new(year => 2023, month => 11, day => 28)],
  17. ['Hendrik Leppkes', 'h.leppkes@gmail.com', DateTime->new(year => 2023, month => 11, day => 28)],
  18. ['Reimar Döffinger', 'Reimar.Doeffinger@gmx.de', DateTime->new(year => 2023, month => 11, day => 28)],
  19. ['Alexander Strasser', 'eclipse7@gmx.net', DateTime->new(year => 2023, month => 11, day => 28)],
  20. ['Baptiste Coudurier', 'baptiste.coudurier@gmail.com', DateTime->new(year => 2023, month => 11, day => 28)],
  21. ['Shiyou Yin', 'yinshiyou-hf@loongson.cn', DateTime->new(year => 2023, month => 11, day => 28)],
  22. );
  23. # list of names of people who asked to be excluded from GA emails
  24. my %excluded_members = (
  25. 'Derek Buitenhuis' => 0,
  26. );
  27. sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
  28. sub print_help {
  29. print "Usage: $0 [options]\n";
  30. print "Options:\n";
  31. print " --names Print only the names\n";
  32. print " --emails Print only the email addresses\n";
  33. print " --full Print both names and email addresses (default)\n";
  34. print " --date YY-MM-DD Generate the GA for a given date, defaults to current system time\n";
  35. print " -h, --help Show this help message\n";
  36. exit;
  37. }
  38. my $print_full = 1;
  39. my $print_names = 0;
  40. my $print_emails = 0;
  41. my $date_str = DateTime->now()->iso8601;
  42. my $help = 0;
  43. GetOptions(
  44. "full" => \$print_full,
  45. "names" => \$print_names,
  46. "emails" => \$print_emails,
  47. "help" => \$help,
  48. "date=s" => \$date_str,
  49. "h" => \$help,
  50. );
  51. print_help() if $help;
  52. if ($print_names || $print_emails) {
  53. $print_full = 0;
  54. }
  55. sub get_date_range {
  56. my ($now) = @_;
  57. # date on which the GA update rule was established, and the voter list
  58. # was extraordinarily updated; cf.:
  59. # * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-October/316054.html
  60. # Message-Id <169818211998.11195.16532637803201641594@lain.khirnov.net>
  61. # * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-November/316618.html
  62. # Message-Id <5efcab06-8510-4226-bf18-68820c7c69ba@betaapp.fastmail.com>
  63. my $date_ga_rule = DateTime->new(year => 2023, month => 11, day => 06);
  64. # date when the regular update rule is first applied
  65. my $date_first_regular = DateTime->new(year => 2024);
  66. if ($now > $date_ga_rule && $now < $date_first_regular) {
  67. return ($date_ga_rule->clone()->set_year($date_ga_rule->year - 3), $date_ga_rule);
  68. }
  69. if ($now < $date_ga_rule) {
  70. print STDERR "GA before $date_ga_rule is not well-defined, be very careful with the output\n";
  71. }
  72. my $cur_year_jan = $now->clone()->truncate(to => "year");
  73. my $cur_year_jul = $cur_year_jan->clone()->set_month(7);
  74. my $date_until = $now > $cur_year_jul ? $cur_year_jul : $cur_year_jan;
  75. my $date_since = $date_until->clone()->set_year($date_until->year - 3);
  76. return ($date_since, $date_until);
  77. }
  78. my $date = DateTime::Format::ISO8601->parse_datetime($date_str);
  79. my ($since, $until) = get_date_range($date);
  80. my @shortlog = split /\n/, decode('UTF-8',
  81. `git log --pretty=format:"%aN <%aE>" --since="$since" --until="$until" | sort | uniq -c | sort -r`,
  82. Encode::FB_CROAK);
  83. my %assembly = ();
  84. foreach my $line (@shortlog) {
  85. my ($count, $name, $email) = $line =~ m/^ *(\d+) *(.*?) <(.*?)>/;
  86. if ($count < 20) {
  87. next;
  88. }
  89. $name = trim $name;
  90. if (exists $excluded_members{$name}) {
  91. next;
  92. }
  93. if ($count < 50) {
  94. my $true = 0;
  95. my @commits = split /(^|\n)commit [a-z0-9]{40}(\n|$)/,
  96. decode('UTF-8',
  97. `git log --name-only --use-mailmap --author="$email" --since="$since" --until="$until"`,
  98. Encode::FB_CROAK);
  99. foreach my $commit (@commits) {
  100. $true++; # if ($commit =~ /\n[\w\/]+\.(c|h|S|asm|texi)/);
  101. }
  102. if ($true < 20) {
  103. next;
  104. }
  105. }
  106. $assembly{$name} = $email;
  107. }
  108. foreach my $entry (@extra_members) {
  109. my $elected = $entry->[2];
  110. if ($date > $elected && $date < $elected->clone()->set_year($elected->year + 2)) {
  111. $assembly{$entry->[0]} = $entry->[1];
  112. }
  113. }
  114. # generate the output string
  115. my @out_lines;
  116. foreach my $name (sort keys %assembly) {
  117. my $email = $assembly{$name};
  118. my $val;
  119. if ($print_full) {
  120. $val = sprintf("%s <%s>", $name, $email);
  121. } elsif ($print_names) {
  122. $val = $name;
  123. } elsif ($print_emails) {
  124. $val = $email;
  125. }
  126. push(@out_lines, ($val));
  127. }
  128. my $out_str = join("\n", @out_lines) . "\n";
  129. utf8::encode($out_str);
  130. printf("# GA for $since/$until; %d people; SHA256:%s; HEAD:%s%s",
  131. scalar @out_lines, Digest::SHA::sha256_hex($out_str),
  132. decode('UTF-8', `git rev-parse HEAD`, Encode::FB_CROAK),
  133. $out_str);