Slide 1

Slide 1 text

Don’t Be a Robot; Build the Bot @mariatta

Slide 2

Slide 2 text

Python Core Developer Backend Engineer @mariatta mariatta.ca #IceCreamSelfie WHO AM I? Mariatta ! PyCon US 2019
 @mariatta https://zapier.com/jobs/ (Booth #713)

Slide 3

Slide 3 text

Problems? CORE PYTHON DEVELOPMENT PyCon US 2019
 @mariatta

Slide 4

Slide 4 text

Problem: We’re outnumbered Source: Stephane Wirtel, CPython loves your pull request https://speakerdeck.com/matrixise/ python-loves-your-contributions PyCon US 2019
 @mariatta

Slide 5

Slide 5 text

Problem: Complicated Workflow Bug or feature? CLA signed? Tests passed? Needs an issue? Needs news entry? News entry added? Needs backport? How? Who? When? First time contributor? Commit message? PyCon US 2019
 @mariatta

Slide 6

Slide 6 text

Problem: Complicated Workflow Bug or feature? CLA signed? Tests passed? Needs an issue? Needs news entry? News entry added? Needs backport? How? Who? When? First time contributor? Commit message? PyCon US 2019
 @mariatta

Slide 7

Slide 7 text

Problem: Complicated Workflow Bug or feature? CLA signed? Tests passed? Needs an issue? Needs news entry? News entry added? Needs backport? How? Who? When? First time contributor? Commit message? PyCon US 2019
 @mariatta

Slide 8

Slide 8 text

Backport? PyCon US 2019
 @mariatta

Slide 9

Slide 9 text

Backport? Applying changes from newer version to older version PyCon US 2019
 @mariatta

Slide 10

Slide 10 text

• master (3.8.0b1, due May 27, 2019) • 3.7 (3.7.4, due June 2019) • 2.7 (EOL, January 2020) Current maintained versions PyCon US 2019
 @mariatta

Slide 11

Slide 11 text

SCENARIO: BUG IN 3.6 Bug in f-strings PyCon US 2019
 @mariatta

Slide 12

Slide 12 text

SCENARIO: BUG IN 3.6 Bug in f-strings 3.6 PyCon US 2019
 @mariatta

Slide 13

Slide 13 text

SCENARIO: BUG IN 3.6 Bug in f-strings 3.6 3.6 PyCon US 2019
 @mariatta

Slide 14

Slide 14 text

SCENARIO: BUG IN 3.6 3.6 Bug in f-strings 3.6 PyCon US 2019
 @mariatta

Slide 15

Slide 15 text

SCENARIO: BUG IN 3.6 Bug in f-strings PyCon US 2019
 @mariatta

Slide 16

Slide 16 text

SCENARIO: BUG IN 3.6 Bug in f-strings 3.7 3.8 PyCon US 2019
 @mariatta

Slide 17

Slide 17 text

SCENARIO: BUG IN 3.6 Bug in f-strings 3.8 3.7 3.8 PyCon US 2019
 @mariatta

Slide 18

Slide 18 text

SCENARIO: BUG IN 3.6 Bug in f-strings 3.8 3.7 3.8 PyCon US 2019
 @mariatta

Slide 19

Slide 19 text

SCENARIO: BUG IN 3.6 Bug in f-strings 3.8 3.7 3.8 3.7 PyCon US 2019
 @mariatta

Slide 20

Slide 20 text

SCENARIO: BUG IN 3.6 Bug in f-strings 3.8 3.7 3.8 3.7 PyCon US 2019
 @mariatta

Slide 21

Slide 21 text

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 3.7 PyCon US 2019
 @mariatta

Slide 22

Slide 22 text

CHERRY_PICKER.PY $ pip install cherry_picker PyCon US 2019
 @mariatta

Slide 23

Slide 23 text

CHERRY_PICKER.PY $ pip install cherry_picker $ cherry_picker 3384d38d51a2c3450e742175db5d6d638fa5d2eb 3.7 3.6 PyCon US 2019
 @mariatta

Slide 24

Slide 24 text

