Created
May 14, 2011 13:09
-
-
Save brutasse/972196 to your computer and use it in GitHub Desktop.
Github Djangoproject commits -> highlighted Atom feed with links to changesets, tickets and files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import feedgenerator | |
from github2.client import Github | |
REPO = 'django/django' | |
BRANCH = 'master' | |
HERE = os.path.abspath(os.path.dirname(__file__)) | |
TICKET_RE = re.compile(r'#(?P<id>\d+)') | |
CHANGESET_RE = re.compile(r'r(?P<id>\d+)') | |
def escape(html): | |
return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''') | |
def commits(num=5): | |
github = Github() | |
commits = github.commits.list(REPO, BRANCH) | |
feed = feedgenerator.Atom1Feed( | |
title='Django commits', | |
link='http://code.djangoproject.com/timeline', | |
feed_url='http://media.bruno.im/django.atom', | |
description='Django pretty commits. Updates every hour.', | |
language='en', | |
) | |
for commit in commits[:num]: | |
details = github.commits.show(REPO, sha=commit.id) | |
description = [] | |
title = details.message.split('\n')[0] | |
svn_id = details.message.split('\n')[-1].split()[1].split('@')[1] | |
author = commit.author['name'] | |
description.append('Author: %s' % author) | |
description.append('Date: %s' % commit.authored_date) | |
description.append('New revision: <a href="http://code.djangoproject.com/changeset/%s">%s</a>' % (svn_id, svn_id)) | |
description.append('') | |
if details.added: | |
description.append('Added:') | |
for added in details.added: | |
description.append(' * <a href="http://code.djangoproject.com/browser/django/trunk/%s">%s</a>' % (added, added)) | |
description.append('') | |
diffs = [] | |
if details.modified: | |
skip = False | |
if len(details.modified) > 30: | |
skip = True | |
description.append('Modified:') | |
for modified in details.modified: | |
description.append(' * <a href="http://code.djangoproject.com/browser/django/trunk/%s">%s</a>' % (modified['filename'], modified['filename'])) | |
if 'diff' in modified and not skip: | |
diffs.append('<pre>%s</pre>' % escape(modified['diff'])) | |
description.append('') | |
if details.removed: | |
description.append('Removed:') | |
for removed in details.removed: | |
description.append(' * %s' % removed) | |
description.append('') | |
message = details.message.split('git-svn-id:')[0] | |
message = TICKET_RE.sub('<a href="http://code.djangoproject.com/ticket/\g<1>">#\g<1></a>', message) | |
message = CHANGESET_RE.sub('<a href="http://code.djangoproject.com/changeset/\g<1>">r\g<1></a>', message) | |
description.append(message) | |
description.append('') | |
description.append('<br>\n'.join(diffs)) | |
feed.add_item( | |
title=details.message.split('\n')[0], | |
link='http://code.djangoproject.com/changeset/%s' % svn_id, | |
description='<br>\n'.join(description), | |
pubdate=details.committed_date, | |
) | |
fp = open(os.path.join(HERE, 'django.atom'), 'w') | |
feed.write(fp, 'utf-8') | |
fp.close() | |
if __name__ == '__main__': | |
commits(30) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
feedgenerator==1.2.1 | |
github2==0.3.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment