Slide 1

Slide 1 text

COMMIT MESSAGES AND PULL REQUESTS by Dana Jones Fractured Atlas

Slide 2

Slide 2 text

twitter.com/commitcampaign

Slide 3

Slide 3 text

BEST PRACTICES Confirm that the work you intend to do is the work that is needed. Remember, a Trello card is a promise of a conversation, not a work order.

Slide 4

Slide 4 text

BEST PRACTICES Confirm that the work you intend to do is the work that is needed. Remember, a Trello card is a promise of a conversation, not a work order. Make sure branch names are dash-separated, and not underscore_separated. As we move more of our infrastructure to Kubernetes, this becomes more important.

Slide 5

Slide 5 text

Set your editor’s preferences to trim trailing whitespace from lines. Variations on this setting muddies the git history and complicates git forensics.

Slide 6

Slide 6 text

Shutterstock.com

Slide 7

Slide 7 text

Susie writes a new feature: def add_numbers(num_1, num_2) Rails.logger("Add some numbers") added = num_1.to_i + num_2.to_i puts added end

Slide 8

Slide 8 text

Susie writes a new feature: def add_numbers(num_1, num_2) Rails.logger("Add some numbers") added = num_1.to_i + num_2.to_i puts added end Martin removes the comment, and adds some trailing whitespace: def add_numbers(num_1, num_2) added = num_1.to_i + num_2.to_i puts added end

Slide 9

Slide 9 text

Susie writes a new feature: def add_numbers(num_1, num_2) Rails.logger("Add some numbers") added = num_1.to_i + num_2.to_i puts added end Martin removes the comment, and adds some trailing whitespace: def add_numbers(num_1, num_2) added = num_1.to_i + num_2.to_i puts added end Anna changes a totally different function in the class, but adds more whitespace: def add_numbers(num_1, num_2) added = num_1.to_i + num_2.to_i puts added end

Slide 10

Slide 10 text

SpongeBob Time Cards
 https://www.youtube.com/channel/UCjfmzjLRyiwgMnZ2pltNSlQ

Slide 11

Slide 11 text

Susie writes a new feature: def add_numbers(num_1, num_2) Rails.logger("Add some numbers") added = num_1.to_i + num_2.to_i puts added end Martin removes the comment, and adds some trailing whitespace: def add_numbers(num_1, num_2) added = num_1.to_i + num_2.to_i puts added end Anna changes a totally different function in the class, but adds more whitespace: def add_numbers(num_1, num_2) added = num_1.to_i + num_2.to_i puts added end Roger is trying to figure out who wrote the add_numbers function so he can ask them about it, and he gets all kinds of misleading information: Anna > def add_numbers(num_1, num_2) Martin > added = num_1.to_i + num_2.to_i Anna > puts added Susie > end

Slide 12

Slide 12 text

Set your editor’s preferences to trim trailing whitespace from lines. Variations on this setting muddies the git history and complicates git forensics. Never use git add . when adding code changes. Use git add -p instead. This protects you from making inadvertent additions to the repo (debugging code, tabs instead of spaces, stray characters, etc.)

Slide 13

Slide 13 text

GIT ADD -P Deletions Additions Whitespace

Slide 14

Slide 14 text

Set your editor’s preferences to trim trailing whitespace from lines. Variations on this setting muddies the git history and complicates git forensics. Never use git add . when adding code changes. Use git add -p instead. This protects you from making inadvertent additions to the repo (debugging code, tabs instead of spaces, stray characters, etc.) The name of an object should indicate what it does. Doing this reduces cognitive load for anyone reviewing your code, and for anyone working on your code in the future.

Slide 15

Slide 15 text

def transact loser.addresses.each do |address| if winner.addresses.blank? address.update_attributes(:person_id => winner.id) elsif !winner.addresses.include?(address) address.update_attributes(:person_id => winner.id, :is_primary => false) end end if winner.addresses.present? && ! winner.addresses.select(&:is_primary?).present? winner.addresses.first.update_attributes(:is_primary => true) end end

Slide 16

Slide 16 text

def transact reassign_addresses set_primary_winner_address end def reassign_addresses loser.addresses.each do |address| if winner_addresses.blank? address.update_attributes(person_id: winner.id) elsif !winner_addresses.include?(address) address.update_attributes(person_id: winner.id, is_primary: false) end end end def set_primary_winner_address if winner_addresses.present? && ! winner_addresses.select(&:is_primary?).present? winner_addresses.first.update_attributes(is_primary: true) end end

Slide 17

Slide 17 text

COMMIT MESSAGES

Slide 18

Slide 18 text

Commit messages should make sense in isolation. They should tell the what and the why.
 
 Examples that do not achieve this: Respond to feedback

Slide 19

Slide 19 text

Commit messages should make sense in isolation. They should tell the what and the why.
 
 Examples that do not achieve this: Respond to feedback Fix spec

Slide 20

Slide 20 text

Commit messages should make sense in isolation. They should tell the what and the why.
 
 Examples that do not achieve this: Respond to feedback Fix spec Make CodeClimate happy

Slide 21

Slide 21 text

Commit messages should make sense in isolation. They should tell the what and the why.
 
 Examples that do not achieve this: Respond to feedback Fix spec Make CodeClimate happy Add logging

Slide 22

Slide 22 text

Commit messages should make sense in isolation. They should tell the what and the why.
 
 Examples that do not achieve this: Respond to feedback Fix spec Make CodeClimate happy Add logging Clean up

Slide 23

Slide 23 text

Commit messages should make sense in isolation. They should tell the what and the why.
 
 Examples that do not achieve this: Respond to feedback Fix spec Make CodeClimate happy Add logging Clean up Abc order

Slide 24

Slide 24 text