Problems: PyCon US 2019
 @mariatta

Slide 25

Slide 25 text

Problems: PyCon US 2019
 @mariatta

Slide 26

Slide 26 text

Problems: PyCon US 2019
 @mariatta

Slide 27

Slide 27 text

Problems: PyCon US 2019
 @mariatta

Slide 28

Slide 28 text

Problems: PyCon US 2019
 @mariatta

Slide 29

Slide 29 text

DON’T BE A ROBOT Build the Bot PyCon US 2019
 @mariatta

Slide 30

Slide 30 text

GITHUB WEBHOOKS Pull request (opened, closed, labeled) Status (pending, success, failure) Pull request review (submitted, dismissed) … Events GitHub Webservice Docs: https://developer.github.com/webhooks PyCon US 2019
 @mariatta

Slide 31

Slide 31 text

GITHUB APIS Create a pull request Merge a pull request Comment on a pull request Apply labels to pull request … APIs Webservice GitHub Docs: https://developer.github.com/v3 PyCon US 2019
 @mariatta

Slide 32

Slide 32 text

PR merged event (webhook) Open pull request (REST API) Run cherry_picker.py PyCon US 2019
 @mariatta

Slide 33

Slide 33 text

PR merged event (webhook) Open pull request (REST API) Run cherry_picker.py Clone CPython repo PyCon US 2019
 @mariatta

Slide 34

Slide 34 text

PR merged event (webhook) Open pull request (REST API) Run cherry_picker.py Clone CPython repo 2 minutes 12-15 seconds PyCon US 2019
 @mariatta

Slide 35

Slide 35 text

PR merged event (webhook) Open pull request (REST API) Run cherry_picker.py Clone CPython repo 2 minutes 12-15 seconds timesout after 30 seconds PyCon US 2019
 @mariatta

Slide 36

Slide 36 text

PR merged event (webhook) Open pull request (REST API) Run cherry_picker.py Clone CPython repo 2 minutes 12-15 seconds timesout after 30 seconds PyCon US 2019
 @mariatta

Slide 37

Slide 37 text

PR merged event (webhook) Open pull request (REST API) Run cherry_picker.py Clone CPython repo Webservice (aiohttp) Background task (celery) Start a task PyCon US 2019
 @mariatta

Slide 38

Slide 38 text

PR merged event (webhook) Open pull request (REST API) Run cherry_picker.py Clone CPython repo Webservice (aiohttp) Background task (celery) miss-islington Start a task PyCon US 2019
 @mariatta

Slide 39

Slide 39 text

miss-islington • open-source https://github.com/python/miss-islington • Python 3.6 (because f-strings) • aiohttp: async web server/client • gidgethub: async Python library for GitHub PyCon US 2019
 @mariatta

Slide 40

Slide 40 text

