Ubuntu.pm 3.9 KB

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