Skip to content

Instantly share code, notes, and snippets.

@singlerider
Last active January 30, 2016 05:35
Show Gist options
  • Save singlerider/0d765b8679206ea5da51 to your computer and use it in GitHub Desktop.
Save singlerider/0d765b8679206ea5da51 to your computer and use it in GitHub Desktop.
Submit A Github Issue using API V3 and Python's requests lib
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