diff options
Diffstat (limited to 'extensions/ContributorEngagement')
4 files changed, 222 insertions, 0 deletions
diff --git a/extensions/ContributorEngagement/Config.pm b/extensions/ContributorEngagement/Config.pm new file mode 100644 index 000000000..3984dd60e --- /dev/null +++ b/extensions/ContributorEngagement/Config.pm @@ -0,0 +1,19 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::ContributorEngagement; +use strict; + +use constant NAME => 'ContributorEngagement'; + +use constant REQUIRED_MODULES => [ +]; + +use constant OPTIONAL_MODULES => [ +]; + +__PACKAGE__->NAME; diff --git a/extensions/ContributorEngagement/Extension.pm b/extensions/ContributorEngagement/Extension.pm new file mode 100644 index 000000000..def41b6ea --- /dev/null +++ b/extensions/ContributorEngagement/Extension.pm @@ -0,0 +1,123 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::ContributorEngagement; + +use strict; +use warnings; + +use base qw(Bugzilla::Extension); + +use Bugzilla::User; +use Bugzilla::Util qw(format_time); +use Bugzilla::Mailer; +use Bugzilla::Install::Util qw(indicate_progress); + +use Bugzilla::Extension::ContributorEngagement::Constants; + +our $VERSION = '2.0'; + +BEGIN { + *Bugzilla::User::first_patch_reviewed_id = \&_first_patch_reviewed_id; +} + +sub _first_patch_reviewed_id { return $_[0]->{'first_patch_reviewed_id'}; } + +sub install_update_db { + my ($self) = @_; + my $dbh = Bugzilla->dbh; + + if ($dbh->bz_column_info('profiles', 'first_patch_approved_id')) { + $dbh->bz_drop_column('profiles', 'first_patch_approved_id'); + } + if (!$dbh->bz_column_info('profiles', 'first_patch_reviewed_id')) { + $dbh->bz_add_column('profiles', 'first_patch_reviewed_id', { TYPE => 'INT3' }); + _populate_first_reviewed_ids(); + } +} + +sub _populate_first_reviewed_ids { + my $dbh = Bugzilla->dbh; + + my $sth = $dbh->prepare('UPDATE profiles SET first_patch_reviewed_id = ? WHERE userid = ?'); + my $ra = $dbh->selectall_arrayref("SELECT attachments.submitter_id, + attachments.attach_id + FROM attachments + INNER JOIN flags ON attachments.attach_id = flags.attach_id + INNER JOIN flagtypes ON flags.type_id = flagtypes.id + WHERE flagtypes.name LIKE 'review%' AND flags.status = '+' + ORDER BY flags.modification_date"); + my $count = 1; + my $total = scalar @$ra; + my %user_seen; + foreach my $ra_row (@$ra) { + my ($user_id, $attach_id) = @$ra_row; + indicate_progress({ current => $count++, total => $total, every => 25 }); + next if $user_seen{$user_id}; + $sth->execute($attach_id, $user_id); + $user_seen{$user_id} = 1; + } + + print "done\n"; +} + +sub object_columns { + my ($self, $args) = @_; + my ($class, $columns) = @$args{qw(class columns)}; + if ($class->isa('Bugzilla::User')) { + push(@$columns, 'first_patch_reviewed_id'); + } +} + +sub flag_end_of_update { + my ($self, $args) = @_; + my ($object, $timestamp, $new_flags) = @$args{qw(object timestamp new_flags)}; + + if ($object->isa('Bugzilla::Attachment') + && @$new_flags + && !$object->attacher->first_patch_reviewed_id + && grep($_ eq $object->bug->product, ENABLED_PRODUCTS)) + { + my $attachment = $object; + + foreach my $orig_change (@$new_flags) { + my $change = $orig_change; + $change =~ s/^[^:]+://; # get rid of setter + $change =~ s/\([^\)]+\)$//; # get rid of requestee + my ($name, $value) = $change =~ /^(.+)(.)$/; + + # Only interested in review flags set to + + next unless $name =~ /^review/ && $value eq '+'; + + _send_mail($attachment, $timestamp); + + Bugzilla->dbh->do("UPDATE profiles SET first_patch_reviewed_id = ? WHERE userid = ?", + undef, $attachment->id, $attachment->attacher->id); + Bugzilla->memcached->clear({ table => 'profiles', id => $attachment->attacher->id }); + last; + } + } +} + +sub _send_mail { + my ($attachment, $timestamp) = @_; + + my $vars = { + date => format_time($timestamp, '%a, %d %b %Y %T %z', 'UTC'), + attachment => $attachment, + from_user => EMAIL_FROM, + }; + + my $msg; + my $template = Bugzilla->template_inner($attachment->attacher->setting('lang')); + $template->process("contributor/email.txt.tmpl", $vars, \$msg) + || ThrowTemplateError($template->error()); + + MessageToMTA($msg); +} + +__PACKAGE__->NAME; diff --git a/extensions/ContributorEngagement/lib/Constants.pm b/extensions/ContributorEngagement/lib/Constants.pm new file mode 100644 index 000000000..346e00c35 --- /dev/null +++ b/extensions/ContributorEngagement/lib/Constants.pm @@ -0,0 +1,31 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::ContributorEngagement::Constants; + +use strict; + +use base qw(Exporter); + +our @EXPORT = qw( + EMAIL_FROM + ENABLED_PRODUCTS +); + +use constant EMAIL_FROM => 'bugzilla-daemon@mozilla.org'; + +use constant ENABLED_PRODUCTS => ( + "Core", + "Firefox", + "Firefox for Android", + "Firefox for Metro", + "Mozilla Services", + "Testing", + "Toolkit", +); + +1; diff --git a/extensions/ContributorEngagement/template/en/default/contributor/email.txt.tmpl b/extensions/ContributorEngagement/template/en/default/contributor/email.txt.tmpl new file mode 100644 index 000000000..915ebd912 --- /dev/null +++ b/extensions/ContributorEngagement/template/en/default/contributor/email.txt.tmpl @@ -0,0 +1,49 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] +[% PROCESS "global/variables.none.tmpl" %] +From: [% from_user FILTER none %] +To: [% attachment.attacher.email FILTER none %] +Subject: Congratulations on having your first patch approved +Date: [% date FILTER none %] +X-Bugzilla-Type: contributor-engagement + +Congratulations on having your first patch approved, and thank you for your +contribution to Mozilla. + +[%+ urlbase %]attachment.cgi?id=[% attachment.id FILTER uri %]&action=edit + +The next step is to get the patch actually checked in to our repository. For +more information about how to make that happen, check out this post: + +https://developer.mozilla.org/en-US/docs/Mercurial_FAQ#How_can_I_generate_a_patch_for_somebody_else_to_check-in_for_me.3F + +While you are going through those final steps, if you're looking for a new +project to take on, have a look at our list of 'mentored' [% terms.bugs %] ([% terms.bugs %] where +someone is specifically available to help you): + +https://bugzil.la/sw:mentor + +Alternatively, you could join us on our IRC chat server in the #introduction +channel and ask for suggestions about what would be a good [% terms.bugs %] to work on. +There's more about using our chat server at: + +http://irc.mozilla.org/ + +If you haven't done so already, this is also a good time to sign up to the +Mozilla Contributor Directory and create a profile for yourself. Doing this +will give you access to community members' profiles so you can reach out and +connect with other Mozillians. You will need someone to 'vouch for' your +profile; if you don't know any other Mozillians well, why not contact the +person who approved your patch? + +The directory is here: + +https://mozillians.org/ + +Thanks again for your help :-) +Josh, Kyle, Dietrich and Brian; Coding Stewards |