From 2468ee28c7656677ce40552dd05124b5995e3667 Mon Sep 17 00:00:00 2001 From: "W. Matthew Wilson" Date: Sat, 4 Jun 2011 13:39:27 -0400 Subject: Started work... --- .gitignore | 2 + README | 10 ++++ pygithubissues/__init__.py | 123 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 .gitignore create mode 100644 README create mode 100644 pygithubissues/__init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d18402d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +.*.swp diff --git a/README b/README new file mode 100644 index 0000000..e3bace0 --- /dev/null +++ b/README @@ -0,0 +1,10 @@ +I want to interact with github issues using python. + +I'm following these docs: http://developer.github.com/v3/issues/ + +This code uses subprocess and curl. It doesn't create a shell though, +so security risks are limited. + +I welcome patches that replace using curl at the command-line with +something that either uses the pycurl, or something from the standard +library, or something like the requests or httplib2 libraries. diff --git a/pygithubissues/__init__.py b/pygithubissues/__init__.py new file mode 100644 index 0000000..fd8bf94 --- /dev/null +++ b/pygithubissues/__init__.py @@ -0,0 +1,123 @@ +# vim: set expandtab ts=4 sw=4 filetype=python: + +""" +This will likely be rewritten into something with classes. +""" + +import json +import logging +import subprocess + +def setup_logging(): + + log = logging.getLogger('pygithubissues') + h = logging.StreamHandler() + f = logging.Formatter("%(levelname)s %(asctime)s %(message)s") + h.setFormatter(f) + log.addHandler(h) + + return log + +log = setup_logging() + + +def list_issues_for_repo(username, password, repo_owner, repo): + + """ + Does this:: + + curl -u "username:password" \\ + https://api.github.com/repos/repo_owner/repo/issues + + """ + + auth_option = '%s:%s' % (username, password) + + url = ('https://api.github.com/repos/%s/%s/issues' + % (repo_owner, repo)) + + args = ['curl', '-u', auth_option, url] + + p = subprocess.Popen(args, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + results = p.communicate() + + return json.loads(results[0]) + +def get_a_single_issue(username, password, repo_owner, repo, issue_id): + + """ + Does this:: + + curl -u "username:password" \\ + https://api.github.com/repos/:repo_owner/:repo/issues/:issue_id + + """ + + auth_option = '%s:%s' % (username, password) + + url = ('https://api.github.com/repos/%s/%s/issues/%s' + % (repo_owner, repo, issue_id)) + + args = ['curl', '-u', auth_option, url] + + p = subprocess.Popen(args, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + results = p.communicate() + + return json.loads(results[0]) + + + +def list_milestones_for_repo(username, password, repo_owner, repo): + + """ + Does this:: + + curl -u "{username}:{password}" \\ + https://api.github.com/repos/{repo_owner}/{repo}/milestones + + """ + + auth_option = '%s:%s' % (username, password) + + url = ('https://api.github.com/repos/%s/%s/milestones' + % (repo_owner, repo)) + + args = ['curl', '-u', auth_option, url] + + p = subprocess.Popen(args, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + results = p.communicate() + + return json.loads(results[0]) + + +def list_issues_in_milestone(username, password, repo_owner, repo, + milestone_number): + + """ + Does this:: + + curl -u "username:password" \\ + https://api.github.com/repos/repo_owner/repo/issues \\ + ?milestone={milestone_number} + + """ + + auth_option = '%s:%s' % (username, password) + + url = ('https://api.github.com/repos/%s/%s/issues?milestone=%s' + % (repo_owner, repo, milestone_number)) + + args = ['curl', '-u', auth_option, url] + + p = subprocess.Popen(args, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + results = p.communicate() + + return json.loads(results[0]) -- cgit v1.2.3