File size: 5,681 Bytes
3a5685e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d601226
 
3a5685e
d601226
3a5685e
d601226
3a5685e
 
 
 
d601226
 
3a5685e
 
 
d601226
3a5685e
 
 
 
d601226
3a5685e
 
 
 
d601226
3a5685e
 
 
 
d601226
3a5685e
 
 
 
 
 
 
 
 
d601226
3a5685e
 
 
 
d601226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a5685e
 
 
 
 
 
 
d601226
3a5685e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d601226
 
 
3a5685e
 
 
 
d601226
3a5685e
 
 
 
d601226
 
 
 
 
 
3a5685e
 
 
 
d601226
 
3a5685e
 
 
 
 
d601226
3a5685e
 
d601226
3a5685e
 
 
 
 
d601226
3a5685e
 
 
 
d601226
 
3a5685e
 
 
d601226
 
 
3a5685e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
{
 "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
}