How to use gidgethub - 10 common examples

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 / bedevere / tests / test_follow_up.py View on Github external
"action": "closed",
        "pull_request": {
            "number": 5326,
            "merged": False,
            "statuses_url": "https://api.github.com/blah/blah/git-sha",
            "title": "No issue in title",
            "issue_url": "issue URL",
            "merge_commit_sha": None,
            "comments_url": "https://api.github.com/repos/python/cpython/pulls/5326/comments",
        },
        "repository": {
            "commits_url": "https://api.github.com/repos/python/cpython/commits{/sha}"
        }
    }

    event = sansio.Event(data, event="pull_request", delivery_id="12345")
    gh = FakeGH()
    await follow_up.router.dispatch(event, gh)
    post_data = gh.post_data
    assert post_data is None
github python / miss-islington / tests / test_backport_pr.py View on Github external
async def test_labeled_on_merged_pr_no_backport_label():
    data = {
        "action": "labeled",
        "pull_request": {
            "merged": True,
            "number": 1,
            "merged_by": {"login": "Mariatta"},
            "user": {"login": "Mariatta"},
            "merge_commit_sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9",
        },
        "repository": {
            "issues_url": "https://api.github.com/repos/python/cpython/issues{/number}"
        },
        "label": {"name": "CLA signed"},
    }
    event = sansio.Event(data, event="pull_request", delivery_id="1")

    gh = FakeGH()
    await backport_pr.router.dispatch(event, gh)
    assert not hasattr(gh, "post_data")
    assert not hasattr(gh, "post_url")
github python / bedevere / tests / test_close_pr.py View on Github external
"issue_url": "https://api.github.com/org/repo/issues/123",
            "url": "https://api.github.com/org/repo/pulls/123",
            "head": {
                "label": "python:3.6"
            },
            "base": {
                "label": "python:master"
            }
        },
    }
    pr_data = {
        "labels": [
            {"name": "non-trivial"},
        ]
    }
    event = sansio.Event(data, event="pull_request", delivery_id="12345")
    gh = FakeGH(getitem=pr_data)
    await close_pr.router.dispatch(event, gh)
    patch_data = gh.patch_data
    assert patch_data["state"] == "closed"

    assert len(gh.post_url) == 2
    assert gh.post_url[0] == 'https://api.github.com/org/repo/issues/123/labels'
    assert gh.post_data[0] == ['invalid']
    assert gh.post_url[1] == 'https://api.github.com/org/repo/issues/123/comments'
    assert gh.post_data[1] == {'body': close_pr.INVALID_PR_COMMENT}
github python / miss-islington / tests / test_delete_branch.py View on Github external
async def test_branch_deleted_when_pr_merged():
    data = {
        "action": "closed",
        "pull_request": {
            "number": 5722,
            "user": {"login": "miss-islington"},
            "merged": True,
            "merged_by": {"login": "miss-islington"},
            "head": {"ref": "backport-17ab8f0-3.7"},
        },
    }
    event = sansio.Event(data, event="pull_request", delivery_id="1")

    gh = FakeGH()
    await delete_branch.router.dispatch(event, gh)
    assert gh.post_data is None  # does not leave a comment
    assert (
        gh.delete_url
        == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}"
    )
github python / bedevere / tests / test_follow_up.py View on Github external
async def getitem(self, url, url_vars={}):
        self.getitem_url = sansio.format_url(url, url_vars)
        return self._getitem_return[self.getitem_url]
github python / miss-islington / tests / test_backport_pr.py View on Github external
async def getitem(self, url, url_vars={}):
        self.getitem_url = sansio.format_url(url, url_vars)
        return self._getitem_return[self.getitem_url]
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