Quick cpanterster report processing with jt

作者:   發佈於:  

It has been a while since JSON became the popular format for web service, the beloved cpantester also provide report summary per-distribution like this (taking App-perlbrew for example):

http://www.cpantesters.org/distro/A/App-perlbrew.json

This produced a minified JSON, which is not optimized for reading, the recently released App-jt, it's easy to prettify any JSON:

curl http://www.cpantesters.org/distro/A/App-perlbrew.json | jt

The prettified content looked like this:

[
    {
        "ostext" : "IRIX",
        "status" : "FAIL",
        "osvers" : "6.5",
        "state" : "fail",
        "osname" : "irix",
        "guid" : "851aa3be-af72-11df-aa76-d8fe8adbd73a",
        "id" : "8327044",
        "platform" : "IP35-irix-64int",
        "version" : "0.10",
        "dist" : "App-perlbrew",
        "csspatch" : "unp",
        "distribution" : "App-perlbrew",
        "perl" : "5.8.8",
        "distversion" : "App-perlbrew-0.10",
        "cssperl" : "rel",
        "fulldate" : "201008241127"
    },
    {
        ...
    }
]

Generally I care more about FAIL reports and their details more, filtering can be easily done with --grep option:

... | jt --grep '$_{status} eq "FAIL"

Or to be more specific, only care about specific version

... | jt --grep '$_{status} eq "FAIL" && $_{version} eq "0.59"'

Sometimes tsv/csv is better for doing ad-hoc processing with all those friendly unix commands

... | jt --fields guid,perl,platform,ostext,osvers --tsv

The result is a page of tab-seperated rows

guid    perl	platform	ostext	osvers
1e3119c0-8d97-11e2-97cb-820323e4fb11    5.14.4	x86_64-linux-thread-multi	GNU/Linux	2.6.28-19-generic
e26959dc-8c12-11e2-afb5-3c9c96fda259    5.14.3	darwin-2level	"Mac OS X"	12.2.1
e8d1bd00-8c03-11e2-a637-037c84b8c917    5.17.10	x86_64-linux-thread-multi-ld	GNU/Linux	3.2.0-4-amd64
f781ab1c-8bf4-11e2-8fe2-9c3397fda259    5.12.5	darwin-2level	"Mac OS X"	12.2.1
4187cfa6-8a66-11e2-bad2-eca396fda259    5.14.4	darwin-2level	"Mac OS X"	12.2.1
1a995e90-89a4-11e2-a7ac-bc45f1f528ea    5.12.4	amd64-freebsd	FreeBSD	9.1-release
430501cd-7076-1014-a8b0-11a3b77d427c    5.14.2	MSWin32-x86-multi-thread	"Windows (Win32)"	4.0
d2a8fa68-87f6-11e2-a4ba-7c4497fda259    5.16.2	darwin-2level	"Mac OS X"	12.2.1
13dc3174-88df-11e2-a7ac-bc45f1f528ea    5.12.3	amd64-freebsd-thread-multi	FreeBSD	9.1-release

And can be easily piped to cut -f1 or sort -k2 etc. With parallel, the URLs to each individual report can be easily constructed or just curl-ed:

... | jt --fields guid,perl,platform,ostext,osvers --tsv | cut -f1 | parallel 'echo http://www.cpantesters.org/cpan/report/{}'

jt also supports JSONPath to pick any fields from it's input. It is still rather young but already deal with many major hassles for my daily routine work. Feel free to fork the App-jt project on github and send me a pull request for the features you want!