@@ -0,0 +1,89 @@
1+#!/usr/bin/env nix-shell
2+#!nix-shell -i python -p pythonFull pythonPackages.requests pythonPackages.pyquery pythonPackages.click
3+
4+# To use, just execute this script with --help to display help.
5+
6+import subprocess
7+import json
8+
9+import click
10+import requests
11+from pyquery import PyQuery as pq
12+
13+
14+maintainers_json = subprocess.check_output([
15+ 'nix-instantiate',
16+ 'lib/maintainers.nix',
17+ '--eval',
18+ '--json'])
19+maintainers = json.loads(maintainers_json)
20+MAINTAINERS = {v: k for k, v in maintainers.iteritems()}
21+
22+
23+def get_response_text(url):
24+ return pq(requests.get(url).text) # IO
25+
26+EVAL_FILE = {
27+ 'nixos': 'nixos/release.nix',
28+ 'nixpkgs': 'pkgs/top-level/release.nix',
29+}
30+
31+
32+def get_maintainers(attr_name):
33+ nixname = attr_name.split('.')
34+ meta_json = subprocess.check_output([
35+ 'nix-instantiate',
36+ '--eval',
37+ '--strict',
38+ '-A',
39+ '.'.join(nixname[1:]) + '.meta',
40+ EVAL_FILE[nixname[0]],
41+ '--json'])
42+ meta = json.loads(meta_json)
43+ if meta.get('maintainers'):
44+ return [MAINTAINERS[name] for name in meta['maintainers'] if MAINTAINERS.get(name)]
45+
46+
47+@click.command()
48+@click.option(
49+ '--jobset',
50+ default="nixos/release-16.09",
51+ help='Hydra project like nixos/release-16.09')
52+def cli(jobset):
53+ """
54+ Given a Hydra project, inspect latest evaluation
55+ and print a summary of failed builds
56+ """
57+
58+ url = "http://hydra.nixos.org/jobset/{}".format(jobset)
59+
60+ # get the last evaluation
61+ click.echo(click.style(
62+ 'Getting latest evaluation for {}'.format(url), fg='green'))
63+ d = get_response_text(url)
64+ evaluations = d('#tabs-evaluations').find('a[class="row-link"]')
65+ latest_eval_url = evaluations[0].get('href')
66+
67+ # parse last evaluation page
68+ click.echo(click.style(
69+ 'Parsing evaluation {}'.format(latest_eval_url), fg='green'))
70+ d = get_response_text(latest_eval_url + '?full=1')
71+
72+ # TODO: aborted evaluations
73+ # TODO: dependency failed without propagated builds
74+ for tr in d('img[alt="Failed"]').parents('tr'):
75+ a = pq(tr)('a')[1]
76+ print "- [ ] [{}]({})".format(a.text, a.get('href'))
77+
78+ maintainers = get_maintainers(a.text)
79+ if maintainers:
80+ print " - maintainers: {}".format(", ".join(map(lambda u: '@' + u, maintainers)))
81+ # TODO: print last three persons that touched this file
82+ # TODO: pinpoint the diff that broke this build, or maybe it's transient or maybe it never worked?
83+
84+
85+if __name__ == "__main__":
86+ try:
87+ cli()
88+ except:
89+ import pdb;pdb.post_mortem()