Skip to content

Commit

Permalink
feat: github get comments and reactions from issue
Browse files Browse the repository at this point in the history
  • Loading branch information
varshakumarr committed Jun 6, 2024
1 parent 20a2713 commit c0e933a
Show file tree
Hide file tree
Showing 3 changed files with 321 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"tags": []
},
"source": [
"# GitHub - Get comments and reactions from Issue\n",
"# GitHub - Get comments and reactions from issue\n",
"<a href=\"https://bit.ly/3JyWIk6\">Give Feedback</a> | <a href=\"https://github.com/jupyter-naas/awesome-notebooks/issues/new?assignees=&labels=bug&template=bug_report.md&title=GitHub+-+Add+new+issues+as+page+in+Notion+database:+Error+short+description\">Bug report</a>"
]
},
Expand Down Expand Up @@ -80,28 +80,17 @@
"## Input"
]
},
{
"cell_type": "markdown",
"id": "b483a140",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 22,
"id": "353ef79c",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-05T12:26:01.851334Z",
"iopub.status.busy": "2024-06-05T12:26:01.851046Z",
"iopub.status.idle": "2024-06-05T12:26:02.759162Z",
"shell.execute_reply": "2024-06-05T12:26:02.758418Z",
"shell.execute_reply.started": "2024-06-05T12:26:01.851256Z"
"iopub.execute_input": "2024-06-06T12:46:32.840909Z",
"iopub.status.busy": "2024-06-06T12:46:32.840683Z",
"iopub.status.idle": "2024-06-06T12:46:32.843884Z",
"shell.execute_reply": "2024-06-06T12:46:32.843118Z",
"shell.execute_reply.started": "2024-06-06T12:46:32.840886Z"
},
"papermill": {},
"tags": []
Expand All @@ -110,7 +99,8 @@
"source": [
"import requests\n",
"import re\n",
"import pandas as pd"
"import pandas as pd\n",
"import naas_python as naas"
]
},
{
Expand All @@ -121,29 +111,29 @@
"tags": []
},
"source": [
"### Setup Variables\n",
"### Setup variables\n",
"- `github_token`: personal token creates\n",
"- `issue_url`: link to the chosen issue"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 23,
"id": "01647a55",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-05T12:26:02.800457Z",
"iopub.status.busy": "2024-06-05T12:26:02.800186Z",
"iopub.status.idle": "2024-06-05T12:26:02.804857Z",
"shell.execute_reply": "2024-06-05T12:26:02.804318Z",
"shell.execute_reply.started": "2024-06-05T12:26:02.800432Z"
"iopub.execute_input": "2024-06-06T12:46:33.132172Z",
"iopub.status.busy": "2024-06-06T12:46:33.131874Z",
"iopub.status.idle": "2024-06-06T12:46:34.326369Z",
"shell.execute_reply": "2024-06-06T12:46:34.325734Z",
"shell.execute_reply.started": "2024-06-06T12:46:33.132140Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"github_token = \"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\"\n",
"github_token = naas.secret.get(\"GITHUB_TOKEN\").value\n",
"issue_url = \"https://github.com/pola-rs/polars/issues/16661\""
]
},
Expand All @@ -155,20 +145,21 @@
"tags": []
},
"source": [
"## Model\n"
"## Model\n",
"### Get comments and reactions from issue"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 24,
"id": "29e87112-879c-439c-87b3-3065f9a91085",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-05T12:26:05.445237Z",
"iopub.status.busy": "2024-06-05T12:26:05.444998Z",
"iopub.status.idle": "2024-06-05T12:26:05.452150Z",
"shell.execute_reply": "2024-06-05T12:26:05.451507Z",
"shell.execute_reply.started": "2024-06-05T12:26:05.445212Z"
"iopub.execute_input": "2024-06-06T12:46:34.327546Z",
"iopub.status.busy": "2024-06-06T12:46:34.327369Z",
"iopub.status.idle": "2024-06-06T12:46:34.335484Z",
"shell.execute_reply": "2024-06-06T12:46:34.334966Z",
"shell.execute_reply.started": "2024-06-06T12:46:34.327526Z"
},
"tags": []
},
Expand Down Expand Up @@ -221,20 +212,21 @@
"tags": []
},
"source": [
"## Output\n"
"## Output\n",
"### Display result"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 25,
"id": "947ce69b-f636-4ac4-abd9-4254fca3f897",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-05T12:29:18.324360Z",
"iopub.status.busy": "2024-06-05T12:29:18.324086Z",
"iopub.status.idle": "2024-06-05T12:29:18.786161Z",
"shell.execute_reply": "2024-06-05T12:29:18.785121Z",
"shell.execute_reply.started": "2024-06-05T12:29:18.324334Z"
"iopub.execute_input": "2024-06-06T12:46:34.337044Z",
"iopub.status.busy": "2024-06-06T12:46:34.336812Z",
"iopub.status.idle": "2024-06-06T12:46:34.904718Z",
"shell.execute_reply": "2024-06-06T12:46:34.904094Z",
"shell.execute_reply.started": "2024-06-06T12:46:34.337017Z"
},
"tags": []
},
Expand All @@ -260,41 +252,72 @@
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>COMMENT_ID</th>\n",
" <th>OBJECT_URL</th>\n",
" <th>ID</th>\n",
" <th>TYPE</th>\n",
" <th>CONTENT</th>\n",
" <th>DATE/TIME</th>\n",
" <th>CREATOR NAME</th>\n",
" <th>CREATOR LOGIN</th>\n",
" <th>DATE_TIME</th>\n",
" <th>USER_NAME</th>\n",
" <th>USER_LOGIN</th>\n",
" <th>USER_ID</th>\n",
" <th>REACTIONS COUNT</th>\n",
" <th>REACTION TYPE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>https://api.github.com/repos/pola-rs/polars/is...</td>\n",
" <td>2144455441</td>\n",
" <td>COMMENT</td>\n",
" <td>We can support both. Coming up.</td>\n",
" <td>2024-06-03T07:20:29Z</td>\n",
" <td>N/A</td>\n",
" <td>ritchie46</td>\n",
" <td>3023000</td>\n",
" <td>2</td>\n",
" <td>{'hooray': 1, '+1': 1}</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>https://api.github.com/repos/pola-rs/polars/is...</td>\n",
" <td>2144455441</td>\n",
" <td>REACTION</td>\n",
" <td>hooray</td>\n",
" <td>2024-06-03T07:25:35Z</td>\n",
" <td>N/A</td>\n",
" <td>alexander-beedie</td>\n",
" <td>2613171</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>https://api.github.com/repos/pola-rs/polars/is...</td>\n",
" <td>2144455441</td>\n",
" <td>REACTION</td>\n",
" <td>+1</td>\n",
" <td>2024-06-03T10:26:28Z</td>\n",
" <td>N/A</td>\n",
" <td>cmdlineluser</td>\n",
" <td>99486669</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" COMMENT_ID CONTENT DATE/TIME \\\n",
"0 2144455441 We can support both. Coming up. 2024-06-03T07:20:29Z \n",
" OBJECT_URL ID TYPE \\\n",
"0 https://api.github.com/repos/pola-rs/polars/is... 2144455441 COMMENT \n",
"1 https://api.github.com/repos/pola-rs/polars/is... 2144455441 REACTION \n",
"2 https://api.github.com/repos/pola-rs/polars/is... 2144455441 REACTION \n",
"\n",
" CONTENT DATE_TIME USER_NAME \\\n",
"0 We can support both. Coming up. 2024-06-03T07:20:29Z N/A \n",
"1 hooray 2024-06-03T07:25:35Z N/A \n",
"2 +1 2024-06-03T10:26:28Z N/A \n",
"\n",
" CREATOR NAME CREATOR LOGIN USER_ID REACTIONS COUNT REACTION TYPE \n",
"0 N/A ritchie46 3023000 2 {'hooray': 1, '+1': 1} "
" USER_LOGIN USER_ID \n",
"0 ritchie46 3023000 \n",
"1 alexander-beedie 2613171 \n",
"2 cmdlineluser 99486669 "
]
},
"execution_count": 9,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -307,32 +330,45 @@
" comments = get_issue_comments(repo_owner, repo_name, issue_number)\n",
"\n",
" for comment in comments:\n",
" object_url = comment['issue_url']\n",
" comment_id = comment['id']\n",
" comment_body = comment['body']\n",
" comment_created_at = comment['created_at']\n",
" user_id = comment['user']['id']\n",
" comment_user_name = comment['user']['name'] if 'name' in comment['user'] else 'N/A'\n",
" comment_user_login = comment['user']['login']\n",
" comment_user_id = comment['user']['id']\n",
" \n",
" data = [{\n",
" \"OBJECT_URL\": object_url,\n",
" \"ID\": comment_id,\n",
" \"TYPE\": \"COMMENT\",\n",
" \"CONTENT\": comment_body,\n",
" \"DATE_TIME\": comment_created_at,\n",
" \"USER_NAME\": comment_user_name,\n",
" \"USER_LOGIN\": comment_user_login,\n",
" \"USER_ID\": comment_user_id,\n",
" }]\n",
" \n",
" reactions = get_comment_reactions(repo_owner, repo_name, comment_id)\n",
" reaction_count = len(reactions)\n",
" reaction_types = {}\n",
" for reaction in reactions:\n",
" reaction_content = reaction['content']\n",
" if reaction_content in reaction_types:\n",
" reaction_types[reaction_content] += 1\n",
" else:\n",
" reaction_types[reaction_content] = 1\n",
"\n",
" data.append({\n",
" \"COMMENT_ID\": comment_id,\n",
" \"CONTENT\": comment_body,\n",
" \"DATE/TIME\": comment_created_at,\n",
" \"CREATOR NAME\": comment_user_name,\n",
" \"CREATOR LOGIN\": comment_user_login,\n",
" \"USER_ID\": user_id,\n",
" \"REACTIONS COUNT\": reaction_count,\n",
" \"REACTION TYPE\": reaction_types\n",
" })\n",
" reaction_id = reaction['id']\n",
" reaction_body = reaction['content']\n",
" reaction_created_at = reaction['created_at']\n",
" reaction_user_name = reaction['user']['name'] if 'name' in comment['user'] else 'N/A'\n",
" reaction_user_login = reaction['user']['login']\n",
" reaction_user_id = reaction['user']['id']\n",
" \n",
" data.append({\n",
" \"OBJECT_URL\": object_url,\n",
" \"ID\": comment_id,\n",
" \"TYPE\": \"REACTION\",\n",
" \"CONTENT\": reaction_body,\n",
" \"DATE_TIME\": reaction_created_at,\n",
" \"USER_NAME\": reaction_user_name,\n",
" \"USER_LOGIN\": reaction_user_login,\n",
" \"USER_ID\": reaction_user_id,\n",
" })\n",
" \n",
" \n",
"\n",
"except ValueError as e:\n",
Expand All @@ -341,6 +377,14 @@
"df = pd.DataFrame(data)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5326f466-a95b-467a-8b8e-30235d6e5a78",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit c0e933a

Please sign in to comment.