Skip to content

Instantly share code, notes, and snippets.

@meffie
Created October 12, 2018 14:39
Show Gist options
  • Save meffie/d77d56128f57164643d0effa2d73835a to your computer and use it in GitHub Desktop.
Save meffie/d77d56128f57164643d0effa2d73835a to your computer and use it in GitHub Desktop.
List open gerrits in descending order on wiki.openafs.org
#!/usr/bin/python3
#
# List the gerrits in descending order on wiki.openafs.org.
#
import os
import tempfile
import git_gerrit
from sh.contrib import git
from sh import ErrorReturnCode, ErrorReturnCode_1
WIKI_DIR = os.path.expanduser('~/src/openafs-wiki')
OPENAFS_DIR = os.path.expanduser('~/src/openafs');
def by_number(c):
return c['_number']
def info(msg):
print(msg)
def list_gerrits(fh, branch):
info('listing gerrits for branch ' + branch)
fh.write('<p>Changes for branch {branch}.</p>'.format(branch=branch))
fh.write('<table>\n')
fh.write('<tr><th>number</th><th>subject</th><th>topic</th></tr>\n')
terms = 'status:open branch:{branch}'.format(branch=branch)
for change in sorted(git_gerrit.query(terms, repodir=OPENAFS_DIR), key=by_number, reverse=True):
if change['topic'] == 'no-topic':
change['topic'] = ''
fh.write(
'<tr>'\
'<td><a href="https://gerrit.openafs.org/#/c/{_number}">{_number}</a></td>'\
'<td>{subject}</td>'\
'<td><a href="https://gerrit.openafs.org/#/q/'\
'status:open+project:openafs+branch:{branch}+topic:{topic}">{topic}</td>'\
'</tr>\n'\
.format(**change))
fh.write('</table>')
def update_page(filename, branches):
info('updating page '+filename)
with open(filename, 'w') as fh:
for branch in branches:
list_gerrits(fh, branch)
git.add(filename)
def main():
with tempfile.TemporaryDirectory() as tmpdir:
info('created tmp directory '+ tmpdir)
os.chdir(tmpdir)
git.clone(WIKI_DIR, 'openafs-wiki', _fg=True)
os.chdir('openafs-wiki')
git.remote('add', 'gerrit', 'ssh://gerrit.openafs.org/openafs-wiki.git')
git.fetch('gerrit', _fg=True)
git.reset('gerrit/master', '--hard', _fg=True)
update_page('devel/GerritsForStable.mdwn',
['openafs-stable-1_6_x', 'openafs-stable-1_8_x'])
update_page('devel/GerritsForMaster.mdwn', ['master'])
try:
git.commit('-m', 'update gerrit list', _fg=True)
except ErrorReturnCode_1:
print('no changes, skipping push')
except ErrorReturnCode:
print('something bad happened')
else:
git.push('gerrit', 'HEAD:refs/heads/master', _fg=True)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment