# This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # AutoAssign # AutoAssign/lib # AutoAssign/lib/Util.pm # AutoAssign/web # AutoAssign/web/README # AutoAssign/template # AutoAssign/template/en # AutoAssign/template/en/default # AutoAssign/template/en/default/hook # AutoAssign/template/en/default/hook/README # AutoAssign/template/en/default/autoassign # AutoAssign/template/en/default/autoassign/README # AutoAssign/Config.pm # AutoAssign/Extension.pm # echo c - AutoAssign mkdir -p AutoAssign > /dev/null 2>&1 echo c - AutoAssign/lib mkdir -p AutoAssign/lib > /dev/null 2>&1 echo x - AutoAssign/lib/Util.pm sed 's/^X//' >AutoAssign/lib/Util.pm << 'ce3e7c3b4bf3da8aad733bc2be89ffa0' Xpackage Bugzilla::Extension::AutoAssign::Util; Xuse strict; Xuse base qw(Exporter); Xour @EXPORT = qw( X X); X X# This file can be loaded by your extension via X# "use Bugzilla::Extension::AutoAssign::Util". You can put functions X# used by your extension in here. (Make sure you also list them in X# @EXPORT.) X X1; ce3e7c3b4bf3da8aad733bc2be89ffa0 echo c - AutoAssign/web mkdir -p AutoAssign/web > /dev/null 2>&1 echo x - AutoAssign/web/README sed 's/^X//' >AutoAssign/web/README << '4ee4597f4630407d06274d97bf51f841' XWeb-accessible files, like JavaScript, CSS, and images go in this Xdirectory. You can reference them directly in your HTML. For example, Xif you have a file called "style.css" and your extension is called X"Foo", you would put it in "extensions/Foo/web/style.css", and then Xyou could link to it in HTML like: X X 4ee4597f4630407d06274d97bf51f841 echo c - AutoAssign/template mkdir -p AutoAssign/template > /dev/null 2>&1 echo c - AutoAssign/template/en mkdir -p AutoAssign/template/en > /dev/null 2>&1 echo c - AutoAssign/template/en/default mkdir -p AutoAssign/template/en/default > /dev/null 2>&1 echo c - AutoAssign/template/en/default/hook mkdir -p AutoAssign/template/en/default/hook > /dev/null 2>&1 echo x - AutoAssign/template/en/default/hook/README sed 's/^X//' >AutoAssign/template/en/default/hook/README << '894acadca9c71f62c4b1fad8f34ea3e9' XTemplate hooks go in this directory. Template hooks are called in normal XBugzilla templates like [% Hook.process('some-hook') %]. XMore information about them can be found in the documentation of XBugzilla::Extension. (Do "perldoc Bugzilla::Extension" from the main XBugzilla directory to see that documentation.) 894acadca9c71f62c4b1fad8f34ea3e9 echo c - AutoAssign/template/en/default/autoassign mkdir -p AutoAssign/template/en/default/autoassign > /dev/null 2>&1 echo x - AutoAssign/template/en/default/autoassign/README sed 's/^X//' >AutoAssign/template/en/default/autoassign/README << 'b2bc3ef4052ce696619db2a3070432b2' XNormal templates go in this directory. You can load them in your Xcode like this: X Xuse Bugzilla::Error; Xmy $template = Bugzilla->template; X$template->process('autoassign/some-template.html.tmpl') X or ThrowTemplateError($template->error()); X XThat would be how to load a file called some-template.html.tmpl that Xwas in this directory. X XNote that you have to be careful that the full path of your template Xnever conflicts with a template that exists in Bugzilla or in Xanother extension, or your template might override that template. That's why Xwe created this directory called 'autoassign' for you, so you Xcan put your templates in here to help avoid conflicts. b2bc3ef4052ce696619db2a3070432b2 echo x - AutoAssign/Config.pm sed 's/^X//' >AutoAssign/Config.pm << 'e9523e423617d00b0c9c8de25b2e38ef' Xpackage Bugzilla::Extension::AutoAssign; Xuse strict; X Xuse constant NAME => 'AutoAssign'; X Xuse constant REQUIRED_MODULES => [ X]; X Xuse constant OPTIONAL_MODULES => [ X]; X X__PACKAGE__->NAME; e9523e423617d00b0c9c8de25b2e38ef echo x - AutoAssign/Extension.pm sed 's/^X//' >AutoAssign/Extension.pm << '5bcf3b8840d5d4199deeb65546f8b3b6' Xpackage Bugzilla::Extension::AutoAssign; Xuse strict; Xuse base qw(Bugzilla::Extension); X Xuse Bugzilla::Comment; Xuse Bugzilla::Field; Xuse Bugzilla::User; X Xuse constant { X PORTSDIR => "/usr/ports", X INDEX => "INDEX", X # Needs to be changed to some an internal user X UID_AUTOASSIGN => "bugzilla-noreply\@FreeBSD.org", X # We want a comment about the automatic CC X AUTOCOMMENT => 1 X}; X Xour $VERSION = '0.1.0'; X Xsub bug_end_of_create { X my ($self, $args) = @_; X my $bug = $args->{'bug'}; X X # We only add CCs, if it is a individual port bug X my $product = $bug->product; X my $component = $bug->component; X if ($product ne "Ports Tree" || X $component ne "Individual Port(s)") { X warn("meh: '$product' : '$component'"); X return; X } X X my @foundports = (); X X # Is it a port patch in summary matching ([A-Za-z0-9_-]/[A-Za-z0-9_-])? X my @res = ($bug->short_desc =~ /([\w-]+\/[\w-]+)/g); X if (@res && scalar (@res) > 0) { X warn("Found ports in summary: @res"); X push(@foundports, @res); X } X X # Is it a port in the description matching ([A-Za-z0-9_-]/[A-Za-z0-9_-])? X my $first = $bug->comments->[0]->body; X @res = ($first =~ /([\w-]+\/[\w-]+)/g); X if (@res && scalar (@res) > 0) { X warn("Found ports in description: @res"); X push(@foundports, @res); X } X X # TODO: scan attachment(s) X X # Remove duplicate entries. X my %hashed = map{$_, 1} @foundports; X @foundports = keys(%hashed); X warn("Unique ports: @foundports"); X X # Sync with the cf_ports_affected list. cf_ports_affected in a X # comma-separated list of / entries X my @newlyadded = (); X my @affected = split(",", $bug->cf_ports_affected); X %hashed = map{$_, 1} @affected; X foreach my $port (@foundports) { X if (!exists($hashed{$port})) { X push(@affected, $port); X push(@newlyadded, $port); X } X } X X # Store the new affected port list back to the cf_ field X my $field = new Bugzilla::Field({ name => "cf_ports_affected"}); X $bug->set_custom_field($field, join(",", @affected)); X X # Add the maintainers of the newly added ports to the CC. X my $someoneccd = 0; X foreach my $port (@newlyadded) { X my $fname = "" . PORTSDIR . "/$port/Makefile"; X if (open(my $file, "<", $fname)) { X my @maintainer = grep(s/^MAINTAINER=[ \t]+(.*)\s$/$1/, <$file>); X if (@maintainer) { X my $userid = login_to_id($maintainer[0]); X if ($userid) { X my $user = new Bugzilla::User($userid); X if ($user) { X # TODO: filter already added users X $bug->add_cc($user); X $someoneccd = 1; X } else { X warn("Could not find user for '$maintainer[0]'"); X } X } else { X warn("Could not find user id for '$maintainer[0]'"); X } X } else { X warn("Could not find MAINTAINER in $fname"); X } X close($file); X } else { X warn("Could not open $fname"); X } X } X X if (AUTOCOMMENT != 0 && $someoneccd != 0) { X warn("Adding comment"); X my $autoid = login_to_id(UID_AUTOASSIGN); X if ($autoid) { X my $curuser = Bugzilla->user; X # Do not set a comment, if the user does not exist. X Bugzilla->set_user(new Bugzilla::User($autoid)); X $bug->add_comment("Maintainers CC'd"); X Bugzilla->set_user($curuser); X } X } X return; X} X X__PACKAGE__->NAME; 5bcf3b8840d5d4199deeb65546f8b3b6 exit