Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with Bots
 @mariatta Boring chores

Slide 5

Slide 5 text

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?

Slide 6

Slide 6 text

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?

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with Bots
 @mariatta Building the GitHub Bot

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with Bots
 @mariatta Say thanks? Source: https://developer.github.com/v3/issues/comments/#create-a-comment

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with Bots
 @mariatta Build your own GitHub Bot

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Code & Coffee Pop-Up Richmond 
 Automating GitHub Workflow with Bots
 @mariatta @mariatta Thanks! [email protected] mariatta.ca