App-Kritika
view release on metacpan or search on metacpan
kritika.fatpack view on Meta::CPAN
#!/usr/bin/env perl
# This chunk of stuff was generated by App::FatPacker. To find the original
# file's code, look for the end of this BEGIN block or the string 'FATPACK'
BEGIN {
my %fatpacked;
$fatpacked{"App/Kritika.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'APP_KRITIKA';
package App::Kritika;use strict;use warnings;our$VERSION='0.05';use JSON ();use Cwd qw(abs_path);use HTTP::Tiny;sub new {my$class=shift;my (%params)=@_;my$self={};bless$self,$class;$self->{base_url}=$params{base_url}|| 'https://kritika.io';$self->{...
APP_KRITIKA
$fatpacked{"App/Kritika/Settings.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'APP_KRITIKA_SETTINGS';
package App::Kritika::Settings;use strict;use warnings;use Cwd qw(getcwd);use File::Basename qw(dirname);use File::Spec;use File::HomeDir ();sub new {my$class=shift;my (%params)=@_;my$self={};bless$self,$class;$self->{file}=$params{file};return$sel...
APP_KRITIKA_SETTINGS
$fatpacked{"ExtUtils/Config.pm"} = '#line '.(1+__LINE__).' "'.__FILE__."\"\n".<<'EXTUTILS_CONFIG';
package ExtUtils::Config;$ExtUtils::Config::VERSION='0.05';use strict;use warnings;use Config;use Data::Dumper ();sub new {my ($pack,$args)=@_;return bless {values=>($args ? {%$args }: {}),},$pack}sub get {my ($self,$key)=@_;return exists$self->{va...
EXTUTILS_CONFIG
kritika.fatpack view on Meta::CPAN
my $kritika = App::Kritika->new(
%$settings,
diff_branch => $opt_diff_branch,
diff_ref => $opt_diff_ref,
diff_snapshot => $opt_diff_snapshot
);
my $issues_found = 0;
my $report = $kritika->validate(@files);
if ( $report->{success} ) {
print "No violations found\n";
exit 0;
}
else {
foreach my $file ( @{ $report->{files} } ) {
if ( $file->{success} ) {
print "$file->{path}:OK\n";
lib/App/Kritika.pm view on Meta::CPAN
$self->{branch} = $params{branch};
$self->{branch} = $self->_detect_branch unless defined $self->{branch};
$self->{revision} = $params{revision};
$self->{revision} = $self->_detect_revision
unless defined $self->{revision};
return $self;
}
sub validate {
my $self = shift;
my (@paths) = @_;
my $files = [];
foreach my $path (@paths) {
$path = abs_path($path);
my $content = do {
local $/;
lib/App/Kritika.pm view on Meta::CPAN
push @$files,
{
path => $path,
content => $content
};
}
my $ua = $self->{ua};
my $response = $ua->post(
"$self->{base_url}/validate",
{
headers => {
Authorization => 'Token ' . $self->{token},
Accept => 'application/json',
'X-Version' => $VERSION,
},
content => JSON->new->canonical(1)->encode(
{
branch => $self->{branch},
revision => $self->{revision},
script/kritika view on Meta::CPAN
my $kritika = App::Kritika->new(
%$settings,
diff_branch => $opt_diff_branch,
diff_ref => $opt_diff_ref,
diff_snapshot => $opt_diff_snapshot
);
my $issues_found = 0;
my $report = $kritika->validate(@files);
if ( $report->{success} ) {
print "No violations found\n";
exit 0;
}
else {
foreach my $file ( @{ $report->{files} } ) {
if ( $file->{success} ) {
print "$file->{path}:OK\n";
t/kritika.t view on Meta::CPAN
use Test::More;
use Test::MonkeyMock;
use Test::Fatal;
use Test::TempDir::Tiny;
use Test::Deep;
use JSON ();
use_ok 'App::Kritika';
subtest 'validate: submits correct file' => sub {
my $tempdir = tempdir();
my $ua = _mock_ua();
my $kritika = _build_kritika(
base_url => 'http://localhost',
token => 'deadbeef',
root => $tempdir,
branch => 'master',
revision => 'deadbeef',
ua => $ua
);
_touch_file( "$tempdir/file.txt", 'hello there' );
$kritika->validate("$tempdir/file.txt");
my ( $url, $options ) = $ua->mocked_call_args('post');
cmp_deeply $options,
{
headers =>
{ Authorization => 'Token deadbeef', Accept => 'application/json', 'X-Version' => ignore() },
content => JSON->new->canonical(1)->encode(
{
branch => 'master',
revision => 'deadbeef',
t/kritika.t view on Meta::CPAN
{
path => 'file.txt',
content => 'hello there'
}
]
}
)
};
};
subtest 'validate: returns parsed issues' => sub {
my $tempdir = tempdir();
my $ua = _mock_ua();
my $kritika = _build_kritika(
base_url => 'http://localhost',
token => 'deadbeef',
root => $tempdir,
branch => 'master',
revision => 'deadbeef',
ua => $ua
);
_touch_file( "$tempdir/file.txt", 'hello there' );
my $issues = $kritika->validate("$tempdir/file.txt");
is_deeply $issues, [ { line_no => 1, message => 'Oops' } ];
};
subtest 'validate: throws on internal error' => sub {
my $tempdir = tempdir();
my $ua = _mock_ua( post =>
sub { { success => 0, status => 599, content => 'Cant connect' } } );
my $kritika = _build_kritika(
base_url => 'http://localhost',
token => 'deadbeef',
root => $tempdir,
branch => 'master',
revision => 'deadbeef',
ua => $ua
);
_touch_file( "$tempdir/file.txt", 'hello there' );
like exception { $kritika->validate("$tempdir/file.txt") },
qr/Cant connect/;
};
subtest 'validate: throws on remote error' => sub {
my $tempdir = tempdir();
my $ua = _mock_ua(
post => sub { { success => 0, status => 404, reason => 'Not found' } }
);
my $kritika = _build_kritika(
base_url => 'http://localhost',
token => 'deadbeef',
root => $tempdir,
branch => 'master',
revision => 'deadbeef',
ua => $ua
);
_touch_file( "$tempdir/file.txt", 'hello there' );
like exception { $kritika->validate("$tempdir/file.txt") }, qr/Not found/;
};
done_testing;
sub _mock_ua {
my (%params) = @_;
my $ua = Test::MonkeyMock->new;
$ua->mock(
post => $params{post} || sub {
( run in 0.307 second using v1.01-cache-2.11-cpan-beeb90c9504 )