Successfully reported this slideshow.

Code reviews vs Pull requests

6

Share

Loading in …3
×
1 of 112
1 of 112

Code reviews vs Pull requests

6

Share

Download to read offline

@kannonboy's JavaOne 2016 presentation "Code reviews vs Pull requests"

Many styles and processes are available for code review. Which one is suitable for your team? Do you use Git, Subversion, or something more exotic? Do you prefer to review code precommit or via a pull request? Do you favor a feature branching, forking, or Gerrit-style workflow? This session breaks down the various popular options adopted by professional teams. It investigates pull requests (popularized by Bitbucket and GitHub), Gerrit’s specialized workflow, and other postcommit and precommit review systems, discussing the pros and cons of each. Finally, it shows the battle-hardened review processes used by Atlassian’s development teams, refined over tens of thousands of code reviews and pull requests and across countless retrospectives.

@kannonboy's JavaOne 2016 presentation "Code reviews vs Pull requests"

Many styles and processes are available for code review. Which one is suitable for your team? Do you use Git, Subversion, or something more exotic? Do you prefer to review code precommit or via a pull request? Do you favor a feature branching, forking, or Gerrit-style workflow? This session breaks down the various popular options adopted by professional teams. It investigates pull requests (popularized by Bitbucket and GitHub), Gerrit’s specialized workflow, and other postcommit and precommit review systems, discussing the pros and cons of each. Finally, it shows the battle-hardened review processes used by Atlassian’s development teams, refined over tens of thousands of code reviews and pull requests and across countless retrospectives.

