Last active
January 30, 2016 05:35
-
-
Save singlerider/0d765b8679206ea5da51 to your computer and use it in GitHub Desktop.
Submit A Github Issue using API V3 and Python's requests lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests # pip install requests | |
def report(args): | |
username = "github username" | |
bot_repo = "bot repository name (on username's account)" | |
github_token = "github token obtained from https://github.com/settings/tokens with scopes" | |
reporter = "user reporting issue" | |
channel = "#channel name" | |
description = unicode(args[0]) # python 2.7-safe user input | |
with requests.Session() as session: | |
session.auth = (username, github_token) | |
url = ( | |
"https://api.github.com/repos/" + username + "/" + bot_repo + | |
"/issues") | |
headers = { | |
"Content-Type": "application/json", | |
"Authorization": "token " + github_token, | |
} | |
params = { | |
"title": channel + ": " + reporter, | |
"assignee": username, | |
"body": reporter + " reports \"" + description + "\" in " + channel | |
} | |
resp = session.post(url=url, json=params, headers=headers) | |
data = json.loads(resp.content) | |
issue_number = data["number"] | |
issue_url = data["html_url"] | |
message = ( | |
"Issue #" + str(issue_number) + " created and is visible at " + | |
issue_url) | |
return message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment