aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorW. Matthew Wilson <matt@tplus1.com>2011-06-04 13:39:27 -0400
committerW. Matthew Wilson <matt@tplus1.com>2011-06-04 13:39:27 -0400
commit2468ee28c7656677ce40552dd05124b5995e3667 (patch)
tree9a53113294993659142c754a437ed89efc8ae5ec
downloadpygithubissues-2468ee28c7656677ce40552dd05124b5995e3667.tar.bz2
pygithubissues-2468ee28c7656677ce40552dd05124b5995e3667.tar.xz
pygithubissues-2468ee28c7656677ce40552dd05124b5995e3667.zip
Started work...
-rw-r--r--.gitignore2
-rw-r--r--README10
-rw-r--r--pygithubissues/__init__.py123
3 files changed, 135 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d18402d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
1*.pyc
2.*.swp
diff --git a/README b/README
new file mode 100644
index 0000000..e3bace0
--- /dev/null
+++ b/README
@@ -0,0 +1,10 @@
1I want to interact with github issues using python.
2
3I'm following these docs: http://developer.github.com/v3/issues/
4
5This code uses subprocess and curl. It doesn't create a shell though,
6so security risks are limited.
7
8I welcome patches that replace using curl at the command-line with
9something that either uses the pycurl, or something from the standard
10library, 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 @@
1# vim: set expandtab ts=4 sw=4 filetype=python:
2
3"""
4This will likely be rewritten into something with classes.
5"""
6
7import json
8import logging
9import subprocess
10
11def setup_logging():
12
13 log = logging.getLogger('pygithubissues')
14 h = logging.StreamHandler()
15 f = logging.Formatter("%(levelname)s %(asctime)s %(message)s")
16 h.setFormatter(f)
17 log.addHandler(h)
18
19 return log
20
21log = setup_logging()
22
23
24def list_issues_for_repo(username, password, repo_owner, repo):
25
26 """
27 Does this::
28
29 curl -u "username:password" \\
30 https://api.github.com/repos/repo_owner/repo/issues
31
32 """
33
34 auth_option = '%s:%s' % (username, password)
35
36 url = ('https://api.github.com/repos/%s/%s/issues'
37 % (repo_owner, repo))
38
39 args = ['curl', '-u', auth_option, url]
40
41 p = subprocess.Popen(args, stdout=subprocess.PIPE,
42 stderr=subprocess.PIPE)
43
44 results = p.communicate()
45
46 return json.loads(results[0])
47
48def get_a_single_issue(username, password, repo_owner, repo, issue_id):
49
50 """
51 Does this::
52
53 curl -u "username:password" \\
54 https://api.github.com/repos/:repo_owner/:repo/issues/:issue_id
55
56 """
57
58 auth_option = '%s:%s' % (username, password)
59
60 url = ('https://api.github.com/repos/%s/%s/issues/%s'
61 % (repo_owner, repo, issue_id))
62
63 args = ['curl', '-u', auth_option, url]
64
65 p = subprocess.Popen(args, stdout=subprocess.PIPE,
66 stderr=subprocess.PIPE)
67
68 results = p.communicate()
69
70 return json.loads(results[0])
71
72
73
74def list_milestones_for_repo(username, password, repo_owner, repo):
75
76 """
77 Does this::
78
79 curl -u "{username}:{password}" \\
80 https://api.github.com/repos/{repo_owner}/{repo}/milestones
81
82 """
83
84 auth_option = '%s:%s' % (username, password)
85
86 url = ('https://api.github.com/repos/%s/%s/milestones'
87 % (repo_owner, repo))
88
89 args = ['curl', '-u', auth_option, url]
90
91 p = subprocess.Popen(args, stdout=subprocess.PIPE,
92 stderr=subprocess.PIPE)
93
94 results = p.communicate()
95
96 return json.loads(results[0])
97
98
99def list_issues_in_milestone(username, password, repo_owner, repo,
100 milestone_number):
101
102 """
103 Does this::
104
105 curl -u "username:password" \\
106 https://api.github.com/repos/repo_owner/repo/issues \\
107 ?milestone={milestone_number}
108
109 """
110
111 auth_option = '%s:%s' % (username, password)
112
113 url = ('https://api.github.com/repos/%s/%s/issues?milestone=%s'
114 % (repo_owner, repo, milestone_number))
115
116 args = ['curl', '-u', auth_option, url]
117
118 p = subprocess.Popen(args, stdout=subprocess.PIPE,
119 stderr=subprocess.PIPE)
120
121 results = p.communicate()
122
123 return json.loads(results[0])