Ubuntu.pm 3.8 KB

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