Skip to content

Commit

Permalink
fenix: add support for GitHub commits
Browse files Browse the repository at this point in the history
  • Loading branch information
hadfl committed Jan 31, 2025
1 parent 51eb45a commit 0f8eae7
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/Fenix/Model/Handler/Help.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sub process_p($self, $chan, $from, $msg, $mentioned = 0) {
$preface
I can look up Redmine issues with 'illumos <issue>', 'issue <issue>' or '#<issue>'
For SmartOS issues, use the issue type and number together, e.g. OS-1234.
I will look up GitHub commits if you ask with '<org|user>/<repository>#<commit_hash>'.
I can also find IPDs - 'IPD123', 'IPD-123' or 'IPD 123'
as well as OpenSolaris issues with a seven digit bug ID. If you want me to, I can also
dig very deeply and find stuff in the OpenSolaris ARC Material Archive, just use e.g. FWARC/2004/510.
Expand Down
2 changes: 1 addition & 1 deletion lib/Fenix/Model/Handler/Issue/Gerrit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ has issuestr => sub { 'code review' };

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either a valid issue or undef.
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
my $baseurl = $self->baseurl->to_string;
my $urlre = qr!\b\Q$baseurl\E/c/illumos-gate/\+/(\d+)\b!;
Expand Down
89 changes: 89 additions & 0 deletions lib/Fenix/Model/Handler/Issue/GitHub.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package Fenix::Model::Handler::Issue::GitHub;
use Mojo::Base 'Fenix::Model::Handler::Issue::base', -signatures;

use Mojo::URL;

# attributes
has priority => 7;
has baseurl => sub { Mojo::URL->new('https://github.com') };
has issuestr => sub { 'GitHub commit' };

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
my $baseurl = $self->baseurl->to_string;
my $urlre = qr§\b\Q$baseurl\E/((?:[^/]+/){2}commit/[[:xdigit:]]+)$§;
for ($msg) {
return ([ /$urlre/g ], { url => 1 }) if /$urlre/;
return [ m!\b([^/\s]+/[^#\s]+#[[:xdigit:]]+)\b!g ];
}

return [];
}

sub issueURL($self, $issue) {
return Mojo::URL->new("/$issue.patch")->base($self->baseurl)->to_abs
if $issue =~ m!/commit/!;

my ($orgrepo, $hash) = split /#/, $issue, 2;

return Mojo::URL->new("/$orgrepo/commit/$hash.patch")->base($self->baseurl)->to_abs;
}

sub processIssue($self, $issue, $res) {
my ($orgrepo) = split /#/, $issue, 2;

# we are only interested in the first 4 lines (the header), drop everything else
my @data = split /\r?\n/, $res->body, 5;
pop @data;

my ($fullhash) = map { /^From\s+([[:xdigit:]]+)/ } @data;
my $hash = substr $fullhash, 0, 7;

my ($subject) = map { /^Subject:\s+\[PATCH\]\s+(.+)/ } @data;
# strip Reviewed by if it occurs on the first commit message line
$subject =~ s/\s+Reviewed.*//;

my ($author) = map { /^From:\s+([^<]+)\s+</ } @data;

return {
id => $self->issuestr . " $hash",
subject => $subject,
url => [ Mojo::URL->new("/$orgrepo/commit/$fullhash")->base($self->baseurl)->to_abs ],
status => 'committed',
author => $author,
assigned_to => '',
};
}

1;

__END__
=head1 COPYRIGHT
Copyright 2025 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see L<http://www.gnu.org/licenses/>.
=head1 AUTHOR
S<Dominik Hassler E<lt>[email protected]E<gt>>
=head1 HISTORY
2025-01-31 had Initial Version
=cut
2 changes: 1 addition & 1 deletion lib/Fenix/Model/Handler/Issue/IPD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ has issuestr => sub { 'IPD' };

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either a valid issue or undef.
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
my $baseurl = $GITHUB->to_string;
my $urlre = qr!\b\Q$baseurl\E/illumos/ipd/\S+/ipd/0+(\d+)/README\.md\b!i;
Expand Down
2 changes: 1 addition & 1 deletion lib/Fenix/Model/Handler/Issue/Illumos.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ has baseurl => sub { Mojo::URL->new('https://www.illumos.org') };

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either a valid issue or undef.
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
my $baseurl = $self->baseurl->to_string;
my $urlre = qr!\b\Q$baseurl\E/issues/(\d+)\b!;
Expand Down
2 changes: 1 addition & 1 deletion lib/Fenix/Model/Handler/Issue/OpenSolaris.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ has issuestr => sub { 'OpenSolaris issue' };

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either a valid issue or undef.
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
my $baseurl = $self->baseurl->to_string;
my $urlre = qr§\b\Q$baseurl\E/opensolaris/bugdb/bug\.html#!(\d{7})\b§;
Expand Down
2 changes: 1 addition & 1 deletion lib/Fenix/Model/Handler/Issue/SmartOS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ has baseurl => sub { Mojo::URL->new('https://smartos.org') };

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either a valid issue or undef.
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
my $baseurl = $self->baseurl->to_string;
my $urlre = qr!\b\Q$baseurl\E/bugview/([A-Z]+-\d+)\b!;
Expand Down
2 changes: 1 addition & 1 deletion lib/Fenix/Model/Handler/Issue/XXARC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ has issuestr => sub { 'OpenSolaris ARC Material Archive' };

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either a valid issue or undef.
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
my $baseurl = $self->baseurl->to_string;
my $urlre = qr§\b\Q$baseurl\E/opensolaris/ARChive/((?:FW|LS|PS|WS)ARC/\d{4}/\d{3})/§;
Expand Down
2 changes: 1 addition & 1 deletion lib/Fenix/Model/Handler/Issue/base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ has ua => sub {

# issue should be called first in 'process'.
# It parses the message and checks whether it is the correct handler
# return either a valid issue or undef.
# return either an array ref of valid URLs or an empty array
sub issues($self, $msg) {
return [];
}
Expand Down

0 comments on commit 0f8eae7

Please sign in to comment.