{ "cells": [ { "cell_type": "code", "execution_count": 33, "id": "0b6e3da3-d921-4445-927c-b8a66b3a2428", "metadata": {}, "outputs": [], "source": [ "from github import Github\n", "import requests" ] }, { "cell_type": "code", "execution_count": 39, "id": "1b5b14e4-3b9d-41c0-9df6-4f63d76e05da", "metadata": {}, "outputs": [], "source": [ "def get_diff(url):\n", " return requests.get(url).content.decode()" ] }, { "cell_type": "code", "execution_count": 120, "id": "ebe058f9-f62d-4978-890a-3e8200999779", "metadata": {}, "outputs": [], "source": [ "tok = \"MYGITHUBTOKEN\"" ] }, { "cell_type": "code", "execution_count": 157, "id": "19d37444-e62e-4e31-bce8-6cd1ee63e133", "metadata": {}, "outputs": [], "source": [ "from tqdm.notebook import tqdm" ] }, { "cell_type": "code", "execution_count": 155, "id": "fd25eafa-fb29-4051-ae0a-f71a0dbc92db", "metadata": {}, "outputs": [], "source": [ "gh = Github(\"MYGITNAME\", tok)" ] }, { "cell_type": "code", "execution_count": 160, "id": "f3b9c5f6-31a0-49b2-834b-982952c6b7e5", "metadata": {}, "outputs": [], "source": [ "data = {}" ] }, { "cell_type": "code", "execution_count": 162, "id": "c60588b7-56de-457f-93a6-3e8b3b8965c8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 out of 17\n", "Data length: 29\n", "1 out of 17\n", "Data length: 53\n", "2 out of 17\n", "Data length: 79\n", "3 out of 17\n", "Data length: 107\n", "4 out of 17\n", "Data length: 134\n", "5 out of 17\n", "Data length: 159\n", "6 out of 17\n", "Data length: 187\n", "7 out of 17\n", "Data length: 211\n", "8 out of 17\n", "Data length: 239\n", "9 out of 17\n", "Data length: 266\n", "10 out of 17\n", "Data length: 295\n", "11 out of 17\n", "Data length: 323\n", "12 out of 17\n", "Data length: 353\n", "13 out of 17\n", "Data length: 380\n", "14 out of 17\n", "Data length: 409\n", "15 out of 17\n", "Data length: 439\n", "16 out of 17\n", "Data length: 454\n" ] } ], "source": [ "repo = gh.get_repo(\"huggingface/accelerate\")\n", "pulls = repo.get_pulls(state=\"closed\")\n", "total_pages = (pulls.totalCount // 30) + 1\n", "total = pulls.totalCount\n", "for page_id in range(total_pages):\n", " page = pulls.get_page(page_id)\n", " for pull in page:\n", " pull_id = pull.id\n", " pull_diff = get_diff(pull.diff_url)\n", " pull_user = pull.user.login\n", " if pull.is_merged():\n", " code_comments = []\n", " conversation = []\n", " # Code comments\n", " for comment in pull.get_comments():\n", " code_comments.append(\n", " {\n", " \"body\":comment.body,\n", " \"diff_hunk\":comment.diff_hunk,\n", " \"from_author\": comment.user.login == pull_user\n", " }\n", " )\n", " for comment in pull.get_issue_comments():\n", " conversation.append(\n", " dict(\n", " body=comment.body,\n", " from_author=comment.user.login == pull_user\n", " )\n", " )\n", " data[pull_id] = {\n", " \"diff\":pull_diff, \n", " \"code_comments\":code_comments, \n", " \"context\":conversation,\n", " \"url\":pull.url\n", " } \n", " print(f\"{page_id} out of {total_pages}\")\n", " print(f'Data length: {len(data)}')" ] }, { "cell_type": "code", "execution_count": 164, "id": "16140ee6-88e7-4cdf-b215-2282f1034dcf", "metadata": {}, "outputs": [], "source": [ "new_code = []\n", "for item in list(data.keys()):\n", " d = data[item]\n", " d[\"pr_id\"] = item\n", " if len(d[\"code_comments\"]) > 1:\n", " new_code.append(d)" ] }, { "cell_type": "code", "execution_count": 174, "id": "1149e33e-75bf-4b0b-a94c-fe5ee2a291bc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "134" ] }, "execution_count": 174, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(new_code)" ] }, { "cell_type": "code", "execution_count": 175, "id": "7763a1aa-727c-41c9-b348-a4adaaca8445", "metadata": {}, "outputs": [], "source": [ "import json\n", "with open(\"data.json\", \"w+\") as f:\n", " json.dump(new_code, f)" ] }, { "cell_type": "code", "execution_count": null, "id": "71e93f8e-35a3-4a8c-a706-4dc88d38f3fc", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }