Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions assignment./Github API_Manan.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions assignment./Manan_Bedi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Url: https://github.com/manan-bedi2908/Workshop/issues/2