Skip to content

Instantly share code, notes, and snippets.

@ngoldbaum
Created December 1, 2014 00:01
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 ngoldbaum/e5da963e1ae1cbef974f to your computer and use it in GitHub Desktop.
Save ngoldbaum/e5da963e1ae1cbef974f to your computer and use it in GitHub Desktop.
{
"metadata": {
"kernelspec": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"display_name": "IPython (Python 2)",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:9970a53f1b796d456876b61c849d58a61306481ae6c2c206f6c47c3903e2dc35"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook uses the bitbucket API to count the number of merged pull requests I've authored in the `yt` codebase."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import requests\n",
"from collections import defaultdict\n",
"\n",
"numprs = defaultdict(int)\n",
"\n",
"# Template for the 0th paginated url.\n",
"url0 =\"http://bitbucket.org/api/2.0/repositories/yt_analysis/{}/pullrequests/?state=merged\"\n",
"\n",
"repositories = [\n",
" 'yt', # The main yt development repository \n",
" 'yt-doc', # The old repository for the yt documentation \n",
" 'yt-3.0', # The repository used for development of yt 3.0\n",
"]\n",
"\n",
"for repository in repositories:\n",
" url = url0.format(repository)\n",
" while True:\n",
" r = requests.get(url)\n",
" if r.status_code != 200:\n",
" raise RuntimeError\n",
" data = r.json()\n",
" values = data['values']\n",
" for value in values:\n",
" if value['author']['username'] == 'ngoldbaum':\n",
" numprs[repository] += 1\n",
" if 'next' in data.keys():\n",
" url = data['next']\n",
" else:\n",
" break\n",
" print(\"Merged {} pull requests in the {} repository\".format(numprs[repository], repository))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Merged 285 pull requests in the yt repository\n",
"Merged 31 pull requests in the yt-doc repository\n",
"Merged 15 pull requests in the yt-3.0 repository\n"
]
}
],
"prompt_number": 1
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment