Share
Embed
Automating GitHub Workflow with Bots
GitHub provides a great platform for collaborating and maintaining open source projects.
Take it to the next level by creating custom GitHub bots.
By delegating some of the chores to the bots, project maintainers get to spend more time developing and collaborating with other contributors.
Learn how the Core Python team automated their workflow by building GitHub bots to help maintain one of the most popular open source projects, CPython.
Presented at Richmond Code and Coffee Pop-Up.
Mariatta
February 28, 2018
Transcript
42 slides
-
Automating GitHub Workflow with Bots @mariatta Code & Coffee Pop-Up
Richmond Automating GitHub Workflow with Bots @mariatta -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Hi! ! @mariatta Platform Engineer Python Core Developer -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Python github.com/python/cpython 5000+ pull requests 500+ contributors, 30 core devs -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Boring chores -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta For every pull request … CLA signed? Issue number included? News entry? Tests passed? Ready for review? Backport needed? -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta For every pull request … CLA signed? Issue number included? News entry? Tests passed? Ready for review? Backport needed? -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Meet CPython’s GitHub Bots https://github.com/the-knights-who-say-ni https://github.com/python/the-knights-who-say-ni the-knights-who-say-ni https://github.com/bedevere-bot https://github.com/python/bedevere bedevere https://github.com/miss-islington https://github.com/python/miss-islington miss-islington -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta the-knights-who-say-ni -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta bedevere -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta bedevere -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta bedevere -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta bedevere -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta bedevere -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta miss-islington ⛏ -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta miss-islington ⛏ -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta miss-islington ⛏ -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Cherry-picking $ git fetch upstream $ git checkout -b backport-3384d38d-3.7 upstream/3.7 $ git cherry-pick -x 3384d38d51a2c3450e742175db5d6d638fa5d2eb $ git push origin backport-3384d38d-3.7 $ git checkout master $ git branch -D backport-3384d38d-3.7 -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta miss-islington ⛏ -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta miss-islington ⛏ -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Building the GitHub Bot -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta GitHub Webhooks https://developer.github.com/webhooks/ Events pull_request ("opened", "closed", "labeled") status ("pending", "success", "failure") pull_request_review ("submitted", "dismissed") GitHub Webservice -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta GitHub REST API v3 https://developer.github.com/v3/ REST API Create a pull request Merge a pull request Apply label to pull request GitHub Webservice Comment on a pull request -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta The webservice Python 3.6+ pip install aiohttp http://aiohttp.readthedocs.io/en/stable/ https://github.com/aio-libs/aiohttp aiohttp - Asyncio HTTP Server / Client by Andrew Svetlov -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta The webservice Python 3.6+ pip install gidgethub https://gidgethub.readthedocs.io/en/stable/ https://github.com/brettcannon/gidgethub gidgethub - Async library for calling GitHub’s API by Brett Cannon -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Receive the webhook @router.register("pull_request_review", action="submitted") async def pr_reviewed(event, gh, *args, **kwargs): reviewer = event.data["review"]["user"]["login"] approved = event.data["review"]["state"] == "approved" if approved and await util.is_core_dev(gh, reviewer): ... # merge the PR, leave a comment to say thanks Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Receive the webhook @router.register("pull_request_review", action="submitted") async def pr_reviewed(event, gh, *args, **kwargs): reviewer = event.data["review"]["user"]["login"] approved = event.data["review"]["state"] == "approved" if approved and await util.is_core_dev(gh, reviewer): ... # merge the PR, leave a comment to say thanks Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Receive the webhook @router.register("pull_request_review", action="submitted") async def pr_reviewed(event, gh, *args, **kwargs): reviewer = event.data["review"]["user"]["login"] approved = event.data["review"]["state"] == "approved" if approved and await util.is_core_dev(gh, reviewer): ... # merge the PR, leave a comment to say thanks Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Receive the webhook @router.register("pull_request_review", action="submitted") async def pr_reviewed(event, gh, *args, **kwargs): reviewer = event.data["review"]["user"]["login"] approved = event.data["review"]["state"] == "approved" if approved and await util.is_core_dev(gh, reviewer): ... # merge the PR, leave a comment to say thanks Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Receive the webhook @router.register("pull_request_review", action="submitted") async def pr_reviewed(event, gh, *args, **kwargs): reviewer = event.data["review"]["user"]["login"] approved = event.data["review"]["state"] == "approved" if approved and await util.is_core_dev(gh, reviewer): ... # merge the PR, leave a comment to say thanks Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Receive the webhook @router.register("pull_request_review", action="submitted") async def pr_reviewed(event, gh, *args, **kwargs): reviewer = event.data["review"]["user"]["login"] approved = event.data["review"]["state"] == "approved" if approved and await util.is_core_dev(gh, reviewer): ... # merge the PR, leave a comment to say thanks Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Receive the webhook @router.register("pull_request_review", action="submitted") async def pr_reviewed(event, gh, *args, **kwargs): reviewer = event.data["review"]["user"]["login"] approved = event.data["review"]["state"] == "approved" if approved and await util.is_core_dev(gh, reviewer): ... # merge the PR, leave a comment to say thanks Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Say thanks? Source: https://developer.github.com/v3/issues/comments/#create-a-comment -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Say thanks pr_number = 5590 data = {"body": "Thanks, @Mariatta!"} await gh.post(f"/repos/python/cpython/issues/{pr_number}/comments", data=data) Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Say thanks pr_number = 5590 data = {"body": "Thanks, @Mariatta!"} await gh.post(f"/repos/python/cpython/issues/{pr_number}/comments", data=data) Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Merge the Pull Request? Source: https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Merge the Pull Request pr_number = 5590 await gh.put(f"/repos/python/cpython/pulls/{pr_number}/merge", data={"commit_title": "Fix typo in f-strings docs", "commit_message": "Shorten the comment to: 'using integer format specifier'"), "sha": sha, "merge_method": "squash" } ) Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Merge the Pull Request pr_number = 5590 await gh.put(f"/repos/python/cpython/pulls/{pr_number}/merge", data={"commit_title": "Fix typo in f-strings docs", "commit_message": "Shorten the comment to: 'using integer format specifier'"), "sha": sha, "merge_method": "squash" } ) Source: https://github.com/python/miss-islington/blob/master/miss_islington/status_change.py -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Build your own GitHub Bot -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Open Source https://github.com/the-knights-who-say-ni https://github.com/python/the-knights-who-say-ni the-knights-who-say-ni https://github.com/bedevere-bot https://github.com/python/bedevere bedevere https://github.com/miss-islington https://github.com/python/miss-islington miss-islington -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta Dependencies http://aiohttp.readthedocs.io/en/stable/ https://github.com/aio-libs/aiohttp aiohttp - Asyncio HTTP Server / Client https://gidgethub.readthedocs.io/en/stable/ https://github.com/brettcannon/gidgethub gidgethub - Async library for calling GitHub’s API by Andrew Svetlov by Brett Cannon -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta GitHub API docs https://developer.github.com/webhooks/ https://developer.github.com/v3/ -
Code & Coffee Pop-Up Richmond Automating GitHub Workflow with
Bots @mariatta @mariatta Thanks! [email protected] mariatta.ca