diff --git a/.gitignore b/.gitignore index 269c735..f0c73ea 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ MANIFEST docs/_build dist/ +build/ *egg-info diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..44333a8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: python +python: + - "2.6" + - "2.7" +install: + - pip install -r requirements/dev.txt --use-mirrors +script: nosetests diff --git a/AUTHORS.rst b/AUTHORS.rst index 3497c25..9a5f5e1 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -1,4 +1,5 @@ python-github3 is written and maintained by **David Medina** and + various contributors: Development Lead @@ -24,3 +25,11 @@ Patches and Suggestions - Francisco Marcos - Nathaniel Williams - Alejandro Gómez +- Stefano Rivera +- Ouertani Mohammed Amine +- Conor Branagan +- Ralph Bean +- Jason A. Donenfeld +- Brad Montgomery +- Thomas Whitton +- Jonas Baumann diff --git a/MANIFEST.in b/MANIFEST.in index 93f4e76..072beda 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ include AUTHORS.rst include README.rst include LICENSE -include requirements.txt +include requirements/base.txt diff --git a/README.rst b/README.rst index d7fa447..dc80034 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,5 @@ +.. image:: https://secure.travis-ci.org/copitux/python-github3.png + Pygithub3 ========== @@ -43,11 +45,13 @@ Achievements - `Gists service `_ - `Git Data service `_ - `Pull requests service `_ +- `Orgs service `_ +- `Issues service `_ +- `Events service `_ TODO ----- -- Services: Issues, Orgs, Events - Oauth authorization API (service?) - Proxy methods into resources (e.g copitux.followers) diff --git a/docs/events.rst b/docs/events.rst new file mode 100644 index 0000000..49d0de5 --- /dev/null +++ b/docs/events.rst @@ -0,0 +1,150 @@ +.. _Events service: + +Events service +============== + +This service exposes the `Events API`_. Much of this API is read-only, and while +pagination is supported, there is a fixed page size of 30 with a limit of 10 +page requests. + +Many events have an `actor` which denotes the user that performed an event. +Additionally, there may be `org` or `repo` attributes for events related to +Organizations and Repos. Finally, each event object contains a `payload` +attribute containing more detailed information about the event. + +.. _public events: + +Public Events +------------- +Yields the most recent public events from Github. + +:: + + from pygithub3 import Github + + gh = Github() + + events = gh.events.list().all() + print events[0].payload + +Event +....... + +.. autoclass:: pygithub3.services.events.Event + :members: + + .. attribute:: issues + + :ref:`Issues events ` + + .. attribute:: networks + + :ref:`Events network service` + + .. attribute:: orgs + + :ref:`Events org service` + + .. attribute:: repos + + :ref:`Events repo service` + + .. attribute:: users + + :ref:`Events user service` + +.. _repository events: + +Repo Events +----------- + +These are events for a specific repo, including issue and network events. The +Issues events are proxied to the :ref:`Issues service`. + +:: + + events = gh.events.repos.list(user="copitux", repo="python-github3") + for e in events.next(): + print("{t}".format(t=e.type)) + + # Get the issue Events + events = gh.events.issues.list_by_repo(user="copitux", + repo="python-github3") + + # Get the Public Events for a Repo's Network + events = gh.events.networks.list(user="copitux", repo="python-github3") + +.. _Events network service: + +Network +....... + +.. autoclass:: pygithub3.services.events.networks.Network + :members: + + +.. _Events repo service: + +Repo +........ + +.. autoclass:: pygithub3.services.events.repos.Repo + :members: + + +.. _organziation events: + +Organization Events +------------------- + +These are the public events for an Organization + +:: + + events = gh.events.orgs.list(org="Acme") + +You may also get a user's feed of events for an Organization, but you *must* be +authenticated as the provided user, and you must be a member of the given +organization. + +:: + + events = gh.events.users.orgs(user="copitux", org="acme") + +.. _Events org service: + +Org +........ + +.. autoclass:: pygithub3.services.events.orgs.Org + :members: + +.. _user events: + +User Events +----------- + +You can retrieve the public events performed by a user and the public events +that a user receives. If you're authenticated, you may also receive private +events. + +:: + + received_events = gh.events.users.list_received_public(user="copitux") + performed_events = gh.events.users.list_performed_public(user="copitux") + +If authenticated as `copitux`, you could get private events with the +following, otherwise you'll just get the public events as above: + +:: + + received_events = gh.events.users.list_received(user="copitux") + performed_events = gh.events.users.list_performed(user="copitux") + +.. _Events user service: + +User +........ + +.. autoclass:: pygithub3.services.events.users.User + :members: diff --git a/docs/issues.rst b/docs/issues.rst new file mode 100644 index 0000000..3c35eb8 --- /dev/null +++ b/docs/issues.rst @@ -0,0 +1,74 @@ +.. _Issues service: + +Issues services +=============== + +**Fast sample**:: + + from pygithub3 import Github + + auth = dict(login='octocat', password='pass') + gh = Github(**auth) + + octocat_issues = gh.issues.list() + octocat_repo_issues = gh.issues.list_by_repo('octocat', 'Hello-World') + +Issues +------ + +.. autoclass:: pygithub3.services.issues.Issue + :members: + + .. attribute:: comments + + :ref:`Issues comments service` + + .. attribute:: events + + :ref:`Issues events service` + + .. attribute:: labels + + :ref:`Labels service` + + .. attribute:: milestones + + :ref:`Milestones service` + +.. _Issues comments service: + +Comments +-------- + +.. autoclass:: pygithub3.services.issues.Comments + :members: + +.. _Issues events service: + +Events +------ + +.. autoclass:: pygithub3.services.issues.Events + :members: + +.. _Labels service: + +Labels +------ + +.. autoclass:: pygithub3.services.issues.Labels + :members: + +.. _Milestones service: + +Milestones +---------- + +.. autoclass:: pygithub3.services.issues.Milestones + :members: + +.. _github issues doc: http://developer.github.com/v3/issues +.. _github comments doc: http://developer.github.com/v3/issues/comments +.. _github events doc: http://developer.github.com/v3/issues/events +.. _github labels doc: http://developer.github.com/v3/issues/labels +.. _github milestones doc: http://developer.github.com/v3/issues/milestones diff --git a/docs/orgs.rst b/docs/orgs.rst new file mode 100644 index 0000000..96e7a73 --- /dev/null +++ b/docs/orgs.rst @@ -0,0 +1,46 @@ +.. _Orgs service: + +Orgs services +============== + +**Fast sample**:: + + from pygithub3 import Github + + gh = Github(token='abc123') + + auth_orgs = gh.orgs.list().all() + members = gh.orgs.members.list('github') + +Org +------ + +.. autoclass:: pygithub3.services.orgs.Org + :members: + + .. attribute:: members + + :ref:`Members service` + + .. attribute:: teams + + :ref:`Teams service` + +.. _Members service: + +Members +--------- + +.. autoclass:: pygithub3.services.orgs.members.Members + :members: + +.. _Teams service: + +Teams +------- + +.. autoclass:: pygithub3.services.orgs.teams.Teams + :members: + +.. _github orgs doc: http://developer.github.com/v3/orgs +.. _github orgs teams doc: http://developer.github.com/v3/orgs/teams diff --git a/docs/repos.rst b/docs/repos.rst index c065671..9832f3d 100644 --- a/docs/repos.rst +++ b/docs/repos.rst @@ -128,6 +128,14 @@ Watchers .. autoclass:: pygithub3.services.repos.Watchers :members: +.. _Stargazers service: + +Stargazers +--------- + +.. autoclass:: pygithub3.services.repos.Stargazers + :members: + .. _Hooks service: Hooks @@ -136,6 +144,12 @@ Hooks .. autoclass:: pygithub3.services.repos.Hooks :members: +Statuses +--------- + +.. autoclass:: pygithub3.services.repos.Statuses + :members: + .. _github repos doc: http://developer.github.com/v3/repos .. _github collaborators doc: http://developer.github.com/v3/repos/collaborators .. _github commits doc: http://developer.github.com/v3/repos/commits @@ -144,3 +158,4 @@ Hooks .. _github keys doc: http://developer.github.com/v3/repos/keys .. _github watching doc: http://developer.github.com/v3/repos/watching .. _github hooks doc: http://developer.github.com/v3/repos/hooks +.. _github statuses doc: http://developer.github.com/v3/repos/statuses diff --git a/docs/services.rst b/docs/services.rst index 190ae99..998fb7e 100644 --- a/docs/services.rst +++ b/docs/services.rst @@ -74,5 +74,8 @@ List of services gists git_data pull_requests + orgs + issues + events .. _mimetypes: http://developer.github.com/v3/mime diff --git a/pygithub3/__init__.py b/pygithub3/__init__.py index 9a626f3..461dabe 100644 --- a/pygithub3/__init__.py +++ b/pygithub3/__init__.py @@ -1,8 +1,7 @@ -#!/usr/bin/env python # -*- encoding: utf-8 -*- __title__ = 'pygithub3' -__version__ = '0.3' +__version__ = '0.5' __author__ = 'David Medina' __email__ = 'davidmedina9@gmail.com' __license__ = 'ISC' diff --git a/pygithub3/core/client.py b/pygithub3/core/client.py index ee7c97f..d4b8cd5 100644 --- a/pygithub3/core/client.py +++ b/pygithub3/core/client.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- encoding: utf-8 -*- import requests @@ -25,6 +24,8 @@ def __init__(self, **kwargs): self.config.update(kwargs) self.set_credentials(self.config.get('login'), self.config.get('password')) + self.set_oauth_credentials(self.config.get('client_id'), + self.config.get('client_secret')) self.set_token(self.config.get('token')) self.__set_params(self.config) @@ -48,14 +49,22 @@ def set_credentials(self, login, password): if login and password: self.requester.auth = (login, password) + def set_oauth_credentials(self, client_id, client_secret): + if client_id and client_secret: + self.requester.params.append(('client_id', client_id)) + self.requester.params.append(('client_secret', client_secret)) + def set_token(self, token): if token: - self.requester.params['access_token'] = token + self.requester.params.append(('access_token', token)) def __set_params(self, config): - self.requester.params['per_page'] = config.get('per_page') + per_page = ('per_page', config.get('per_page')) + self.requester.params.append(per_page) if config.get('verbose'): self.requester.config = {'verbose': config['verbose']} + if config.get('timeout'): + self.requester.timeout = config['timeout'] def __parse_kwargs(func): """ Decorator to put extra args into requests.params """ diff --git a/pygithub3/core/utils.py b/pygithub3/core/compat.py similarity index 97% rename from pygithub3/core/utils.py rename to pygithub3/core/compat.py index 24a3bbf..c6dbf0a 100644 --- a/pygithub3/core/utils.py +++ b/pygithub3/core/compat.py @@ -2,11 +2,6 @@ # -*- encoding: utf-8 -*- """ Utils to support python 2.6 compatibility """ -try: - import simplejson as json -except ImportError: - import json - from collections import MutableMapping diff --git a/pygithub3/core/errors.py b/pygithub3/core/errors.py index 9b84479..d86b2dd 100644 --- a/pygithub3/core/errors.py +++ b/pygithub3/core/errors.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- encoding: utf-8 -*- -from pygithub3.core.utils import json +from pygithub3.core import json from pygithub3.exceptions import NotFound, BadRequest, UnprocessableEntity diff --git a/pygithub3/core/json/__init__.py b/pygithub3/core/json/__init__.py new file mode 100644 index 0000000..f0adb20 --- /dev/null +++ b/pygithub3/core/json/__init__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +""" +Emulate json module with encode/decoders to support github datetime format +""" + +from datetime import datetime +try: + import simplejson as json +except ImportError: + import json + +GITHUB_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ' + + +class GHJSONEncoder(json.JSONEncoder): + def default(self, o): + try: + return datetime.strftime(o, GITHUB_DATE_FORMAT) + except: + return super(GHJSONEncoder, self).default(o) + + +def gh_decoder_hook(dict_): + for k, v in dict_.iteritems(): + try: + date = datetime.strptime(v, GITHUB_DATE_FORMAT) + dict_[k] = date + except: + continue + return dict_ + + +def dumps(obj, cls=GHJSONEncoder, **kwargs): + return json.dumps(obj, cls=cls, **kwargs) + + +def loads(s, object_hook=gh_decoder_hook, **kwargs): + return json.loads(s, object_hook=object_hook, **kwargs) + +dump = json.dump +load = json.load diff --git a/pygithub3/github.py b/pygithub3/github.py index 87c4a6d..d64577c 100644 --- a/pygithub3/github.py +++ b/pygithub3/github.py @@ -17,13 +17,19 @@ def __init__(self, **config): from pygithub3.services.users import User from pygithub3.services.repos import Repo from pygithub3.services.gists import Gist + from pygithub3.services.events import Event from pygithub3.services.git_data import GitData from pygithub3.services.pull_requests import PullRequests + from pygithub3.services.orgs import Org + from pygithub3.services.issues import Issue self._users = User(**config) self._repos = Repo(**config) self._gists = Gist(**config) self._git_data = GitData(**config) self._pull_requests = PullRequests(**config) + self._orgs = Org(**config) + self._issues = Issue(**config) + self._events = Event(**config) @property def remaining_requests(self): @@ -65,3 +71,24 @@ def pull_requests(self): :ref:`Pull Requests service ` """ return self._pull_requests + + @property + def orgs(self): + """ + :ref:`Orgs service ` + """ + return self._orgs + + @property + def issues(self): + """ + :ref:`Issues service ` + """ + return self._issues + + @property + def events(self): + """ + :ref:`Events service ` + """ + return self._events diff --git a/pygithub3/requests/base.py b/pygithub3/requests/base.py index c4fe5cc..7eb0ff3 100644 --- a/pygithub3/requests/base.py +++ b/pygithub3/requests/base.py @@ -1,9 +1,9 @@ -#!/usr/bin/env python # -*- encoding: utf-8 -*- import re -from pygithub3.core.utils import import_module, json +from pygithub3.core import json +from pygithub3.core.compat import import_module from pygithub3.exceptions import (RequestDoesNotExist, UriInvalid, ValidationError, InvalidBodySchema) from pygithub3.resources.base import Raw @@ -27,8 +27,8 @@ def dumps(self): def parse(self): """ Parse body with schema-required rules """ if not hasattr(self.content, 'items'): - raise ValidationError("'%s' needs a content dictionary" - % self.__class__.__name__) + raise ValidationError("It needs a content dictionary (%s)" % ( + self.content, )) parsed = dict([(key, self.content[key]) for key in self.schema if key in self.content]) for attr_required in self.required: diff --git a/pygithub3/requests/events/__init__.py b/pygithub3/requests/events/__init__.py new file mode 100644 index 0000000..fd4988f --- /dev/null +++ b/pygithub3/requests/events/__init__.py @@ -0,0 +1,10 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request +from pygithub3.resources.events import Event + + +class List(Request): + + uri = 'events' + resource = Event diff --git a/pygithub3/requests/events/networks.py b/pygithub3/requests/events/networks.py new file mode 100644 index 0000000..e510773 --- /dev/null +++ b/pygithub3/requests/events/networks.py @@ -0,0 +1,10 @@ +# -*- encoding: utf-8 -*- + +from . import Request +from pygithub3.resources.events import Network + + +class List(Request): + + uri = 'networks/{user}/{repo}/events' + resource = Network diff --git a/pygithub3/requests/events/orgs.py b/pygithub3/requests/events/orgs.py new file mode 100644 index 0000000..c8e9fc7 --- /dev/null +++ b/pygithub3/requests/events/orgs.py @@ -0,0 +1,10 @@ +# -*- encoding: utf-8 -*- + +from . import Request +from pygithub3.resources.events import Org + + +class List(Request): + + uri = 'orgs/{org}/events' + resource = Org diff --git a/pygithub3/requests/events/repos.py b/pygithub3/requests/events/repos.py new file mode 100644 index 0000000..6bb2f98 --- /dev/null +++ b/pygithub3/requests/events/repos.py @@ -0,0 +1,10 @@ +# -*- encoding: utf-8 -*- + +from . import Request +from pygithub3.resources.events import Repo + + +class List(Request): + + uri = 'repos/{user}/{repo}/events' + resource = Repo diff --git a/pygithub3/requests/events/users.py b/pygithub3/requests/events/users.py new file mode 100644 index 0000000..a8556ae --- /dev/null +++ b/pygithub3/requests/events/users.py @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- + +from . import Request +from pygithub3.resources.events import User, Org + + +class List_received(Request): + + uri = 'users/{user}/received_events' + resource = User + + +class List_received_public(Request): + + uri = 'users/{user}/received_events/public' + resource = User + + +class List_performed(Request): + + uri = 'users/{user}/events' + resource = User + + +class List_performed_public(Request): + + uri = 'users/{user}/events/public' + resource = User + + +class List_org_events(Request): + + uri = 'users/{user}/events/orgs/{org}' + resource = Org diff --git a/pygithub3/requests/gists/__init__.py b/pygithub3/requests/gists/__init__.py index 4dbc6e6..a8d92b7 100644 --- a/pygithub3/requests/gists/__init__.py +++ b/pygithub3/requests/gists/__init__.py @@ -1,8 +1,9 @@ # -*- encoding: utf-8 -*- -from pygithub3.requests.base import Request, ValidationError +from pygithub3.requests.base import Request from pygithub3.resources.gists import Gist + class List(Request): uri = 'users/{user}/gists' diff --git a/pygithub3/requests/gists/comments.py b/pygithub3/requests/gists/comments.py index 8e5af15..1da78cb 100644 --- a/pygithub3/requests/gists/comments.py +++ b/pygithub3/requests/gists/comments.py @@ -3,6 +3,7 @@ from pygithub3.requests.base import Request from pygithub3.resources.gists import Comment + class List(Request): uri = 'gists/{gist_id}/comments' diff --git a/pygithub3/requests/git_data/references.py b/pygithub3/requests/git_data/references.py index 2aac6a4..9824bdb 100644 --- a/pygithub3/requests/git_data/references.py +++ b/pygithub3/requests/git_data/references.py @@ -1,3 +1,5 @@ +# -*- encoding: utf-8 -*- + from pygithub3.requests.base import Request from pygithub3.resources.git_data import Reference @@ -20,6 +22,7 @@ class Create(Request): 'required': ('ref', 'sha'), } + class Update(Request): uri = 'repos/{user}/{repo}/git/refs/{ref}' resource = Reference diff --git a/pygithub3/requests/git_data/tags.py b/pygithub3/requests/git_data/tags.py index dbc8da4..88a79c0 100644 --- a/pygithub3/requests/git_data/tags.py +++ b/pygithub3/requests/git_data/tags.py @@ -1,3 +1,5 @@ +# -*- encoding: utf-8 -*- + from pygithub3.requests.base import Request from pygithub3.resources.git_data import Tag @@ -6,6 +8,7 @@ class Get(Request): uri = 'repos/{user}/{repo}/git/tags/{sha}' resource = Tag + class Create(Request): uri = 'repos/{user}/{repo}/git/tags' resource = Tag diff --git a/pygithub3/requests/issues/__init__.py b/pygithub3/requests/issues/__init__.py new file mode 100644 index 0000000..d6c7b06 --- /dev/null +++ b/pygithub3/requests/issues/__init__.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request +from pygithub3.resources.issues import Issue + + +class List(Request): + + uri = 'issues' + resource = Issue + + +class List_by_repo(Request): + + uri = 'repos/{user}/{repo}/issues' + resource = Issue + + +class Get(Request): + + uri = 'repos/{user}/{repo}/issues/{number}' + resource = Issue + + +class Create(Request): + + uri = 'repos/{user}/{repo}/issues' + resource = Issue + body_schema = { + 'schema': ('title', 'body', 'assignee', 'milestone', 'labels'), + 'required': ('title', ) + } + + +class Update(Request): + + uri = 'repos/{user}/{repo}/issues/{number}' + resource = Issue + body_schema = { + 'schema': ('title', 'body', 'assignee', 'state', 'milestone', + 'lables'), + 'required': () + } diff --git a/pygithub3/requests/issues/comments.py b/pygithub3/requests/issues/comments.py new file mode 100644 index 0000000..c9618a8 --- /dev/null +++ b/pygithub3/requests/issues/comments.py @@ -0,0 +1,42 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request +from pygithub3.resources.issues import Comment + + +class List(Request): + + uri = 'repos/{user}/{repo}/issues/{number}/comments' + resource = Comment + + +class Get(Request): + + uri = 'repos/{user}/{repo}/issues/comments/{id}' + resource = Comment + + +class Create(Request): + + uri = 'repos/{user}/{repo}/issues/{number}/comments' + resource = Comment + body_schema = { + 'schema': ('body', ), + 'required': ('body', ) + } + + +class Edit(Request): + + uri = 'repos/{user}/{repo}/issues/comments/{id}' + resource = Comment + body_schema = { + 'schema': ('body', ), + 'required': ('body', ) + } + + +class Delete(Request): + + uri = 'repos/{user}/{repo}/issues/comments/{id}' + resource = Comment diff --git a/pygithub3/requests/issues/events.py b/pygithub3/requests/issues/events.py new file mode 100644 index 0000000..d284681 --- /dev/null +++ b/pygithub3/requests/issues/events.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request +from pygithub3.resources.issues import Event + + +class List_by_issue(Request): + + uri = 'repos/{user}/{repo}/issues/{number}/events' + resource = Event + + +class List_by_repo(Request): + + uri = 'repos/{user}/{repo}/issues/events' + resource = Event + + +class Get(Request): + + uri = 'repos/{user}/{repo}/issues/events/{id}' + resource = Event diff --git a/pygithub3/requests/issues/labels.py b/pygithub3/requests/issues/labels.py new file mode 100644 index 0000000..7ba6c7a --- /dev/null +++ b/pygithub3/requests/issues/labels.py @@ -0,0 +1,77 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request, ValidationError +from pygithub3.resources.issues import Label + + +class List(Request): + + uri = 'repos/{user}/{repo}/labels' + resource = Label + + +class Get(Request): + uri = 'repos/{user}/{repo}/labels/{name}' + resource = Label + + +class Create(Request): + uri = 'repos/{user}/{repo}/labels' + resource = Label + body_schema = { + 'schema': ('name', 'color'), + 'required': ('name', 'color') + } + + def clean_body(self): + color = self.body.get('color', '') + if not Label.is_valid_color(color): + raise ValidationError('colors must have 6 hexadecimal characters, ' + 'without # in the beggining') + else: + return self.body + + +class Update(Create): + + uri = 'repos/{user}/{repo}/labels/{name}' + resource = Label + body_schema = { + 'schema': ('name', 'color'), + 'required': ('name', 'color') + } + + +class Delete(Request): + uri = 'repos/{user}/{repo}/labels/{name}' + resource = Label + + +class List_by_issue(Request): + uri = 'repos/{user}/{repo}/issues/{number}/labels' + resource = Label + + +class Add_to_issue(Request): + uri = 'repos/{user}/{repo}/issues/{number}/labels' + resource = Label + + +class Remove_from_issue(Request): + uri = 'repos/{user}/{repo}/issues/{number}/labels/{name}' + resource = Label + + +class Replace_all(Request): + uri = 'repos/{user}/{repo}/issues/{number}/labels' + resource = Label + + +class Remove_all(Request): + uri = 'repos/{user}/{repo}/issues/{number}/labels' + resource = Label + + +class List_by_milestone(Request): + uri = 'repos/{user}/{repo}/milestones/{number}/labels' + resource = Label diff --git a/pygithub3/requests/issues/milestones.py b/pygithub3/requests/issues/milestones.py new file mode 100644 index 0000000..4093c7e --- /dev/null +++ b/pygithub3/requests/issues/milestones.py @@ -0,0 +1,39 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request, ValidationError +from pygithub3.resources.issues import Milestone + + +class List(Request): + uri = 'repos/{user}/{repo}/milestones' + resource = Milestone + + +class Get(Request): + uri = 'repos/{user}/{repo}/milestones/{number}' + resource = Milestone + + +class Create(Request): + uri = 'repos/{user}/{repo}/milestones' + resource = Milestone + body_schema = { + 'schema': ('title', 'state', 'description', 'due_on'), + 'required': ('title',) + } + + def clean_body(self): # Test if API normalize it + state = self.body.get('state', '') + if state and state.lower() not in ('open', 'closed'): + raise ValidationError("'state' must be 'open' or 'closed'") + return self.body + + +class Update(Create): + + uri = 'repos/{user}/{repo}/milestones/{number}' + + +class Delete(Request): + uri = 'repos/{user}/{repo}/milestones/{number}' + resource = Milestone diff --git a/pygithub3/requests/orgs/__init__.py b/pygithub3/requests/orgs/__init__.py new file mode 100644 index 0000000..deba5ef --- /dev/null +++ b/pygithub3/requests/orgs/__init__.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request +from pygithub3.resources.orgs import Org + + +class List(Request): + uri = 'users/{user}/orgs' + resource = Org + + def clean_uri(self): + if not self.user: + return 'user/orgs' + + +class Get(Request): + uri = 'orgs/{org}' + resource = Org + + +class Update(Request): + uri = 'orgs/{org}' + resource = Org + body_schema = { + 'schema': ('billing_email', 'company', 'email', 'location', 'name'), + 'required': (), + } diff --git a/pygithub3/requests/orgs/members.py b/pygithub3/requests/orgs/members.py new file mode 100644 index 0000000..a6b05c2 --- /dev/null +++ b/pygithub3/requests/orgs/members.py @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.resources.orgs import Member +from . import Request + + +class List(Request): + uri = 'orgs/{org}/members' + resource = Member + + +class Is_member(Request): + uri = 'orgs/{org}/members/{user}' + + +class Delete(Request): + uri = 'orgs/{org}/members/{user}' + + +class Listpublic(Request): + uri = 'orgs/{org}/public_members' + resource = Member + + +class Is_public_member(Request): + uri = 'orgs/{org}/public_members/{user}' + + +class Publicize(Request): + uri = 'orgs/{org}/public_members/{user}' + + +class Conceal(Request): + uri = 'orgs/{org}/public_members/{user}' diff --git a/pygithub3/requests/orgs/teams.py b/pygithub3/requests/orgs/teams.py new file mode 100644 index 0000000..cc92f9c --- /dev/null +++ b/pygithub3/requests/orgs/teams.py @@ -0,0 +1,74 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.resources.orgs import Member, Team +from pygithub3.resources.repos import Repo +from . import Request + + +class List(Request): + uri = 'orgs/{org}/teams' + resource = Team + + +class Get(Request): + uri = 'teams/{id}' + resource = Team + + +class Create(Request): + uri = 'orgs/{org}/teams' + resource = Team + body_schema = { + 'schema': ('name', 'repo_names', 'permission',), + 'required': ('name',), + } + + # TODO: Check if this request fails with invalid permission + #def clean_body(self): + + +class Update(Request): + uri = 'teams/{id}' + resource = Team + body_schema = { + 'schema': ('name', 'permission',), + 'required': ('name',), + } + + +class Delete(Request): + uri = 'teams/{id}' + + +class List_members(Request): + uri = 'teams/{id}/members' + resource = Member + + +class Is_member(Request): + uri = 'teams/{id}/members/{user}' + + +class Add_member(Request): + uri = 'teams/{id}/members/{user}' + + +class Remove_member(Request): + uri = 'teams/{id}/members/{user}' + + +class List_repos(Request): + uri = 'teams/{id}/repos' + resource = Repo + + +class Contains_repo(Request): + uri = 'teams/{id}/repos/{user}/{repo}' + + +class Add_repo(Request): + uri = 'teams/{id}/repos/{user}/{repo}' + + +class Remove_repo(Request): + uri = 'teams/{id}/repos/{user}/{repo}' diff --git a/pygithub3/requests/pull_requests/__init__.py b/pygithub3/requests/pull_requests/__init__.py index f25572d..5845dd7 100644 --- a/pygithub3/requests/pull_requests/__init__.py +++ b/pygithub3/requests/pull_requests/__init__.py @@ -30,6 +30,7 @@ def clean_body(self): 'issue number or a title and body') return self.body + class Update(Request): uri = 'repos/{user}/{repo}/pulls/{number}' resource = PullRequest diff --git a/pygithub3/requests/repos/__init__.py b/pygithub3/requests/repos/__init__.py index cd920fe..3e48865 100644 --- a/pygithub3/requests/repos/__init__.py +++ b/pygithub3/requests/repos/__init__.py @@ -1,8 +1,10 @@ # -*- encoding: utf-8 -*- -from pygithub3.requests.base import Request, ValidationError +from pygithub3.requests.base import Request +from pygithub3.resources.orgs import Team +from pygithub3.resources.repos import Repo, Tag, Branch from pygithub3.resources.users import User -from pygithub3.resources.repos import Repo, Team, Tag, Branch + class List(Request): @@ -41,6 +43,12 @@ class Get(Request): resource = Repo +class Delete(Request): + + uri = 'repos/{user}/{repo}' + resource = Repo + + class Update(Request): uri = 'repos/{user}/{repo}' @@ -74,7 +82,14 @@ class List_tags(Request): uri = 'repos/{user}/{repo}/tags' resource = Tag + class List_branches(Request): uri = 'repos/{user}/{repo}/branches' resource = Branch + + +class Get_branch(Request): + + uri = 'repos/{user}/{repo}/branches/{branch}' + resource = Branch diff --git a/pygithub3/requests/repos/stargazers.py b/pygithub3/requests/repos/stargazers.py new file mode 100644 index 0000000..b1feb2a --- /dev/null +++ b/pygithub3/requests/repos/stargazers.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from . import Request +from pygithub3.resources.users import User +from pygithub3.resources.repos import Repo + + +class List(Request): + + uri = 'repos/{user}/{repo}/stargazers' + resource = User + + +class List_repos(Request): + + uri = 'users/{user}/starred' + resource = Repo + + def clean_uri(self): + if not self.user: + return 'user/starred' + + +class Is_starring(Request): + + uri = 'user/starred/{user}/{repo}' + + +class Star(Request): + + uri = 'user/starred/{user}/{repo}' + + +class Unstar(Request): + + uri = 'user/starred/{user}/{repo}' diff --git a/pygithub3/requests/repos/statuses.py b/pygithub3/requests/repos/statuses.py new file mode 100644 index 0000000..eaf307d --- /dev/null +++ b/pygithub3/requests/repos/statuses.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from . import Request + +from pygithub3.resources.repos import Status + + +class List(Request): + + uri = 'repos/{user}/{repo}/statuses/{sha}' + resource = Status + + +class Create(Request): + + uri = '/repos/{user}/{repo}/statuses/{sha}' + resource = Status + body_schema = { + 'schema': ('state', 'target_url', 'description'), + 'required': ('state',)} diff --git a/pygithub3/requests/repos/watchers.py b/pygithub3/requests/repos/watchers.py index 46e01d7..0889847 100644 --- a/pygithub3/requests/repos/watchers.py +++ b/pygithub3/requests/repos/watchers.py @@ -8,30 +8,30 @@ class List(Request): - uri = 'repos/{user}/{repo}/watchers' + uri = 'repos/{user}/{repo}/subscribers' resource = User class List_repos(Request): - uri = 'users/{user}/watched' + uri = 'users/{user}/subscriptions' resource = Repo def clean_uri(self): if not self.user: - return 'user/watched' + return 'user/subscriptions' class Is_watching(Request): - uri = 'user/watched/{user}/{repo}' + uri = 'user/subscriptions/{user}/{repo}' class Watch(Request): - uri = 'user/watched/{user}/{repo}' + uri = 'user/subscriptions/{user}/{repo}' class Unwatch(Request): - uri = 'user/watched/{user}/{repo}' + uri = 'user/subscriptions/{user}/{repo}' diff --git a/pygithub3/resources/base.py b/pygithub3/resources/base.py index 7045529..25b045c 100644 --- a/pygithub3/resources/base.py +++ b/pygithub3/resources/base.py @@ -1,7 +1,6 @@ -#!/usr/bin/env python -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- -from pygithub3.core.utils import json +from pygithub3.core import json class Resource(object): @@ -11,7 +10,6 @@ class Resource(object): _collection_maps = {} def __init__(self, attrs): - """ """ self._attrs = attrs self.__set_attrs() @@ -43,14 +41,6 @@ def wrapper(resource, raw_resource): return func(resource, raw_resource) return wrapper - def parse_date(string_date): - from datetime import datetime - try: - date = datetime.strptime(string_date, '%Y-%m-%dT%H:%M:%SZ') - except TypeError: - date = None - return date - @self_resource def parse_map(resource, raw_resource): if hasattr(raw_resource, 'items'): @@ -70,9 +60,6 @@ def parse_collection_map(resource, raw_resources): for raw_resource in raw_resources] new_resource = raw_resource.copy() - new_resource.update(dict([ - (attr, parse_date(raw_resource[attr])) - for attr in self._dates if attr in raw_resource])) new_resource.update(dict([ (attr, parse_map(resource, raw_resource[attr])) for attr, resource in self._maps.items() diff --git a/pygithub3/resources/events.py b/pygithub3/resources/events.py new file mode 100644 index 0000000..d779c23 --- /dev/null +++ b/pygithub3/resources/events.py @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.resources.base import Resource +from pygithub3.resources import users, repos, orgs + + +class Event(Resource): + + _dates = ('created_at', ) + _maps = {'actor': users.User, 'repo': repos.Repo, 'org': orgs.Org} + + def __str__(self): + return '<(%s)>' % getattr(self, 'type', '') + + +class Repo(Resource): + + _dates = ('created_at', ) + _maps = {'actor': users.User, 'repo': repos.Repo, 'org': orgs.Org} + + def __str__(self): + return '<(%s)>' % getattr(self, 'type', '') + + +class Network(Resource): + + _dates = ('created_at', ) + _maps = {'actor': users.User, 'repo': repos.Repo, 'org': orgs.Org} + + def __str__(self): + return '<(%s)>' % getattr(self, 'type', '') + + +class Org(Resource): + + _dates = ('created_at', ) + _maps = {'actor': users.User, 'repo': repos.Repo, 'org': orgs.Org} + + def __str__(self): + return '<(%s)>' % getattr(self, 'type', '') + + +class User(Resource): + + _dates = ('created_at', ) + _maps = {'actor': users.User, 'repo': repos.Repo, 'org': orgs.Org} + + def __str__(self): + return '<(%s)>' % getattr(self, 'type', '') diff --git a/pygithub3/resources/gists.py b/pygithub3/resources/gists.py index 89425bf..feb39c1 100644 --- a/pygithub3/resources/gists.py +++ b/pygithub3/resources/gists.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- encoding: utf-8 -*- from .base import Resource @@ -28,6 +27,7 @@ class History(Resource): def __str__(self): return '' % getattr(self, 'version', '') + class Gist(Resource): _dates = ('created_at', ) @@ -37,6 +37,7 @@ class Gist(Resource): def __str__(self): return '' % getattr(self, 'description', '') + class Comment(Resource): _dates = ('created_at', ) 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 '