Ubuntu.pm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
  2. # Copyright © 2008 Ian Jackson <ian@davenant.greenend.org.uk>, Colin Watson
  3. # <cjwatson@ubuntu.com>, James Westby <jw+debian@jameswestby.net>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. package Dpkg::Vendor::Ubuntu;
  15. use strict;
  16. use warnings;
  17. use Dpkg::ErrorHandling;
  18. use Dpkg::Gettext;
  19. use Dpkg::Control::Types;
  20. use base 'Dpkg::Vendor::Debian';
  21. =head1 NAME
  22. Dpkg::Vendor::Ubuntu - Ubuntu vendor object
  23. =head1 DESCRIPTION
  24. This vendor object customize the behaviour of dpkg-source
  25. to check that Maintainers have been modified if necessary.
  26. =cut
  27. sub run_hook {
  28. my ($self, $hook, @params) = @_;
  29. if ($hook eq "before-source-build") {
  30. my $src = shift @params;
  31. my $fields = $src->{'fields'};
  32. # check that Maintainer/XSBC-Original-Maintainer comply to
  33. # https://wiki.ubuntu.com/DebianMaintainerField
  34. if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
  35. $fields->{'Version'} =~ /ubuntu/) {
  36. if ($fields->{'Maintainer'} !~ /ubuntu/i) {
  37. if (defined ($ENV{'DEBEMAIL'}) and $ENV{'DEBEMAIL'} =~ /\@ubuntu\.com/) {
  38. error(_g('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
  39. } else {
  40. warning(_g('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
  41. }
  42. }
  43. unless ($fields->{'Original-Maintainer'}) {
  44. warning(_g('Version number suggests Ubuntu changes, but there is no XSBC-Original-Maintainer field'));
  45. }
  46. }
  47. } elsif ($hook eq "keyrings") {
  48. my @keyrings = $self->SUPER::run_hook($hook);
  49. push(@keyrings, '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
  50. return @keyrings;
  51. } elsif ($hook eq "register-custom-fields") {
  52. my @field_ops = $self->SUPER::run_hook($hook);
  53. push @field_ops,
  54. [ "register", "Launchpad-Bugs-Fixed",
  55. CTRL_FILE_CHANGES | CTRL_CHANGELOG ],
  56. [ "insert_after", CTRL_FILE_CHANGES, "Closes", "Launchpad-Bugs-Fixed" ],
  57. [ "insert_after", CTRL_CHANGELOG, "Closes", "Launchpad-Bugs-Fixed" ];
  58. return @field_ops;
  59. } elsif ($hook eq "post-process-changelog-entry") {
  60. my $fields = shift @params;
  61. # Add Launchpad-Bugs-Fixed field
  62. my $bugs = find_launchpad_closes($fields->{"Changes"} || "");
  63. if (scalar(@$bugs)) {
  64. $fields->{"Launchpad-Bugs-Fixed"} = join(" ", @$bugs);
  65. }
  66. } else {
  67. return $self->SUPER::run_hook($hook, @params);
  68. }
  69. }
  70. =head1 PUBLIC FUNCTIONS
  71. =over
  72. =item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes)
  73. Takes one string as argument and finds "LP: #123456, #654321" statements,
  74. which are references to bugs on Launchpad. Returns all closed bug
  75. numbers in an array reference.
  76. =cut
  77. sub find_launchpad_closes {
  78. my ($changes) = @_;
  79. my @closes = ();
  80. while ($changes &&
  81. ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/ig)) {
  82. push(@closes, $& =~ /\#?\s?(\d+)/g);
  83. }
  84. @closes = sort { $a <=> $b } @closes;
  85. return \@closes;
  86. }
  87. =back
  88. =cut
  89. 1;