Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate maintainer-approval flag & Improve cat/port detection #4

Open
wants to merge 1 commit into
base: freebsd-local
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 82 additions & 1 deletion extensions/BFBSD/lib/Helpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ use base qw(Exporter);
our @EXPORT = qw(
no_maintainer get_user ports_product ports_component
switch_to_automation
get_maintainers_of_bug _get_maintainer

UID_AUTOMATION
PRODUCT_PORTS
COMPONENT_PORTS
PORTSDIR
INDEX
PORT_CAT_LIST
);

use constant {
UID_AUTOMATION => "bugzilla\@FreeBSD.org",
PRODUCT_PORTS => "Ports & Packages",
COMPONENT_PORTS => "Individual Port(s)"
COMPONENT_PORTS => "Individual Port(s)",

#XXX Mokhi added inorder to avoid duplicated codes :)
PORTSDIR => "/usr/ports-dev",
INDEX => "INDEX",
PORT_CAT_LIST => "accessibility|arabic|archivers|astro|audio|benchmarks|biology|cad|chinese|comms|converters|databases|deskutils|devel|distfiles|dns|editors|emulators|finance|french|ftp|games|german|graphics|hebrew|hungarian|irc|japanese|java|korean|lang|mail|math|misc|multimedia|net|net\-im|net\-mgmt|net\-p2p|news|packages|palm|polish|ports\-mgmt|portuguese|print|russian|science|security|shells|sysutils|textproc|ukrainian|vietnamese|www|x11|x11\-clocks|x11\-drivers|x11\-fm|x11\-fonts|x11\-servers|x11\-themes|x11\-toolkits|x11\-wm",
};

