post-update.reuse (1315B)
- #!/usr/bin/env perl
- # reuse lint appropriate for git-hook (short summary, no output on success)
- # SPDX-FileCopyrightText: 2025 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: BSD-3-Clause
- use JSON;
- use Cwd;
- use builtin qw(reftype);
- use strict;
- my $base = getcwd;
- if ($base =~ /\.git$/) {
- $base =~ s/\.git$/\.work/;
- chdir $base or die "chdir failed: $!";
- }
- open(FH, '-|', 'reuse lint -j') or die "Failed to execute reuse: $!";
- undef $/; # slurp
- my $reuse_json = decode_json(<FH>);
- # ignore reuse exit status
- if (not close(FH) and $!) {
- die "Error closing reuse pipe: $!"
- }
- if ($reuse_json->{"summary"}->{"compliant"} != JSON::true) {
- my $obj = $reuse_json->{"non_compliant"};
- foreach my $key (keys %{$obj}) {
- my $v = $obj->{$key};
- my $ref_type = reftype($v);
- if ($ref_type eq 'ARRAY') {
- my $n = scalar @{$v};
- if($n == 1) {
- print "reuse: ", $key, ": [\"" , $v->[0], "\"]\n";
- } elsif ($n > 1) {
- print "reuse: ", $key, ": @ " , $n, "\n";
- }
- } elsif ($ref_type eq 'HASH') {
- my @k = keys %{$v};
- my $n = scalar @k;
- if($n == 1) {
- print "reuse: ", $key, ": {\"" , $k[0], "\": …}\n";
- } elsif ($n > 1) {
- print "reuse: ", $key, ": % " , $n, "\n";
- }
- } else {
- print "reuse: ", $key, ": [", $ref_type ,"] " , $v, "\n";
- }
- }
- }