Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mariatta - Don't be a robot, build the bot

Mariatta - Don't be a robot, build the bot

Managing a large open source project like CPython is no easy task. Learn how the Python core team automated their GitHub workflow with bots, making it easier for maintainers and contributors to collaborate together. Even if you’re not managing a large project, you can still build your own bot! Hear some ideas on what you can automate on GitHub and personalize your bot based on your own workflow. All you need is Python. Don’t be a robot; build the bot.

https://us.pycon.org/2019/schedule/presentation/218/

PyCon 2019

May 03, 2019
Tweet

More Decks by PyCon 2019

Other Decks in Programming

Transcript

  1. Python Core Developer Backend Engineer @mariatta mariatta.ca #IceCreamSelfie WHO AM

    I? Mariatta ! PyCon US 2019
 @mariatta https://zapier.com/jobs/ (Booth #713)
  2. Problem: We’re outnumbered Source: Stephane Wirtel, CPython loves your pull

    request https://speakerdeck.com/matrixise/ python-loves-your-contributions PyCon US 2019
 @mariatta
  3. 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
  4. 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
  5. 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
  6. • 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
  7. SCENARIO: BUG IN 3.6 Bug in f-strings 3.8 3.7 3.8

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

    3.7 PyCon US 2019
 @mariatta
  9. 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
  10. 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
  11. 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
  12. PR merged event (webhook) Open pull request (REST API) Run

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

    cherry_picker.py Clone CPython repo PyCon US 2019
 @mariatta
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. RHYMES WITH HAPPIER! OOOS bot Out of open source auto

    reply bot PyCon US 2019
 @mariatta
  28. 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
  29. 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/
  30. 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
  31. 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!!