forked from apache/storm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split off dependency libraries, and added in columns for age of pulls…
…/JIRA in days.
- Loading branch information
Robert (Bobby) Evans
committed
Jun 9, 2014
1 parent
4550bbf
commit e3b9d46
Showing
3 changed files
with
349 additions
and
265 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# -*- coding: utf-8 -*- | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import getpass | ||
import base64 | ||
import urllib | ||
import urllib2 | ||
from datetime import datetime | ||
try: | ||
import json | ||
except ImportError: | ||
import simplejson as json | ||
|
||
def mstr(obj): | ||
if (obj == None): | ||
return "" | ||
return unicode(obj) | ||
|
||
def gittime(obj): | ||
if (obj == None): | ||
return None | ||
return datetime.strptime(obj[0:19], "%Y-%m-%dT%H:%M:%S") | ||
|
||
class GitPullRequest: | ||
"""Pull Request from Git""" | ||
def __init__(self, data, parent): | ||
self.data = data | ||
self.parent = parent | ||
|
||
def html_url(self): | ||
return self.data["html_url"] | ||
|
||
def title(self): | ||
return self.data["title"] | ||
|
||
def number(self): | ||
return self.data["number"] | ||
|
||
#TODO def review_comments | ||
|
||
def user(self): | ||
return mstr(self.data["user"]["login"]) | ||
|
||
def fromBranch(self): | ||
return mstr(self.data["head"]["ref"]) | ||
|
||
def fromRepo(self): | ||
return mstr(self.data["head"]["repo"]["clone_url"]) | ||
|
||
def merged(self): | ||
return self.data["merged_at"] != None | ||
|
||
def raw(self): | ||
return self.data | ||
|
||
def created_at(self): | ||
return gittime(self.data["created_at"]) | ||
|
||
def updated_at(self): | ||
return gittime(self.data["updated_at"]) | ||
|
||
def merged_at(self): | ||
return gittime(self.data["merged_at"]) | ||
|
||
def __str__(self): | ||
return self.html_url() | ||
|
||
def __repr__(self): | ||
return self.html_url() | ||
|
||
class GitHub: | ||
"""Github API""" | ||
def __init__(self, options): | ||
self.headers = {} | ||
if options.gituser: | ||
gitpassword = getpass.getpass("github.com user " + options.gituser+":") | ||
authstr = base64.encodestring('%s:%s' % (options.gituser, gitpassword)).replace('\n', '') | ||
self.headers["Authorization"] = "Basic "+authstr | ||
|
||
def pulls(self, user, repo, type="all"): | ||
page=1 | ||
ret = [] | ||
while True: | ||
url = "https://api.github.com/repos/"+user+"/"+repo+"/pulls?state="+type+"&page="+str(page) | ||
|
||
req = urllib2.Request(url,None,self.headers) | ||
result = urllib2.urlopen(req) | ||
contents = result.read() | ||
if result.getcode() != 200: | ||
raise Exception(result.getcode() + " != 200 "+ contents) | ||
got = json.loads(contents) | ||
for part in got: | ||
ret.append(GitPullRequest(part, self)) | ||
if len(got) == 0: | ||
return ret | ||
page = page + 1 | ||
|
||
def openPulls(self, user, repo): | ||
return self.pulls(user, repo, "open") |
Oops, something went wrong.