aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/resources
diff options
context:
space:
mode:
Diffstat (limited to 'pygithub3/resources')
-rw-r--r--pygithub3/resources/base.py7
-rw-r--r--pygithub3/resources/issues.py65
2 files changed, 70 insertions, 2 deletions
diff --git a/pygithub3/resources/base.py b/pygithub3/resources/base.py
index 7045529..4c65b8b 100644
--- a/pygithub3/resources/base.py
+++ b/pygithub3/resources/base.py
@@ -1,8 +1,12 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
+from datetime import datetime
+
from pygithub3.core.utils import json
+GITHUB_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
+
class Resource(object):
@@ -44,9 +48,8 @@ class Resource(object):
return wrapper
def parse_date(string_date):
- from datetime import datetime
try:
- date = datetime.strptime(string_date, '%Y-%m-%dT%H:%M:%SZ')
+ date = datetime.strptime(string_date, GITHUB_DATE_FORMAT)
except TypeError:
date = None
return date
diff --git a/pygithub3/resources/issues.py b/pygithub3/resources/issues.py
new file mode 100644
index 0000000..b2301a6
--- /dev/null
+++ b/pygithub3/resources/issues.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+import re
+
+from .base import Resource
+from .users import User
+from .pull_requests import PullRequest
+
+
+class Label(Resource):
+
+ @staticmethod
+ def is_valid_color(color):
+ valid_color = re.compile(r'[0-9abcdefABCDEF]{6}')
+ match = valid_color.match(color)
+ if match is None:
+ return False
+ return match.start() == 0 and match.end() == len(color)
+
+ def __str__(self):
+ return '<Label (%s)>' % getattr(self, 'name', '')
+
+
+class Milestone(Resource):
+
+ _dates = ('created_at', 'due_on')
+ _maps = {'creator': User}
+
+ def __str__(self):
+ return '<Milestone (%s)>' % getattr(self, 'title', '')
+
+
+class Issue(Resource):
+
+ _dates = ('created_at', 'updated_at', 'closed_at')
+ _maps = {
+ 'assignee': User,
+ 'user': User,
+ 'milestone': Milestone,
+ 'pull_request': PullRequest
+ }
+
+ _collection_maps = {'labels': Label}
+
+ def __str__(self):
+ return '<Issue (%s)>' % getattr(self, 'number', '')
+
+
+class Comment(Resource):
+
+ _dates = ('created_at', 'updated_at')
+ _maps = {'user': User}
+
+ def __str__(self):
+ return '<Comment (%s)>' % (getattr(self, 'user', ''))
+
+
+class Event(Resource):
+
+ _dates = ('created_at', )
+ _maps = {'actor': User, 'issue': Issue}
+
+ def __str__(self):
+ return '<Event (%s)>' % (getattr(self, 'commit_id', ''))