Automating GitHub Workflow with Bots

6b6e72d297aa0270654a0d4575f1287e?s=47 Mariatta
February 28, 2018

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.

6b6e72d297aa0270654a0d4575f1287e?s=128

Mariatta

February 28, 2018
Tweet

Transcript

  1. Automating GitHub Workflow with Bots @mariatta Code & Coffee Pop-Up

    Richmond 
 Automating GitHub Workflow with Bots
 @mariatta
  2. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta Hi! ! @mariatta Platform Engineer Python Core Developer
  3. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta Python github.com/python/cpython 5000+ pull requests 500+ contributors, 30 core devs
  4. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta Boring chores
  5. 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?
  6. 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?
  7. 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
  8. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta the-knights-who-say-ni
  9. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta bedevere
  10. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta bedevere
  11. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta bedevere
  12. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta bedevere
  13. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta bedevere
  14. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta miss-islington ⛏
  15. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta miss-islington ⛏
  16. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta miss-islington ⛏
  17. 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
  18. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta miss-islington ⛏
  19. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta miss-islington ⛏
  20. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta Building the GitHub Bot
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta Say thanks? Source: https://developer.github.com/v3/issues/comments/#create-a-comment
  33. 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
  34. 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
  35. 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
  36. 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
  37. 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
  38. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta Build your own GitHub Bot
  39. 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
  40. 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
  41. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta GitHub API docs https://developer.github.com/webhooks/ https://developer.github.com/v3/
  42. Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with

    Bots
 @mariatta @mariatta Thanks! mariatta@python.org mariatta.ca