Skip to content

Instantly share code, notes, and snippets.

@chrisrzhou
Last active October 14, 2022 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisrzhou/126a83460332651d8f1bbff5b22df94f to your computer and use it in GitHub Desktop.
Save chrisrzhou/126a83460332651d8f1bbff5b22df94f to your computer and use it in GitHub Desktop.

Code Reviews

Chris Zhou, 2022-10-14


Elements of Coding

  • Code
  • Coder

Processes of Coding

  • Code design
  • Coding
  • Code review

Elements of Code Reviews

  • Author(s)
  • Reviewer(s)
  • Commits
  • Diffs
  • Discussions

Merge Requests

A pull/merge request is a request to merge code changes.

It integrates all elements of code reviews:

  • View commits and diffs.
  • Enable discussions between authors and reviewers.

Code Review Frustrations


Who enjoys reviewing complex merge requests?


Who enjoys merge request conversations that are difficult to track over time?


Who enjoys not being able to close merge requests?


Philosophy


Code reviews > Code


Sell your code to ship your code.


Our code, not my code.


Assume an AI Overlord.


Value (git) history.


Author the history with meaningful commits.


Coauthor the history with others.


Best Practices


Consider your audience/reviewers. Do they have context? Does context need to be established?


Consider primary reviewers.


Keep merge requests isolated (not small).


Build a habit of breaking code changes into commits with isolated responsibility. Review by commits.


Have meaningful merge request summary, test plans to build searchable metadata.


Focus less on the outcome of shipping code, and more on the process of reviewing code with others.


Always consider your role (e.g. primary author/reviewer). Am I blocking others?


git Commits and History


A bad history

c1: implement page X

A better history

c1: update state
c2: update tests
c3: fix bug in A and B
c4: install deps
c4: bootstrap page X

A complete history

c1: feat(workflow): register tickets state
c2: test(A): add tests
c3: test(B): add tests
c4: fix(A): fix against c2
c5: fix(B): fix against c3
c6: deps: install D1 and D2
c7: feat(PageX): bootstrap

Conventional Commits

  • Conventions adding semantics and structure for commit messages.
  • Link
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

fix: handle Y in X
fix!: handle Y in X (with breaking changes)
fix(X): handle Y
feat: support Y in X
feat!: support Y in X (with breaking changes)
feat(X): support Y
build: update deps
chore: cleanup package.json
docs: update Y for X
docs(X): update Y
test: test Y in X
test(X): test Y

Conventional Changelog

  • Generate changelogs and release notes from a project's commit messages and metadata
  • Because there is consistent structure in git commits, Semver and breaking changes can be systematically generated.
  • Link

[1.2.1](link to commit) (YYYY-MM-DD)

## Fixes

### [commit.domain]
- [commit.id]: commit.message

## Features
### [commit.domain]
- [commit.id]: commit.message

## Breaking Changes
### [commit.domain]
- [commit.id]: commit.message

Commit lints

  • Lint commit messages to ensure consistent and compliant structure.
  • Link

Live Demo


Appendix

This presentation is written entirely in Markdown (CommonMark).

It is presented using md-slides (a hacked POC) utilizing the following microlibraries:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment