Ubuntu.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. =head1 NAME
  28. Dpkg::Vendor::Ubuntu - Ubuntu vendor object
  29. =head1 DESCRIPTION
  30. This vendor object customize the behaviour of dpkg-source
  31. to check that Maintainers have been modified if necessary.
  32. =cut
  33. sub run_hook {
  34. my ($self, $hook, @params) = @_;
  35. if ($hook eq "before-source-build") {
  36. my $src = shift @params;
  37. my $fields = $src->{'fields'};
  38. # check that Maintainer/XSBC-Original-Maintainer comply to
  39. # https://wiki.ubuntu.com/DebianMaintainerField
  40. if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
  41. $fields->{'Version'} =~ /ubuntu/) {
  42. if ($fields->{'Maintainer'} !~ /ubuntu/i) {
  43. if (defined ($ENV{'DEBEMAIL'}) and $ENV{'DEBEMAIL'} =~ /\@ubuntu\.com/) {
  44. error(_g('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
  45. } else {
  46. warning(_g('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
  47. }
  48. }
  49. unless ($fields->{'Original-Maintainer'}) {
  50. warning(_g('Version number suggests Ubuntu changes, but there is no XSBC-Original-Maintainer field'));
  51. }
  52. }
  53. } elsif ($hook eq "keyrings") {
  54. my @keyrings = $self->SUPER::run_hook($hook);
  55. push(@keyrings, '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
  56. return @keyrings;
  57. } elsif ($hook eq "register-custom-fields") {
  58. my @field_ops = $self->SUPER::run_hook($hook);
  59. push @field_ops,
  60. [ "register", "Launchpad-Bugs-Fixed",
  61. CTRL_FILE_CHANGES | CTRL_CHANGELOG ],
  62. [ "insert_after", CTRL_FILE_CHANGES, "Closes", "Launchpad-Bugs-Fixed" ],
  63. [ "insert_after", CTRL_CHANGELOG, "Closes", "Launchpad-Bugs-Fixed" ];
  64. return @field_ops;
  65. } elsif ($hook eq "post-process-changelog-entry") {
  66. my $fields = shift @params;
  67. # Add Launchpad-Bugs-Fixed field
  68. my $bugs = find_launchpad_closes($fields->{"Changes"} || "");
  69. if (scalar(@$bugs)) {
  70. $fields->{"Launchpad-Bugs-Fixed"} = join(" ", @$bugs);
  71. }
  72. } else {
  73. return $self->SUPER::run_hook($hook, @params);
  74. }
  75. }
  76. =head1 PUBLIC FUNCTIONS
  77. =over
  78. =item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes)
  79. Takes one string as argument and finds "LP: #123456, #654321" statements,
  80. which are references to bugs on Launchpad. Returns all closed bug
  81. numbers in an array reference.
  82. =cut
  83. sub find_launchpad_closes {
  84. my ($changes) = @_;
  85. my %closes;
  86. while ($changes &&
  87. ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/ig)) {
  88. $closes{$_} = 1 foreach($& =~ /\#?\s?(\d+)/g);
  89. }
  90. my @closes = sort { $a <=> $b } keys %closes;
  91. return \@closes;
  92. }
  93. =back
  94. =cut
  95. 1;