How to use the gidgethub.sansio.Event function in gidgethub

To help you get started, we’ve selected a few gidgethub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python / miss-islington / tests / test_status_change.py View on Github external
{"name": "awaiting merge"},
                {"name": AUTOMERGE_LABEL},
                {"name": "CLA signed"},
            ],
            "head": {"sha": sha},
            "number": 5547,
            "title": "bpo-32720: Fixed the replacement field grammar documentation.",
            "body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
            "url": "https://api.github.com/repos/python/cpython/pulls/5547",
            "issue_url": "https://api.github.com/repos/python/cpython/issues/5547",
        },
        "sender": {"login": "Mariatta"},
        "label": {"name": AUTOMERGE_LABEL},
    }

    event = sansio.Event(data, event="pull_request", delivery_id="1")

    getitem = {
        f"/repos/python/cpython/commits/{sha}/status": {
            "state": "success",
            "statuses": [
                {
                    "state": "success",
                    "description": "Issue report skipped",
                    "context": "bedevere/issue-number",
                },
                {
                    "state": "success",
                    "description": "The Travis CI build passed",
                    "target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification",
                    "context": "continuous-integration/travis-ci/pr",
                },
github python / miss-islington / tests / test_backport_pr.py View on Github external
async def test_unmerged_pr_is_ignored():
    data = {"action": "closed", "pull_request": {"merged": False}}
    event = sansio.Event(data, event="pull_request", delivery_id="1")
    gh = FakeGH()
    await backport_pr.router.dispatch(event, gh)
    assert gh.getitem_url is None
github python / bedevere / tests / test_backport.py View on Github external
data = {
        'action': action,
        'number': 2248,
        'pull_request': {
            'title': title,
            'body': '',
            'issue_url': 'https://api.github.com/issue/2248',
            'base': {
                'ref': 'master',
            },
            'statuses_url': 'https://api.github.com/repos/python/cpython/statuses/somehash',
        },
        'repository': {'issues_url': 'https://api.github.com/issue{/number}'},
        'changes': {'title': title},
    }
    event = sansio.Event(data, event='pull_request',
                        delivery_id='1')
    getitem = {
        'https://api.github.com/issue/1234':
            {'labels': [{'name': 'CLA signed'}]},
        'https://api.github.com/issue/2248': {},
    }
    gh = FakeGH(getitem=getitem)
    await backport.router.dispatch(event, gh)
    assert len(gh.post_) == 0
github python / bedevere / tests / test_bpo.py View on Github external
async def test_set_comment_body_already_hyperlinked_bpo(event, action):
    data = {
        "action": action,
        "comment": {
            "url": "https://api.github.com/repos/blah/blah/issues/comments/123456",
            "body": ("bpo-123"
                    "[bpo-123](https://bugs.python.org/issue123)"
                    "[something about bpo-123](https://bugs.python.org/issue123)"
                    "<a href="https://bugs.python.org/issue123">bpo-123</a>"
                   )
        }
    }

    event = sansio.Event(data, event=event, delivery_id="123123")
    gh = FakeGH()
    await bpo.router.dispatch(event, gh)
    body_data = gh.patch_data
    assert body_data["body"].count("[bpo-123](https://bugs.python.org/issue123)") == 2
    assert body_data["body"].count("[something about bpo-123](https://bugs.python.org/issue123)") == 1
    assert "123456" in gh.patch_url
github python / bedevere / tests / test_news.py View on Github external
async def test_deleting_label():
    gh = FakeGH()
    event_data = {
        "action": "unlabeled",
        "pull_request": {
            "statuses_url": "https://api.github.com/blah/blah/git-sha",
            "title": "An easy fix",
        },
    }
    event = sansio.Event(event_data, event='pull_request', delivery_id='1')
    await news.router.dispatch(event, gh)
    assert gh.post_data is None
github python / bedevere / tests / test_backport.py View on Github external
'action': 'opened',
        'number': 2248,
        'pull_request': {
            'title': '[3.6] Backport this (GH-1234)',
            'body': 'N/A',
            'issue_url': 'https://api.github.com/issue/2248',
            'base': {
                'ref': '3.6',
            },
            'statuses_url': 'https://api.github.com/repos/python/cpython/statuses/somehash',
        },
        'repository': {
            'issues_url': 'https://api.github.com/issue{/number}',
        },
    }
    event = sansio.Event(event_data, event='pull_request',
                        delivery_id='1')
    labels_to_test = "CLA signed", "skip news", "type-enhancement", "sprint"
    getitem_data = {
        'https://api.github.com/issue/1234': {
            'labels': [{'name': label} for label in labels_to_test],
            'labels_url': 'https://api.github.com/issue/1234/labels{/name}',
            'comments_url': 'https://api.github.com/issue/1234/comments',
        },
        'https://api.github.com/issue/2248': {
            'labels_url': 'https://api.github.com/issue/1234/labels{/name}',
        },
    }
    gh = FakeGH(getitem=getitem_data)
    await backport.router.dispatch(event, gh)
    post = gh.post_[0]
    assert post[0] == 'https://api.github.com/issue/1234/labels'
github bioconda / bioconda-utils / bioconda_utils / githubhandler.py View on Github external
"""GitHubHandler using Aiohttp for HTTP requests

    Arguments:
      session: Aiohttp Client Session object
      requester: Identify self (e.g. user agent)
    """
    def create_api_object(self, session: aiohttp.ClientSession,
                          requester: str, *args, **kwargs) -> None:
        self.api = gidgethub.aiohttp.GitHubAPI(
            session, requester, oauth_token=self.token,
            cache=cachetools.LRUCache(maxsize=500)
        )
        self.session = session


class Event(gidgethub.sansio.Event):
    """Adds **get(path)** method to Github Webhook event"""
    def get(self, path: str, altvalue=KeyError) -> str:
        """Get subkeys from even data using slash separated path"""
        data = self.data
        try:
            for item in path.split("/"):
                data = data[item]
        except (KeyError, TypeError):
            if altvalue == KeyError:
                raise KeyError(f"No '{path}' in event type {self.event}") from None
            else:
                return altvalue
        return data


class GitHubAppHandler:
github sanitizers / octomachinery / octomachinery / github / models / events.py View on Github external
def to_gidgethub(self) -> _GidgetHubEvent:
        """Produce GidgetHub Event from self."""
        return _GidgetHubEvent(
            data=self.payload,
            event=self.name,
            delivery_id=str(uuid.uuid4()),
        )