Skip to content
This repository was archived by the owner on Dec 17, 2019. It is now read-only.

Commit ad34d93

Browse files
committed
Merge pull request copitux#20 from bradmontgomery/develop
1 parent aaf9243 commit ad34d93

File tree

15 files changed

+543
-0
lines changed

15 files changed

+543
-0
lines changed

docs/events.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.. _Events service:
2+
3+
Events service
4+
==============
5+
6+
This service exposes the `Events API`. Much of this API is read-only, and while
7+
pagination is supported, there is a fixed page size of 30 with a limit of 10
8+
page requests.
9+
10+
Many events have an `actor` which denotes the user that performed an event.
11+
Additionally, there may be `org` or `repo` attributes for events related to
12+
Organizations and Repos. Finally, each event object contains a `payload`
13+
attribute containing more detailed information about the event.
14+
.. _public events:
15+
16+
Public Events
17+
-------------
18+
Yields the most recent public events from Github.
19+
20+
::
21+
22+
from pygithub3 import Github
23+
24+
gh = Github()
25+
26+
events = gh.events.list().all()
27+
print events[0].payload
28+
29+
30+
.. _repository events:
31+
32+
Repo Events
33+
-----------
34+
35+
These are events for a specific repo, including issue and network events. The
36+
Issues events are proxied to the `Issues Service`_.
37+
38+
::
39+
40+
events = gh.events.repos.list(user="copitux", repo="python-github3")
41+
for e in events.next():
42+
print("{t}".format(t=e.type))
43+
44+
# Get the issue Events
45+
events = gh.events.issues.list_by_repo(user="copitux",
46+
repo="python-github3")
47+
48+
# Get the Public Events for a Repo's Network
49+
events = gh.events.networks.list(user="copitux", repo="python-github3")
50+
51+
.. _organziation events:
52+
53+
Organization Events
54+
-------------------
55+
56+
These are the public events for an Organization
57+
58+
::
59+
60+
events = gh.events.orgs.list(org="Acme")
61+
62+
You may also get a user's feed of events for an Organization, but you *must* be
63+
authenticated as the provided user, and you must be a member of the given
64+
organization.
65+
66+
::
67+
68+
events = gh.events.users.orgs(user="copitux", org="acme")
69+
70+
.. _user events:
71+
72+
User Events
73+
-----------
74+
75+
You can retrieve the public events performed by a user and the public events
76+
that a user receives. If you're authenticated, you may also receive private
77+
events.
78+
79+
::
80+
81+
received_events = gh.events.users.list_received_public(user="copitux")
82+
performed_events = gh.events.users.list_performed_public(user="copitux")
83+
84+
If authenticated as `copitux`, you could get private events with the
85+
following, otherwise you'll just get the public events as above:
86+
87+
::
88+
89+
received_events = gh.events.users.list_received(user="copitux")
90+
performed_events = gh.events.users.list_performed(user="copitux")
91+
92+
93+
.. _Events API: http://developer.github.com/v3/events/

docs/services.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ List of services
7676
pull_requests
7777
orgs
7878
issues
79+
events
7980

8081
.. _mimetypes: http://developer.github.com/v3/mime

pygithub3/github.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, **config):
1717
from pygithub3.services.users import User
1818
from pygithub3.services.repos import Repo
1919
from pygithub3.services.gists import Gist
20+
from pygithub3.services.events import Events
2021
from pygithub3.services.git_data import GitData
2122
from pygithub3.services.pull_requests import PullRequests
2223
from pygithub3.services.orgs import Org
@@ -28,6 +29,7 @@ def __init__(self, **config):
2829
self._pull_requests = PullRequests(**config)
2930
self._orgs = Org(**config)
3031
self._issues = Issue(**config)
32+
self._events = Events(**config)
3133

3234
@property
3335
def remaining_requests(self):
@@ -83,3 +85,10 @@ def issues(self):
8385
:ref:`Issues service <Issues service>`
8486
"""
8587
return self._issues
88+
89+
@property
90+
def events(self):
91+
"""
92+
:ref:`Events service <Events service>`
93+
"""
94+
return self._events
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
from pygithub3.requests.base import Request, ValidationError
4+
from pygithub3.resources.events import Event
5+
6+
7+
class List(Request):
8+
9+
uri = 'events'
10+
resource = Event
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from . import Request
5+
from pygithub3.resources.events import NetworkEvent
6+
7+
8+
class List(Request):
9+
10+
uri = 'networks/{user}/{repo}/events'
11+
resource = NetworkEvent

pygithub3/requests/events/orgs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from . import Request
5+
from pygithub3.resources.events import OrgEvent
6+
7+
8+
class List(Request):
9+
10+
uri = 'orgs/{org}/events'
11+
resource = OrgEvent

pygithub3/requests/events/repos.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from . import Request
5+
from pygithub3.resources.events import RepoEvent
6+
7+
8+
class List(Request):
9+
10+
uri = 'repos/{user}/{repo}/events'
11+
resource = RepoEvent

pygithub3/requests/events/users.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from . import Request
5+
from pygithub3.resources.events import UserEvent, OrgEvent
6+
7+
8+
class List_received(Request):
9+
10+
uri = 'users/{user}/received_events'
11+
resource = UserEvent
12+
13+
14+
class List_received_public(Request):
15+
16+
uri = 'users/{user}/received_events/public'
17+
resource = UserEvent
18+
19+
20+
class List_performed(Request):
21+
22+
uri = 'users/{user}/events'
23+
resource = UserEvent
24+
25+
26+
class List_performed_public(Request):
27+
28+
uri = 'users/{user}/events/public'
29+
resource = UserEvent
30+
31+
32+
class List_org_events(Request):
33+
34+
uri = 'users/{user}/events/orgs/{org}'
35+
resource = OrgEvent

pygithub3/resources/events.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from .base import Resource
5+
from .users import User
6+
from .repos import Repo
7+
from .orgs import Org
8+
9+
10+
class Event(Resource):
11+
12+
_dates = ('created_at', )
13+
_maps = {'actor': User, 'repo': Repo, 'org': Org}
14+
15+
def __str__(self):
16+
return '<Event (%s)>' % getattr(self, 'type', '')
17+
18+
19+
class RepoEvent(Resource):
20+
21+
_dates = ('created_at', )
22+
_maps = {'actor': User, 'repo': Repo, 'org': Org}
23+
24+
def __str__(self):
25+
return '<Event (%s)>' % getattr(self, 'type', '')
26+
27+
28+
class NetworkEvent(Resource):
29+
30+
_dates = ('created_at', )
31+
_maps = {'actor': User, 'repo': Repo, 'org': Org}
32+
33+
def __str__(self):
34+
return '<Event (%s)>' % getattr(self, 'type', '')
35+
36+
37+
class OrgEvent(Resource):
38+
39+
_dates = ('created_at', )
40+
_maps = {'actor': User, 'repo': Repo, 'org': Org}
41+
42+
def __str__(self):
43+
return '<Event (%s)>' % getattr(self, 'type', '')
44+
45+
46+
class UserEvent(Resource):
47+
48+
_dates = ('created_at', )
49+
_maps = {'actor': User, 'repo': Repo, 'org': Org}
50+
51+
def __str__(self):
52+
return '<Event (%s)>' % getattr(self, 'type', '')
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- encoding: utf-8 -*-
2+
3+
from pygithub3.services.base import Service
4+
from .. issues import Events as IssueEvents
5+
from . networks import NetworkEvents
6+
from . orgs import OrgEvents
7+
from . repos import RepoEvents
8+
from . users import UserEvents
9+
10+
11+
class Events(Service):
12+
""" Consume `Events API <http://developer.github.com/v3/events>`_
13+
14+
The events API supports pagination, but with a fixed page size of 30; In
15+
addition, fetching up to ten pages is supported, for a total of 300 events.
16+
17+
"""
18+
19+
def __init__(self, **config):
20+
self._issues = IssueEvents(**config)
21+
self._networks = NetworkEvents(**config)
22+
self._orgs = OrgEvents(**config)
23+
self._repos = RepoEvents(**config)
24+
self._users = UserEvents(**config)
25+
super(Events, self).__init__(**config)
26+
27+
@property
28+
def issues(self):
29+
""" Events for Issues """
30+
return self._issues
31+
32+
@property
33+
def networks(self):
34+
""" Events for a Network of Repositories """
35+
return self._networks
36+
37+
@property
38+
def orgs(self):
39+
""" Events for an Organization """
40+
return self._orgs
41+
42+
@property
43+
def repos(self):
44+
""" Events for Repos """
45+
return self._repos
46+
47+
@property
48+
def users(self):
49+
""" Events for Users """
50+
return self._users
51+
52+
def list(self):
53+
""" List all public events.
54+
55+
:returns: A :doc:`result`
56+
57+
.. note::
58+
This method uses ``_get_normal_result`` which hits the API fetching
59+
maximum number of events (300 = 30/page * 10).
60+
61+
If there's a good way to tell ``smart.Method`` about the last page
62+
ahead of time, that may be a better way to proceed. Otherwise it
63+
tries to set that via ``_set_last_page_from`` which fails because
64+
that data is not in the returned header.
65+
66+
67+
"""
68+
request = self.request_builder('events.list')
69+
return self._get_normal_result(request, per_page=None)

0 commit comments

Comments
 (0)