sub ports_product {
Expand Down Expand Up @@ -66,4 +75,76 @@ sub switch_to_automation {
return $curuser;
};

#XXX Mokhi added inorder to avoid duplicated codes :)
sub get_maintainers_of_bug {
my ($bug) = @_;

my @foundports = ();

# Is it a port in summary matching ([A-Za-z0-9_-]/[A-Za-z0-9_-])?
#my @res = ($bug->short_desc =~ /(?:^|[:\[\s+])([\w-]+\/[\w-\.]+)(?:[:\]\s+]|$)/g);
my @res = ($bug->short_desc =~ /(?:^|\W)((${\(PORT_CAT_LIST)})\/([\w\-\+](\.(?=\w))*)+)(?:$|\b)*/g);
if (@res && scalar(@res) > 0) {
# warn("Found ports in summary: @res");
push(@foundports, @res);
}

if (scalar(@foundports) == 0) {
# Did not find a port in subject
# Is it a port in the description matching
# ([A-Za-z0-9_-]/[A-Za-z0-9_-])?
my $first = $bug->comments->[0]->body;
#@res = ($first =~ /(?:^|[:,\s+])([\w-]+\/[\w-\.]+)(?:[:,\s+]|$)/g);
@res = ($first =~ /(?:^|\W)((${\(PORT_CAT_LIST)})\/([\w\-\+](\.(?=\w))*)+)(?:$|\b)*/g);
if (@res && scalar(@res) > 0) {
# warn("Found ports in description: @res");
push(@foundports, @res);
}
}
# Remove duplicate entries.
my %hashed = map{$_, 1} @foundports;
@foundports = keys(%hashed);

# Add the maintainers of the affected ports to the CC. If there is
# only one person, add a feedback request for that person and
# optionally assign (if it is a committer), otherwise set all into
# CC.

my @maintainers = ();
foreach my $port (@foundports) {
my $maintainer = _get_maintainer($port);
if ($maintainer) {
push(@maintainers, $maintainer);
}
}

# Remove duplicate entries
%hashed = map{$_, 1} @maintainers;
@maintainers = keys(%hashed);

return @maintainers;
}

#XXX Mokhi added inorder to avoid duplicated codes :)
sub _get_maintainer {
# we expect _get_maintainer("category/port")
my $port = shift();
my $portdir = "" . PORTSDIR . "/$port";
# Does it exist and is a directory?
if (-d $portdir) {
# temporarily manipulate path to allow the exec
# to access all necessary tools
my $oldenv = $ENV{PATH};
$ENV{PATH} .= "/usr/bin:/usr/local/bin:/usr/local/sbin";
my $maintainer = `PORTSDIR=@{[PORTSDIR]} make -C $portdir -V MAINTAINER`;
$ENV{PATH} = $oldenv;
chomp($maintainer);
return $maintainer;
} else {
warn("Port directory $portdir not found");
}
return;
}


1;
12 changes: 12 additions & 0 deletions extensions/FBSDAttachments/Config.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Bugzilla::Extension::FBSDAttachments;
use strict;

use constant NAME => 'FBSDAttachments';

use constant REQUIRED_MODULES => [
];

use constant OPTIONAL_MODULES => [
];

__PACKAGE__->NAME;
59 changes: 59 additions & 0 deletions extensions/FBSDAttachments/Extension.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package Bugzilla::Extension::FBSDAttachments;

use strict;
use warnings;

use base qw(Bugzilla::Extension);

use Bugzilla::Comment;
use Bugzilla::Field;
use Bugzilla::FlagType;
use Bugzilla::Flag;
use Bugzilla::Mailer;
use Bugzilla::User;
use Bugzilla::Attachment;

use Bugzilla::Extension::BFBSD::Helpers;

our $VERSION = '0.3.0';

sub attachment_process_data {
my ($self, $args) = @_;
my $data = $args->{'data'}; # XXX Maybe not needed
my $attrs = $args->{'attributes'};
my $dbh = Bugzilla->dbh; # XXX Maybe not needed

my $bug = $attrs->{'bug'};
my $attacher = Bugzilla->user;
my $is_patch = $attrs->{'ispatch'};

# We only add CCs, if it is a individual port bug
return if ( (!defined($bug) || !defined($attacher)) || ($bug->product ne PRODUCT_PORTS || $bug->component ne COMPONENT_PORTS) );

my @maintainers = get_maintainers_of_bug($bug);

if (defined($is_patch) && $is_patch) {
my $flag_approval;
my $flagtypes = Bugzilla::FlagType::match( { name => 'maintainer-approval' } );
if (scalar(@$flagtypes) == 1) {
$flag_approval = @{$flagtypes}[0];
}
if (!$flag_approval) {
warn("maintainer-approval flag not found");
} else {
my (@oldflags, @newflags);

#XXX maybe "$_->id == $attacher->id" is better for cmp
if (grep($_ == $attacher->login, @maintainers)) {
push(@newflags, { type_id => $flag_approval->id, status => "+", requestee => $attacher->login });
$bug->set_flags(\@oldflags, \@newflags);
} else {
push(@newflags, { type_id => $flag_approval->id, status => "?", requestee => @maintainers });
$bug->set_flags(\@oldflags, \@newflags);
}
}
}

}

__PACKAGE__->NAME;
8 changes: 5 additions & 3 deletions extensions/FBSDAutoAssign/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ sub bug_end_of_create {
my @foundports = ();

# Is it a port patch in summary matching ([A-Za-z0-9_-]/[A-Za-z0-9_-])?
my @res = ($bug->short_desc =~ /(?:^|[:\[\s+])([\w\-]+\/[\w\-\.]+)(?:[:\]\s+]|$)/g);
#my @res = ($bug->short_desc =~ /(?:^|[:\[\s+])([\w-]+\/[\w-\.]+)(?:[:\]\s+]|$)/g);
my @res = ($bug->short_desc =~ /(?:^|\W)((${\(PORT_CAT_LIST)})\/([\w\-\+](\.(?=\w))*)+)(?:$|\b)*/g);
if (@res && scalar(@res) > 0) {
# warn("Found ports in summary: @res");
push(@foundports, @res);
Expand All @@ -81,7 +82,8 @@ sub bug_end_of_create {
# Is it a port in the description matching
# ([A-Za-z0-9_-]/[A-Za-z0-9_-])?
my $first = $bug->comments->[0]->body;
@res = ($first =~ /(?:^|[:,\s+])([\w\-]+\/[\w\-\.]+)(?:[:,\s+]|$)/g);
#@res = ($first =~ /(?:^|[:,\s+])([\w-]+\/[\w-\.]+)(?:[:,\s+]|$)/g);
@res = ($first =~ /(?:^|\W)((${\(PORT_CAT_LIST)})\/([\w\-\+](\.(?=\w))*)+)(?:$|\b)*/g);
if (@res && scalar(@res) > 0) {
# warn("Found ports in description: @res");
push(@foundports, @res);
Expand All @@ -102,7 +104,7 @@ sub bug_end_of_create {
my $maintainer = _get_maintainer($port);
if ($maintainer) {
push(@maintainers, $maintainer);
push(@categories, $port =~ /^([\w\-]+)\/[\w\-\.]+$/g);
push(@categories, $port =~ /^([\w-]+)\/[\w-\.]+$/g);
}
}

Expand Down