miss-islington @router.register("pull_request", action="closed") async def backport_pr(event, gh, *args, **kwargs): if event.data["pull_request"]["merged"]: commit_hash = event.data["pull_request"]["merge_commit_sha"] ... branches = [ label["name"].split()[-1] for label in pr_labels if label["name"].startswith("needs backport to”) ] for branch in branches: ... tasks.backport_task.delay(commit_hash, branch, ...) source: https://github.com/python/miss-islington/blob/master/miss_islington/backport_pr.py PyCon US 2019
 @mariatta

Slide 41

Slide 41 text

First PR https://twitter.com/ChristianHeimes/status/905218281937575936 PyCon US 2019
 @mariatta

Slide 42

Slide 42 text

Problems: PyCon US 2019
 @mariatta

Slide 43

Slide 43 text

Problems: ✅ ✅ ✅ ✅ PyCon US 2019
 @mariatta

Slide 44

Slide 44 text

Problems: ✅ ✅ ✅ ✅ PyCon US 2019
 @mariatta

Slide 45

Slide 45 text

Problem: Complicated Workflow Bug or feature? CLA signed? Tests passed? Needs an issue? Needs news entry? News entry added? Needs backport? How? Who? When? First time contributor? Commit message? PyCon US 2019
 @mariatta

Slide 46

Slide 46 text

PyCon US 2019
 @mariatta

Slide 47

Slide 47 text

PyCon US 2019
 @mariatta

Slide 48

Slide 48 text

PyCon US 2019
 @mariatta

Slide 49

Slide 49 text

PR status event (webhook) Get the combined status for a ref (REST API) Post a comment in PR (REST API) Search PR containing commit (REST API) PyCon US 2019
 @mariatta 1 (status of a Git commit changes) 2 3 4 2. https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref 1. https://developer.github.com/v3/activity/events/types/#statusevent 4. https://developer.github.com/v3/issues/comments/#create-a-comment 3. https://developer.github.com/v3/search/#search-issues

Slide 50

Slide 50 text

PyCon US 2019
 @mariatta

Slide 51

Slide 51 text

✅ ✅ ✅ ✅ ✅ PyCon US 2019
 @mariatta

Slide 52

Slide 52 text

Problem: Complicated Workflow Bug or feature? CLA signed? Tests passed? Needs an issue? Needs news entry? News entry added? Needs backport? How? Who? When? First time contributor? Commit message? PyCon US 2019
 @mariatta

Slide 53

Slide 53 text

https://mail.python.org/pipermail/python-committers/2018-January/005174.html PyCon US 2019
 @mariatta

Slide 54

Slide 54 text

Merge the PR 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" } ) PyCon US 2019
 @mariatta

Slide 55

Slide 55 text

Merge the PR 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" } ) PyCon US 2019
 @mariatta

Slide 56

Slide 56 text

PyCon US 2019
 @mariatta

Slide 57

Slide 57 text

PyCon US 2019
 @mariatta

Slide 58

Slide 58 text

PyCon US 2019
 @mariatta

Slide 59

Slide 59 text

Don’t Be a Robot BUILD THE BOT PyCon US 2019
 @mariatta

Slide 60

Slide 60 text

black-out Bot that formats code with black PyCon US 2019
 @mariatta

Slide 61

Slide 61 text

Close all PRs PyCon US 2019
 @mariatta

Slide 62

Slide 62 text

Close all PRs PR opened/reopened event Close pull request PyCon US 2019
 @mariatta

Slide 63

Slide 63 text

Close all PRs PR opened/reopened event Close pull request @router.register("pull_request", action="opened") @router.register("pull_request", action="reopened") async def close_pr(event, gh, *args, **kwargs): await gh.patch(event.data["pull_request"]["url"], data= {"state": "closed"} ) Source: https://github.com/Mariatta/close-all-pr/blob/master/close-all-pr/close_pr.py PyCon US 2019
 @mariatta

Slide 64

Slide 64 text

OOOS bot Out of open source auto reply bot PyCon US 2019
 @mariatta

Slide 65

Slide 65 text

RHYMES WITH HAPPIER! OOOS bot Out of open source auto reply bot PyCon US 2019
 @mariatta

Slide 66

Slide 66 text

pylabels GitHub bot for the labels package (a collaboration with Raphael Pierzina) labels: CLI app to manage GitHub issue labels https://github.com/hackebrot/labels PyCon US 2019
 @mariatta $ pip install labels

Slide 67

Slide 67 text

Don’t Be a Robot; Build the Bot https://github-bot-tutorial.readthedocs.io/en/latest/ PyCon US 2019
 @mariatta https://tutorial.octomachinery.dev/en/latest/

Slide 68

Slide 68 text

PyCon US 2019
 @mariatta https://discuss.python.org/t/can-we-request-grant-from-the-psf-for-cloud-hosting-like-heroku/834

Slide 69

Slide 69 text

PyCon US 2019
 @mariatta GitHub bots are one honking great idea — let’s do more of those! Open Space, Sunday May 5th 11 AM Room 20

Slide 70

Slide 70 text

Contact [email protected]
 Follow on twitter @mariatta PyCon US 2019
 @mariatta GitHub bots are one honking great idea — let’s do more of those! Room 20 Open Space, Sunday May 5th 11 AM THANK YOU!!