Skip to content

Instantly share code, notes, and snippets.

@dpursehouse
Created May 30, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpursehouse/66e1bd861efce4631ca1966b85ca0226 to your computer and use it in GitHub Desktop.
Save dpursehouse/66e1bd861efce4631ca1966b85ca0226 to your computer and use it in GitHub Desktop.
from pygerrit2 import GerritRestAPI, HTTPBasicAuthFromNetrc
url = "https://gerrit-review.googlesource.com"
auth = HTTPBasicAuthFromNetrc(url=url)
api = GerritRestAPI(url=url, auth=auth)
plugins = api.get("/projects/?p=plugins%2f&d")
branches = ["master"] + ["stable-%s" % v for v in ["3.0", "2.16", "2.15", "2.14"]]
def getRecentChangesCount(pluginName):
changes = api.get("/changes/?q=project:%s after:2018-11-01" % pluginName)
return len(changes)
def getBranches(pluginId):
branchList = api.get("/projects/%s/branches/" % pluginId)
pluginBranches = []
for b in branchList:
if b['ref'].startswith('refs/heads/'):
ref = b['ref']
pluginBranches += [ref[len('refs/heads/'):]]
return ",".join(["YES" if b in pluginBranches else "NO" for b in branches])
with open("plugins.csv", "w+") as output:
output.write("Name,State,Description,RecentChanges,%s\n" % ",".join(branches))
for p in plugins:
name = p[len("plugins/"):]
plugin = plugins[p]
state = plugin['state']
if plugin['state'] == 'ACTIVE':
changes = getRecentChangesCount(p)
availableBranches = getBranches(plugin['id'])
else:
changes = 0
availableBranches = ",".join(["N/A" for b in branches])
if 'description' in plugin:
description = plugin['description'].split('\n')[0].replace(',', ' ')
else:
description = 'NONE'
line = "%s,%s,%s,%d,%s\n" % (name, state, description, changes, availableBranches)
output.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment