def __init__(self, event): super(Event, self).__init__(event) from github3.users import User from github3.orgs import Organization #: :class:`User <github3.users.User>` object representing the actor. self.actor = User(event.get('actor')) if event.get('actor') else None #: datetime object representing when the event was created. self.created_at = self._strptime(event.get('created_at')) #: Unique id of the event self.id = event.get('id') #: List all possible types of Events self.org = None if event.get('org'): self.org = Organization(event.get('org')) #: Event type http://developer.github.com/v3/activity/events/types/ self.type = event.get('type') handler = _payload_handlers[self.type] #: Dictionary with the payload. Payload structure is defined by type_. # _type: http://developer.github.com/v3/events/types self.payload = handler(event.get('payload')) #: Return ``tuple(owner, repository_name)`` self.repo = event.get('repo') if self.repo is not None: self.repo = tuple(self.repo['name'].split('/')) #: Indicates whether the Event is public or not. self.public = event.get('public')
def _retrieve_existing_org_hook_or_none(self, organization: Organization, hook_name: str, webhook_url: str): ''' @raises github3.exceptions.NotFoundError in case of missing privileges to enumerate webhooks ''' def _webhook_set_by_us(org_hook: OrganizationHook, webhook_url: str): org_hook_url = urlparse(org_hook.config['url']) org_hook_query_key = parse_qs( org_hook_url.query).get(DEFAULT_ORG_HOOK_QUERY_KEY) if not org_hook_query_key: return False webhook_url = urlparse(webhook_url) if org_hook_url.path != webhook_url.path: return False return True hooks = filter(lambda org_hook: org_hook.name == hook_name, organization.hooks()) hooks = filter( lambda org_hook: _webhook_set_by_us(org_hook, webhook_url), hooks) hooks = list(hooks) if len(hooks) == 1: return hooks[0] elif len(hooks) == 0: return None raise RuntimeError('found two similar webhooks - what to do now?')
def organization(self, login): """Returns a Organization object for the login name :param str login: (required), login name of the org :returns: :class:`Organization <github3.orgs.Organization>` """ url = self._build_url('orgs', login) json = self._json(self._get(url), 200) return Organization(json, self) if json else None
def test_with_auth(self): if not self.auth: return # Try and do something only sigmavirus24 or other org members # should be able to do. As of now (26 Aug 2012) there are no other # org members. # Might as well avoid a call to the API, right? org = Organization(self.org.to_json(), self._g) try: expect(org.add_member('jcordasc', 'Collaborators')).is_True() expect(org.remove_member('jcordasc', 'Collaborators')).is_True() except github3.GitHubError: pass try: expect(org.add_repo(self.test_repo, 'Contributors')).is_True() expect(org.remove_repo(self.test_repo, 'Contributors')).is_True() except github3.GitHubError: pass try: repo = org.create_repo('test_repo_creation', 'testing') expect(repo).isinstance(Repository) repo.delete() except github3.GitHubError: pass try: expect(org.conceal_member(self.sigm)).is_True() expect(org.publicize_member(self.sigm)).is_True() except github3.GitHubError: pass try: team = org.create_team('New Team', permissions='admin') expect(team).isinstance(Team) team.delete() except github3.GitHubError: pass try: expect(org.edit(name='github3[dot]py')).is_True() expect(org.edit(name='github3.py')).is_True() except github3.GitHubError: pass try: teams = org.list_teams() self.expect_list_of_class(teams, Team) except github3.GitHubError: pass try: expect(org.team(190083)).isinstance(Team) except github3.GitHubError: pass
def test_with_auth(self): if not self.auth: return # Try and do something only sigmavirus24 or other org members # should be able to do. As of now (26 Aug 2012) there are no other # org members. # Might as well avoid a call to the API, right? org = Organization(self.org.to_json(), self._g) try: expect(org.add_member('gh3test', 'Collaborators')).is_True() expect(org.remove_member('gh3test')).is_True() except github3.GitHubError: pass try: repo = self.gh3py + '/' + self.test_repo expect(org.add_repo(repo, 'Contributors')).is_True() expect(org.remove_repo(repo, 'Contributors')).is_True() except github3.GitHubError: pass try: repo = org.create_repo('test_repo_creation', 'testing', team_id=190083) expect(repo).isinstance(Repository) repo.delete() except github3.GitHubError: pass try: expect(org.conceal_member(self.sigm)).is_True() expect(org.publicize_member(self.sigm)).is_True() except github3.GitHubError: pass try: team = org.create_team('New Team', permissions='admin') expect(team).isinstance(Team) team.delete() except github3.GitHubError: pass try: expect(org.edit(name='github3[dot]py')).is_True() expect(org.edit(name='github3.py')).is_True() except github3.GitHubError: pass try: teams = org.list_teams() expect(teams).list_of(Team) except github3.GitHubError: pass try: expect(next(org.iter_teams())).isinstance(Team) except github3.GitHubError: pass try: expect(org.team(190083)).isinstance(Team) except github3.GitHubError: pass try: expect(org.add_member(self.sigm, 'Foo')).is_False() except github3.GitHubError: pass try: expect(org.add_repo(self.test_repo, 'Foo')).is_False() except github3.GitHubError: pass try: co = org.company em = org.email loc = org.location name = org.name expect(org.edit()).is_False() expect(org.edit(None, 'github3.io', em, loc, name)).is_True() expect(org.edit(None, co, em, loc, name)).is_True() except github3.GitHubError: pass try: expect(org.remove_repo(self.test_repo, 'Foo')).isinstance(bool) except github3.GitHubError: pass