More Related Content

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Code reviews vs Pull requests

  1. 1. TIM PETTERSEN • SENIOR DEVELOPER • ATLASSIAN • @KANNONBOY Code review vs Pull requests
  2. 2. @kannonboy Code review at Atlassian 2006 2007 Atlassian acquires Cenqua, starts using Crucible @kannonboy
  3. 3. @kannonboy 2006 2007 Atlassian acquires Cenqua, starts using Crucible Atlassian acquires @kannonboy
  4. 4. @kannonboy 2007 Cenqua, starts using Crucible 2010 Atlassian acquires Bitbucket 2011 Work starts on “Caviar” ! @kannonboy
  5. 5. @kannonboy 2010 Atlassian acquires Bitbucket 2011 Work starts on “Caviar” 2012 Stash 1.0 ships ! @kannonboy
  6. 6. @kannonboy 2011 Work starts on “Caviar” 2012 Stash 1.0 ships ! Stash 2.0 ships with pull requests Unread status @kannonboy
  7. 7. @kannonboy 2012 Stash 1.0 ships Stash 2.0 ships with pull requests Merge checks Comment drift Unread status Conflict markers Build status integration @kannonboy
  8. 8. @kannonboy Stash renamed to Bitbucket Server2015 Merge checks Conflict markers Build status integration Reviewer suggestions Branch permissions Comment likes Enhanced branch permissions Iterative review Merge strategies Reviewer statuses @kannonboy
  9. 9. @kannonboy Bitbucket Server2015 Comment likes Enhanced branch permissions Iterative review Merge strategies Reviewer statuses Today @kannonboy
  10. 10. @kannonboy TYPES OF REVIEW YOU NEED CODE REVIEW CODE REVIEW @ ATLASSIAN TIPS FOR TEAMS Agenda
  11. 11. Automated tests @kannonboy
  12. 12. Automated tests @kannonboy
  13. 13. human judgement needed ? “what-evs” bad API decision O(n!) algorithm technical debt Automated tests @kannonboy
  14. 14. Code Review Photo: Yogi (Flickr) @kannonboy
  15. 15. Better Code Shared Knowledge Team Ownership @kannonboy
  16. 16. G = 1 R+1 Developer guilt @kannonboy
  17. 17. Team Ownership @kannonboy
  18. 18. Team Ownership @kannonboy
  19. 19. Better Code Shared Knowledge Team Ownership @kannonboy
  20. 20. Code reviews take negative time @kannonboy
  21. 21. Reviews and releases 10 20 30 40 Daily Weekly Monthly Quarterly Yearly Code Review No Code Review Source: Atlassian Git Survey 2013 @kannonboy
  22. 22. Types of code review @kannonboy
  23. 23. Pull requests Code review Post-commit review Pre-commit review master for/master Staging area @kannonboy
  24. 24. Pre-commit review master @kannonboy
  25. 25. Pre-commit review dev $project-dev@example.com master maintainer @kannonboy
  26. 26. // flat fees and taxes final float customsFee = 5.5f; final float immigrationFee = 7f; final float federalTransportTax = .025f; public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; fare *= return fare; } AirfareCalculator.java federalTransportTax; @kannonboy
  27. 27. // flat fees and taxes final float customsFee = 5.5f; final float immigrationFee = 7f; final float federalTransportTax = .025f; public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; fare *= return fare; } (1 + ) AirfareCalculator.java federalTransportTax ; @kannonboy
  28. 28. Pre-commit review From: Tim Pettersen <tim@atlassian.com> Date: Mon, 12 Sep 2016 10:24:10 +1000 Subject: [PATCH] Calculate federal transport tax correctly --- a/com/atlassian/airfare/AirfareCalculator.java +++ b/com/atlassian/airfare/AirfareCalculator.java @@ -10,7 +10,7 @@ public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; - fare *= federalTransportTax; + fare *= (1 + federalTransportTax); return fare; } $ git format-patch HEAD~1 --stdout @kannonboy
  29. 29. Pre-commit review dev maintainer public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; - fare *= federalTransportTax; + fare *= (1 + federalTransportTax); return fare; } Subject: [PATCH] Calculate federal transport tax correctly @kannonboy
  30. 30. > > > > > The braces are unnecessary. Pre-commit review dev maintainer public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; - fare *= federalTransportTax; + fare *= (1 + federalTransportTax); return fare; } Subject: Re: [PATCH] Calculate federal transport tax correctly > > @kannonboy
  31. 31. > > > > > > > > > > Technically true, but I think they add clarity. > > > > > > > The braces are unnecessary. Pre-commit review dev maintainer public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; - fare *= federalTransportTax; + fare *= (1 + federalTransportTax); return fare; } Subject: Re: Re: [PATCH] Calculate federal transport tax correctly @kannonboy
  32. 32. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Pre-commit review dev maintainer Subject: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: @kannonboy
  33. 33. Iteration m aster @kannonboy
  34. 34. Pre-commit review Linus Torvalds* Module maintainers File / driver maintainers Contributors linux-kernel@vger.kernel.org * Gross oversimplification, check out: bit.ly/linux-dev @kannonboy
  35. 35. Pre-commit review Junio C Hamano* Contributors git@vger.kernel.org * Also an oversimplification @kannonboy
  36. 36. Pull requests Post-commit review Pre-commit review master for/master Staging area Pre-commit review Version control agnostic Difficult to read High barrier to submit patches Simple and decentralized Difficult to iterate Easy to keep ‘000s of people in the loop Have to manually merge work @kannonboy
  37. 37. Post-commit review @kannonboy
  38. 38. Flexible structure master master patches & untracked files commits branches specific filesmultiple repos @kannonboy
  39. 39. Iterative review Branch diff Merge diff Pull request diffs @kannonboy
  40. 40. Iterative review Branch diff Post-commit review diffs Arbitrary commit diffs @kannonboy
  41. 41. Iterative review in @kannonboy
  42. 42. Iterative review in @kannonboy
  43. 43. Not an SCM SCM host (e.g. Bitbucket) Review host (e.g. Crucible) Dev team push & pull code review slurp slurp slurp slurp @kannonboy
  44. 44. Post-commit review Post-commit review Supports popular CVCS and DVCS Have to manually merge work Flexible review content Need a separate VCS host Easy to iterate Hard to enforce process @kannonboy
  45. 45. Pull requests master for/master Staging area @kannonboy
  46. 46. Gerrit and DIFFY The Kung Foo Review Cuckoo @kannonboy
  47. 47. Gerrit is very “Git-y” $ git config -f ~/gerrit/etc/gerrit.config gerrit.canonicalWebUrl http://localhost:8080/ @kannonboy
  48. 48. Staging area review for/master master reviewers approved? verified (build passing)? Dev team fetch push @kannonboy
  49. 49. From: Gerrit Code Review - A Quick Introduction @kannonboy
  50. 50. From: Gerrit Code Review - A Quick Introduction +2 +1 0 -1 -2 @kannonboy
  51. 51. “squash commits first” $ git push origin HEAD:refs/for/master # typey type type $ git commit -am “Review feedback” Counting objects: 2108776, done. Delta compression using up to 8 threads. Compressing objects: 100% (59/59), done. Writing objects: 100% (86/86), 893.21 KiB, done. Total 86 (delta 0), reused 0 (delta 0) ! [remote rejected] HEAD -> refs/for/master (squash commits first) error: failed to push some refs to ‘ssh://...' @kannonboy
  52. 52. “squash commits first” for/master @kannonboy
  53. 53. “squash commits first” for/master push @kannonboy
  54. 54. “squash commits first” for/master push push --force @kannonboy
  55. 55. “squash commits first” for/master push push --force push --force @kannonboy
  56. 56. From: Gerrit Code Review - A Quick Introduction @kannonboy
  57. 57. Pull requests Post-commit review Pre-commit review master for/master Staging area Staging area review Sophisticated policy enforcement Steep learning curve to use & administer Iteration is a little awkward FOSS project built in Java, on JGit Git only Clean commit history @kannonboy
  58. 58. Pull requests it review @kannonboy
  59. 59. Branches only master master patches & untracked files commits branches specific filesmultiple repos @kannonboy
  60. 60. Pull requests review before merging > Code review @kannonboy
  61. 61. Pull requests > Code review Passing build Reviewer sign-off Ready for deployment @kannonboy
  62. 62. Pull requests > Code review Passing build Reviewer sign-off Ready for deployment @kannonboy
  63. 63. Two developers about to press the “Merge” button @kannonboy
  64. 64. Merge Strategies @kannonboy
  65. 65. @kannonboy
  66. 66. --no-ff --ff-only --squash --ff-only --squash --ff @kannonboy
  67. 67. git merge --no-ff @kannonboy m aster feature/JIRA-123 “Always create a merge commit.”
  68. 68. git merge --no-ff @kannonboy m asterfeature/JIRA-123 “Always create a merge commit.”
  69. 69. git merge --ff @kannonboy m aster feature/JIRA-123 “Fast forward if you can, otherwise create a merge commit.”
  70. 70. git merge --ff @kannonboy m aster feature/JIRA-123 “Fast forward if you can, otherwise create a merge commit.”
  71. 71. git merge --ff @kannonboy m aster “Fast forward if you can, otherwise create a merge commit.”
  72. 72. git merge --ff @kannonboy m aster “Fast forward if you can, otherwise create a merge commit.”
  73. 73. git merge --ff-only @kannonboy m aster feature/JIRA-123 “Only allow fast forwards.”
  74. 74. git merge --ff-only @kannonboy m aster feature/JIRA-123 “Only allow fast forwards.”
  75. 75. git merge --ff-only @kannonboy m aster “Only allow fast forwards.”
  76. 76. git merge --ff-only @kannonboy m aster “Only allow fast forwards.”
  77. 77. git merge --ff-only @kannonboy m aster “Only allow fast forwards.”
  78. 78. git merge --ff-only @kannonboy m aster “Only allow fast forwards.”
  79. 79. git merge --squash @kannonboy “Combine commits on branch into a new commit on master.” m aster feature/JIRA-123
  80. 80. git merge --squash @kannonboy “Combine commits on branch into a new commit on master.” m aster
  81. 81. git merge --squash @kannonboy “Combine commits on branch into a new commit on master. Fail if master has any commits that branch doesn’t.” m aster --ff-only
  82. 82. git merge --squash @kannonboy “Combine commits on branch into a new commit on master. Fail if master has any commits that branch doesn’t.” m aster --ff-only
  83. 83. git merge --squash @kannonboy “Combine commits on branch into a new commit on master. Fail if master has any commits that branch doesn’t.” m aster --ff-only
  84. 84. Merge Commit Fast forward Squash Concise history Lose context of how features evolved Which should I use? “Ugly” history Full traceability Hard to screw up mostly some --no-ff --ff-only --squash @kannonboy No merge commits Verbose history Requires rebasing
  85. 85. Pull requests bit.ly/git-lfs Sophisticated policy enforcement Less flexible review content DVCS had some limitations around file size Choice of merge strategies Multiple team members can author code under review Git & Mercurial @kannonboy
  86. 86. pull requests @kannonboy Tim’s tips for top ten
  87. 87. 1. One issue, one pull request =  @kannonboy
  88. 88. 1. One issue, one pull request # what’s shipping? $ git branch --merged # what’s left to ship? $ git branch --no-merged @kannonboy
  89. 89. master IN REVIEW DONEIN PROGRESSOPEN @kannonboy Automatic Transitions
  90. 90. feature/JIRA-30 master IN REVIEW DONEIN PROGRESSOPEN Branch created! @kannonboy Automatic Transitions
  91. 91. feature/JIRA-30 master IN REVIEW DONEIN PROGRESSOPEN Pull Request Created! @kannonboy Automatic Transitions
  92. 92. feature/JIRA-30 master IN REVIEW DONEIN PROGRESSOPEN Pull Request Merged! @kannonboy Automatic Transitions
  93. 93. 2. Minimum TWO approvals before merge @kannonboy
  94. 94. 2. Minimum TWO approvals before merge 3. Have 1.5x - 2.5x that number reviewers @kannonboy
  95. 95. Fewer reviewers find more defects 0 7.5 15 22.5 30 1 2 3 4 5 6 7 8 9 Defects/kLoC Number of Reviewers @kannonboy source: bit.ly/review-stats
  96. 96. More reviewers spend less time 0 7 14 21 28 1 2 3 4 5 6 Minutesspent/reviewer Number of Reviewers @kannonboy source: bit.ly/review-stats
  97. 97. 4. Use blame to pick reviewers @kannonboy
  98. 98. 4. Use blame to pick reviewers $ npm install -g git-guilt # find blame delta for current branch $ git guilt `git merge-base master HEAD` HEAD Alice Foo ++++++++++++++++++++++++(239) Bob Bar ++++++++ Eve Baz ------- Mira Ted ---------------- Bec Opal ------------------------(-159) @kannonboy
  99. 99. 4. Use blame to pick reviewers bit.ly/suggest-reviewers @kannonboy
  100. 100. 4. Use blame to pick reviewers bit.ly/suggest-reviewers @kannonboy
  101. 101. 4. Use blame to pick reviewers bit.ly/suggest-reviewers @kannonboy
  102. 102. 5. @mention specialists @kannonboy
  103. 103. 6. Stuck in review? Make Tuesday & Thursday inbox zero days @kannonboy
  104. 104. betterCode; 7. Move comments into code review comments // comments // in code @kannonboy
  105. 105. 8. Build a team policy, as a team… …and enforce it! @kannonboy
  106. 106. 9. Add screenshots for UI/UX changes (gifs / videos are even better) @kannonboy
  107. 107. 9. Add screenshots for UI/UX changes (gifs / videos are even better) @kannonboy Monosnap GIPHY ScreenFlow
  108. 108. @kannonboy Ask a programmer to review 10 lines of code, they'll find 10 issues. Ask them to do 500 lines and they'll say it looks good. @GIRAYOZIL “ ” 10. Keep it concise
  109. 109. 10. Keep it conciseSecondsperline Lines of Code 1 line per second 100 lines per second @kannonboy source: bit.ly/review-stats
  110. 110. Code Review vs. Pull requests Need to review multiple repos at once Not on Git Heavily iterative workflow Literally everyone else Dendrophobia + @kannonboy (Traditional)
  111. 111. @kannonboy bitbucket.org Bitbucket atlassian.com/crucible Crucible gerritcodereview.com Gerrit Looking for more? Follow me for occasional Git & Bitbucket trivia

×