Commit messages should make sense in isolation. They should tell the what and the why.
 
 Examples that do not achieve this: Respond to feedback Fix spec Make CodeClimate happy Add logging Clean up Abc order God doesn't love ugly

Slide 25

Slide 25 text

https://revelry.co/pull-requests-code-review/

Slide 26

Slide 26 text

WHAT IS A PULL REQUEST? A Pull Request (PR) is a formalized request that a project maintainer add the submitted code changes to the project repository. Unless otherwise flagged, a PR is a signal to a project
 maintainer and other contributors to the project that the
 code it includes is production-ready.

Slide 27

Slide 27 text

CODE THAT ISN’T PRODUCTION-READY If you just want someone to review work in progress, push the branch you’re working on, and ask the reviewer to check it out. Alternatively, you can create a PR so the reviewer can easily review and comment on the work, but make sure you add the WIP label.

Slide 28

Slide 28 text

EFFECTIVE PULL REQUESTS Smaller PRs are easier and faster to review. Create iterative PRs for large features whenever possible. If you find this hard to do, think about taking a large feature branch and figuring out how you could break it up and re-create it in smaller, more digestible chunks that still get the same result.

Slide 29

Slide 29 text

PR DESCRIPTION express your intent, link to the Trello card, include contextual information, warn about any “gotchas,” give instructions for testing and deploying, avoid accusatory or defensive language, and include a screenshot or animated GIF to demonstrate UX changes. Or just for fun. :) A PR description should:

Slide 30

Slide 30 text

REVIEWING PULL REQUESTS

Slide 31

Slide 31 text

WHAT TO LOOK FOR Do automatic checks pass? For those that don’t, are the failures legitimate? If so, notify the submitter and pause review.

Slide 32

Slide 32 text

WHAT TO LOOK FOR Do automatic checks pass? For those that don’t, are the failures legitimate? If so, notify the submitter and pause review. Are there files with conflicts? If so, these should be resolved before the review proceeds, because files will change.

Slide 33

Slide 33 text

WHAT TO LOOK FOR Do automatic checks pass? For those that don’t, are the failures legitimate? If so, notify the submitter and pause review. Are there files with conflicts? If so, these should be resolved before the review proceeds, because files will change. Does the PR have migrations? If so, part of your review should be to run rake db:migrate and rake db:rollback to ensure there are no syntax errors.

Slide 34

Slide 34 text

Are there any missing new files? It’s a common mistake to forget to add view files, support files (eg. test import files), images, etc. to the git repo.

Slide 35

Slide 35 text

Are there any missing new files? It’s a common mistake to forget to add view files, support files (eg. test import files), images, etc. to the git repo. Examine the fallout of deletions - were all references to a CSS class removed, but the class itself persisted? Same for JS functions, view partials, functions, I18n locale keys, routes, etc.

Slide 36

Slide 36 text

Are there any missing new files? It’s a common mistake to forget to add view files, support files (eg. test import files), images, etc. to the git repo. Examine the fallout of deletions - were all references to a CSS class removed, but the class itself persisted? Same for JS functions, view partials, functions, I18n locale keys, routes, etc. Are there sufficient tests to cover the functionality that's been added?

Slide 37

Slide 37 text

Are there any missing new files? It’s a common mistake to forget to add view files, support files (eg. test import files), images, etc. to the git repo. Examine the fallout of deletions - were all references to a CSS class removed, but the class itself persisted? Same for JS functions, view partials, functions, I18n locale keys, routes, etc. Are there sufficient tests to cover the functionality that's been added? Are there any public functions that should be made private?

Slide 38

Slide 38 text

LEAVING REVIEW COMMENTS Apply the principles explored in the book Radical Candor by Kim Scott - feedback should be both personal and direct (see Ian Feather’s blog post).

Slide 39

Slide 39 text

LEAVING REVIEW COMMENTS Apply the principles explored in the book Radical Candor by Kim Scott - feedback should be both personal and direct (see Ian Feather’s blog post). Feedback on a PR can be either positive or negative, but should be meaningful.

Slide 40

Slide 40 text

LEAVING REVIEW COMMENTS Apply the principles explored in the book Radical Candor by Kim Scott - feedback should be both personal and direct (see Ian Feather’s blog post). Feedback on a PR can be either positive or negative, but should be meaningful. Phrasing critical feedback as questions rather than directives is gentler and less combative.

Slide 41

Slide 41 text

"Have you considered...?" "I wonder if it might be helpful to..." "What do you think about...?" "Can you clarify...?" "Why didn't you just...?"

Slide 42

Slide 42 text

weheartit.com/entry/2454490

Slide 43

Slide 43 text

"Have you considered...?" "I wonder if it might be helpful to..." "What do you think about...?" "Can you clarify...?" "Why didn't you just...?"

Slide 44

Slide 44 text

Ask clarifying questions if there’s something you don’t understand. You learn, and you aren’t rubber- stamping code that could be problematic.

Slide 45

Slide 45 text

Ask clarifying questions if there’s something you don’t understand. You learn, and you aren’t rubber- stamping code that could be problematic. If the feedback you need to give is pervasive or potentially embarrassing, consider talking to the submitter directly instead of putting the feedback in writing.

Slide 46

Slide 46 text

Ask clarifying questions if there’s something you don’t understand. You learn, and you aren’t rubber- stamping code that could be problematic. If the feedback you need to give is pervasive or potentially embarrassing, consider talking to the submitter directly instead of putting the feedback in writing. Ask yourself if your critical comment/inquiry is adding real value or just picking a nit.

Slide 47

Slide 47 text

If you have a considerable number of suggestions for changes, think about creating a branch from the PR branch, make your changes, and submitting a PR to the submitter’s branch.