From 27da68c969dbe6036597e962c0ccfa5f9b15708b Mon Sep 17 00:00:00 2001 From: Manan Bedi <53931841+manan-bedi2908@users.noreply.github.com> Date: Wed, 8 Jul 2020 20:12:02 +0530 Subject: [PATCH 1/3] Added Assignment I have completed the assignment . But unfortunately, i am not able to close the issue through Github API https://github.com/manan-bedi2908/Workshop/issues/2 --- assignment./Github API.ipynb | 183 +++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 assignment./Github API.ipynb diff --git a/assignment./Github API.ipynb b/assignment./Github API.ipynb new file mode 100644 index 0000000..5705c35 --- /dev/null +++ b/assignment./Github API.ipynb @@ -0,0 +1,183 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Create An Issue using Github API" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Successfully created Issue Add README.MD\n" + ] + } + ], + "source": [ + "import os\n", + "import json\n", + "import requests\n", + "\n", + "# Authentication for user filing issue \n", + "USERNAME = 'manan-bedi2908'\n", + "PASSWORD = 'Yuvimanan@2908'\n", + "\n", + "# The repository to add this issue to\n", + "REPO_OWNER = 'manan-bedi2908'\n", + "REPO_NAME = 'Workshop'\n", + "\n", + "def make_github_issue(title, body=None, labels=None):\n", + "\n", + " url = 'https://api.github.com/repos/%s/%s/issues' % (REPO_OWNER, REPO_NAME)\n", + " # Authentication\n", + " session = requests.Session()\n", + " session.auth = (USERNAME, PASSWORD)\n", + " \n", + " # Create our issue\n", + " issue = {'title': title,\n", + " 'body': body,\n", + " 'labels': labels}\n", + " \n", + " # Add the issue to our repository\n", + " r = session.post(url, json.dumps(issue))\n", + " if r.status_code == 201:\n", + " print ('Successfully created Issue {0:s}'.format(title))\n", + " else:\n", + " print ('Could not create Issue {0:s}'.format(title))\n", + " print ('Response:', r.content)\n", + " \n", + "make_github_issue('Add README.MD', 'Add The file README.MD to explain about the project',['bug'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Comment on an Isuue using Github API" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "body = {\n", + " \"body\": \"Me too\"\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "#https://api.github.com/repos/octocat/Hello-World/issues/comments/1\n", + "ISSUE_NUMBER = 2\n", + "url2 = 'https://api.github.com/repos/%s/%s/issues/%d/comments' % (REPO_OWNER, REPO_NAME, ISSUE_NUMBER)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Successfully added comment\n" + ] + } + ], + "source": [ + "session = requests.Session()\n", + "session.auth = (USERNAME, PASSWORD)\n", + "r1 = session.post(url2, json.dumps(body))\n", + "if r1.status_code == 201:\n", + " print(\"Successfully added comment\")\n", + "else:\n", + " print ('Could not comment on Issue)\n", + " print ('Response:', r1.content)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Close The Issue using Github API" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Could not close the Issue\n", + "b''\n" + ] + } + ], + "source": [ + "close = {\n", + " \"locked\": True,\n", + " \"active_lock_reason\": \"too heated\"\n", + "}\n", + "url3 = 'https://api.github.com/repos/%s/%s/issues/%d/lock' % (REPO_OWNER, REPO_NAME, ISSUE_NUMBER)\n", + "r2 = session.put(url3, json.dumps(close))\n", + "if r2.status_code == 201:\n", + " print(\"Successfully Closed the issue\")\n", + "else:\n", + " print ('Could not close the Issue')\n", + " print(r2.content)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 518549d0c35b09e0ccce4594ed7cdac85e9decc0 Mon Sep 17 00:00:00 2001 From: Manan Bedi <53931841+manan-bedi2908@users.noreply.github.com> Date: Wed, 8 Jul 2020 20:14:21 +0530 Subject: [PATCH 2/3] Rename Github API.ipynb to Github API_Manan.ipynb --- assignment./{Github API.ipynb => Github API_Manan.ipynb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename assignment./{Github API.ipynb => Github API_Manan.ipynb} (100%) diff --git a/assignment./Github API.ipynb b/assignment./Github API_Manan.ipynb similarity index 100% rename from assignment./Github API.ipynb rename to assignment./Github API_Manan.ipynb From 3ac6b19fc0293ccb7d1ed9df7e5338efda9228e2 Mon Sep 17 00:00:00 2001 From: Manan Bedi <53931841+manan-bedi2908@users.noreply.github.com> Date: Wed, 8 Jul 2020 20:16:52 +0530 Subject: [PATCH 3/3] Create Manan_Bedi --- assignment./Manan_Bedi | 1 + 1 file changed, 1 insertion(+) create mode 100644 assignment./Manan_Bedi diff --git a/assignment./Manan_Bedi b/assignment./Manan_Bedi new file mode 100644 index 0000000..1872d32 --- /dev/null +++ b/assignment./Manan_Bedi @@ -0,0 +1 @@ +Url: https://github.com/manan-bedi2908/Workshop/issues/2