OIT Code Review Standard¶
Scope: OIT
Type: Standard
Version: 2023-initial
Goal¶
Establish a standard that code is reviewed prior to use.
Ownership¶
Direct questions to the Owner: Seth A. Roby email redacted
Resources to comply with this standard should be directed to your supervisor.
Timeline & Enforcement¶
All teams should be compliant with this standard by the close of 2023.
Exception Process¶
Exceptions that do not meet the standards by the deadline MAY petition the ARB for an extension. A majority vote will extend the deadline for three months. Additional extensions MAY be requested for up to one year after the initial deadline.
Terminology¶
- Code always includes actual source code, but also include scripts, configuration files, infrastructure-as-code, etc. Any artifact that is used to create an eventual product MAY be considered code for the purposes of this document.
- A developer is anyone who writes code.
- A reviewer is anyone who reviews code. They are often a developer themselves, but it can be helpful to distinguish the roles.
- The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119
Requirements¶
Scope¶
- Projects MUST perform code review if they meet any of the following criteria:
- The project is part of an application that has an availability level of 3 or higher
- The project is part of an application that handles data with a protection level of 3 or higher
- The application is considered mission-critical
- The project team contains five or more developers
- Projects SHOULD perform code review even if they do not meet the criteria above
Tooling¶
- Teams SHOULD select a single tool to use for code review
- Teams should ensure the tool is accessible to all developers and reviewers
- ARB recommends using GitHub Pull Requests, which are native to our GitHub Enterprise deployment, document the process, collect and aggregate discussion and signoffs, and integrate with the source code repository in a natural way.
- Most code can be reviewed in GitHub or Git. If your code cannot be housed there, you SHOULD review it in another tool that provides an audit log. If no tool exists, you SHOULD keep an audit log in a shared space that your team can access.
Process¶
- At its core, a code review process looks like this:
- A developer writes code
- One or more reviewers review the code
- The developer MUST NOT be a reviewer of their own code
- The developer works with the reviewers to get their approval
- When approvals are granted, the code is put into use
- Teams SHOULD document their code review process, including…
- Where to put your code to facilitate review
- ARB recommends new git branches to facilitate using pull requests
- How and when to request review
- ARB recommends using your team’s existing communications channels to request reviews
- How quickly reviewers are expected to respond to requests
- ARB recommends that this be no more than 24 hours
- What reviewers are expected to look for and provide feedback on
- ARB recommends that reviewers SHOULD seek to understand the code and check for quality, consistency, and fitness to requirements. Other items can be included in the review at the team’s option– see the “Reasons for code review” section for some ideas on what your team might want to include.
- How reviewers are supposed to leave feedback
- ARB recommends using comments in a pull request
- When and how reviewers should withhold approval
- ARB recommends using the “Request changes” review type
- How many approving reviewers are required
- ARB recommends that small teams require one reviewer, and teams with four or more developers require two reviewers
- What to do when some reviewers approve and some do not
- ARB recommends that code should not be used until all approver’s requested changes have been addressed
- Who takes action to put the reviewed code into use
- ARB recommends that the original developer merges the pull request and deletes the old branch
- If the change will not be approved, ARB recommends that the original developer closes the pull request
- Where to put your code to facilitate review
Background¶
Code review is a process where code written by one developer is examined by another developer before it is put into use. By ensuring that multiple people see the code before it hits production, you have greater confidence that the code does what it is supposed to in a way that the team can support going forward.
Reasons for code review¶
- Regulatory
- Separation of duties
- Possible requirements for deployment into production or merging branches
- Accuracy and Security
- Validating that requirements are fulfilled
- Regression check
- Catching errors and issues before they are put into production and become a challenge for more people
- Spotting attempted insertion of malware and backdoors
- Standards
- Consistency in application development: standardizing patterns and methods across a team or larger group
- Naming and formatting conventions and standards
- Code quality and readability
- Maintainability
- Improvements and discussion
- Sharing new ideas, tools, and techniques
- Suggestions for improvements or optimization
- Bug and logical error catching
- Continuity
- Understanding of details and components by other team members
- Accurate and effective integration of components built by different team members
- Mentorship of newer developers
- Continuity and idea sharing across different teams, simple continuity for a solo developer