Merge pull request #1002 from DeterminateSystems/perlcritic

Check the perl with perlcritic
This commit is contained in:
Graham Christensen 2021-08-20 14:28:35 -04:00 committed by GitHub
commit 4aa6a7b6ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 114 additions and 18 deletions

4
.perlcriticrc Normal file
View file

@ -0,0 +1,4 @@
theme = community
# 5 is the least complainy, 1 is the most complainy
severity = 5

View file

@ -106,17 +106,33 @@ conflicts with services that might be running on your host, hydra and postgress
Note that this is only ever meant as an ad-hoc way of executing Hydra during development. Please make use of the Note that this is only ever meant as an ad-hoc way of executing Hydra during development. Please make use of the
NixOS module for actually running Hydra in production. NixOS module for actually running Hydra in production.
### Running Tests ### Checking your patches
After making your changes, verify the test suite still passes. After following the steps in [Development Environment](#development-environment), run: After making your changes, verify the test suite passes and perlcritic is still happy.
Start by following the steps in [Development Environment](#development-environment).
Then, you can run the tests and the perlcritic linter together with:
```console
$ nix-shell
$ make check
```
You can run a single test with:
``` ```
$ nix-shell $ nix-shell
$ make check
$ # Or, to run a single test, use:
$ yath test ./t/foo/bar.t $ yath test ./t/foo/bar.t
``` ```
And you can run just perlcritic with:
```
$ nix-shell
$ make perlcritic
```
### JSON API ### JSON API
You can also interface with Hydra through a JSON API. The API is defined in [hydra-api.yaml](./hydra-api.yaml) and you can test and explore via the [swagger editor](https://editor.swagger.io/?url=https://raw.githubusercontent.com/NixOS/hydra/master/hydra-api.yaml) You can also interface with Hydra through a JSON API. The API is defined in [hydra-api.yaml](./hydra-api.yaml) and you can test and explore via the [swagger editor](https://editor.swagger.io/?url=https://raw.githubusercontent.com/NixOS/hydra/master/hydra-api.yaml)

View file

@ -345,6 +345,66 @@
}; };
}; };
PerlCriticCommunity = prev.perlPackages.buildPerlModule {
pname = "Perl-Critic-Community";
version = "1.0.0";
src = final.fetchurl {
url = "mirror://cpan/authors/id/D/DB/DBOOK/Perl-Critic-Community-v1.0.0.tar.gz";
sha256 = "311b775da4193e9de94cf5225e993cc54dd096ae1e7ef60738cdae1d9b8854e7";
};
buildInputs = with final.perlPackages; [ ModuleBuildTiny ];
propagatedBuildInputs = with final.perlPackages; [ PPI PathTiny PerlCritic PerlCriticPolicyVariablesProhibitLoopOnHash PerlCriticPulp ];
meta = {
homepage = "https://github.com/Grinnz/Perl-Critic-Freenode";
description = "Community-inspired Perl::Critic policies";
license = final.lib.licenses.artistic2;
};
};
PerlCriticPolicyVariablesProhibitLoopOnHash = prev.perlPackages.buildPerlPackage {
pname = "Perl-Critic-Policy-Variables-ProhibitLoopOnHash";
version = "0.008";
src = final.fetchurl {
url = "mirror://cpan/authors/id/X/XS/XSAWYERX/Perl-Critic-Policy-Variables-ProhibitLoopOnHash-0.008.tar.gz";
sha256 = "12f5f0be96ea1bdc7828058577bd1c5c63ca23c17fac9c3709452b3dff5b84e0";
};
propagatedBuildInputs = with final.perlPackages; [ PerlCritic ];
meta = {
description = "Don't write loops on hashes, only on keys and values of hashes";
license = with final.lib.licenses; [ artistic1 gpl1Plus ];
};
};
PerlCriticPulp = prev.perlPackages.buildPerlPackage {
pname = "Perl-Critic-Pulp";
version = "99";
src = final.fetchurl {
url = "mirror://cpan/authors/id/K/KR/KRYDE/Perl-Critic-Pulp-99.tar.gz";
sha256 = "b8fda842fcbed74d210257c0a284b6dc7b1d0554a47a3de5d97e7d542e23e7fe";
};
propagatedBuildInputs = with final.perlPackages; [ IOString ListMoreUtils PPI PerlCritic PodMinimumVersion ];
meta = {
homepage = "http://user42.tuxfamily.org/perl-critic-pulp/index.html";
description = "Some add-on policies for Perl::Critic";
license = final.lib.licenses.gpl3Plus;
};
};
PodMinimumVersion = prev.perlPackages.buildPerlPackage {
pname = "Pod-MinimumVersion";
version = "50";
src = final.fetchurl {
url = "mirror://cpan/authors/id/K/KR/KRYDE/Pod-MinimumVersion-50.tar.gz";
sha256 = "0bd2812d9aacbd99bb71fa103a4bb129e955c138ba7598734207dc9fb67b5a6f";
};
propagatedBuildInputs = with final.perlPackages; [ IOString PodParser ];
meta = {
homepage = "http://user42.tuxfamily.org/pod-minimumversion/index.html";
description = "Determine minimum Perl version of POD directives";
license = final.lib.licenses.free;
};
};
StringCompareConstantTime = final.buildPerlPackage { StringCompareConstantTime = final.buildPerlPackage {
pname = "String-Compare-ConstantTime"; pname = "String-Compare-ConstantTime";
version = "0.321"; version = "0.321";
@ -363,7 +423,7 @@
perlDeps = buildEnv { perlDeps = buildEnv {
name = "hydra-perl-deps"; name = "hydra-perl-deps";
paths = with perlPackages; lib.closePropagation paths = with perlPackages; lib.closePropagation
[ ModulePluggable [
AuthenSASL AuthenSASL
CatalystActionREST CatalystActionREST
CatalystAuthenticationStoreDBIxClass CatalystAuthenticationStoreDBIxClass
@ -382,20 +442,22 @@
CatalystViewDownload CatalystViewDownload
CatalystViewJSON CatalystViewJSON
CatalystViewTT CatalystViewTT
CatalystXScriptServerStarman
CatalystXRoleApplicator CatalystXRoleApplicator
CatalystXScriptServerStarman
CryptPassphrase CryptPassphrase
CryptPassphraseArgon2 CryptPassphraseArgon2
CryptRandPasswd CryptRandPasswd
DBDPg
DBDSQLite
DataDump DataDump
DateTime DateTime
DBDPg
DBDSQLite
DigestSHA1 DigestSHA1
EmailMIME EmailMIME
EmailSender EmailSender
FileSlurp FileSlurp
FileWhich FileWhich
final.nix.perl-bindings
git
IOCompress IOCompress
IPCRun IPCRun
JSON JSON
@ -403,27 +465,27 @@
JSONXS JSONXS
LWP LWP
LWPProtocolHttps LWPProtocolHttps
ModulePluggable
NetAmazonS3 NetAmazonS3
NetPrometheus NetPrometheus
NetStatsd NetStatsd
PadWalker PadWalker
PerlCriticCommunity
PrometheusTinyShared PrometheusTinyShared
Readonly Readonly
SQLSplitStatement
SetScalar SetScalar
SQLSplitStatement
Starman Starman
StringCompareConstantTime StringCompareConstantTime
SysHostnameLong SysHostnameLong
TermSizeAny TermSizeAny
Test2Harness
TestMore TestMore
TestPostgreSQL TestPostgreSQL
TextDiff TextDiff
Test2Harness
TextTable TextTable
XMLSimple XMLSimple
YAML YAML
final.nix.perl-bindings
git
]; ];
}; };

View file

@ -143,7 +143,7 @@ sub google_login :Path('/google-login') Args(0) {
error($c, "Logging in via Google is not enabled.") unless $c->config->{enable_google_login}; error($c, "Logging in via Google is not enabled.") unless $c->config->{enable_google_login};
my $ua = new LWP::UserAgent; my $ua = LWP::UserAgent->new();
my $response = $ua->post( my $response = $ua->post(
'https://www.googleapis.com/oauth2/v3/tokeninfo', 'https://www.googleapis.com/oauth2/v3/tokeninfo',
{ id_token => ($c->stash->{params}->{id_token} // die "No token."), { id_token => ($c->stash->{params}->{id_token} // die "No token."),
@ -171,7 +171,7 @@ sub github_login :Path('/github-login') Args(0) {
}; };
die "No github secret configured" unless $client_secret; die "No github secret configured" unless $client_secret;
my $ua = new LWP::UserAgent; my $ua = LWP::UserAgent->new();
my $response = $ua->post( my $response = $ua->post(
'https://github.com/login/oauth/access_token', 'https://github.com/login/oauth/access_token',
{ {

View file

@ -44,7 +44,7 @@ sub getHydraConfig {
my $conf = $ENV{"HYDRA_CONFIG"} || (Hydra::Model::DB::getHydraPath . "/hydra.conf"); my $conf = $ENV{"HYDRA_CONFIG"} || (Hydra::Model::DB::getHydraPath . "/hydra.conf");
my %opts = (%Hydra::Config::configGeneralOpts, -ConfigFile => $conf); my %opts = (%Hydra::Config::configGeneralOpts, -ConfigFile => $conf);
if (-f $conf) { if (-f $conf) {
my %h = new Config::General(%opts)->getall; my %h = Config::General->new(%opts)->getall;
$hydraConfig = \%h; $hydraConfig = \%h;
} else { } else {

View file

@ -11,7 +11,7 @@ sub process {
my @storePaths = @{$c->stash->{storePaths}}; my @storePaths = @{$c->stash->{storePaths}};
my $fh = new IO::Handle; my $fh = IO::Handle->new();
open $fh, "nix-store --export `nix-store -qR @storePaths` | gzip |"; open $fh, "nix-store --export `nix-store -qR @storePaths` | gzip |";

View file

@ -11,7 +11,7 @@ sub process {
$c->response->content_type('text/plain; charset=utf-8'); $c->response->content_type('text/plain; charset=utf-8');
my $fh = new IO::Handle; my $fh = IO::Handle->new();
my $tail = int($c->stash->{tail} // "0"); my $tail = int($c->stash->{tail} // "0");

View file

@ -13,7 +13,7 @@ sub process {
$c->response->content_type('application/x-nix-archive'); # !!! check MIME type $c->response->content_type('application/x-nix-archive'); # !!! check MIME type
my $fh = new IO::Handle; my $fh = IO::Handle->new();
open $fh, "nix-store --dump '$storePath' | pixz -0 $pParam |"; open $fh, "nix-store --dump '$storePath' | pixz -0 $pParam |";

View file

@ -23,6 +23,7 @@ EXTRA_DIST = \
$(TESTS) $(TESTS)
TESTS = \ TESTS = \
perlcritic.pl \
test.pl test.pl
check_SCRIPTS = repos check_SCRIPTS = repos

13
t/perlcritic.pl Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd 'abs_path';
use File::Basename;
my $dirname = abs_path(dirname(__FILE__) . "/..");
print STDERR "Executing perlcritic against $dirname\n";
chdir($dirname) or die "Failed to enter $dirname\n";
exec("perlcritic", ".") or die "Failed to execute perlcritic.";