Introduction

Maintaining code quality is a crucial aspect of software development. Ensuring our codebase is clean, maintainable, and free from errors is a collective responsibility. This document outlines our policies, best practices, tools, and metrics for maintaining the highest code quality in our project.

Tools and Technologies

Workflow

  1. Pre-push/Pre-PR:

  2. CI/CD Pipeline:

  3. Results Visualization:

Policies and Practices

  1. Code Quality Metrics:

  2. Code Review Process:

  3. Community Involvement:

Code Review

Every piece of code, irrespective of its origin, undergoes a review process:

  1. Reviewer Requirement: At least one review from a team member is mandatory for every pull request.

  2. Checklist for Reviewers:

Backend CI/CD Pipeline

All backend modules should use pipeline defined in the openimis-be_py in order to execute code analysis (Workflow Definition).

Flow executed by the CI Job:

Example setup: Social Protection Module

Setup variables:

SONAR_TOKEN - either taken from organization settings or from sonar project site

SONAR_PROJECT_KEY - key from Sonar, usually it’s openimis_<repository_name>

SONAR_ORGANIZATION - organization key, always openimis-1 for modules in organization

SONAR_PROJECT_NAME: repository name

SONAR_PROJECT_VERSION: 1.0

SONAR_SOURCES: social_protection

SONAR_EXCLUSIONS: excluded directories for coverage, by default "**/migrations/**,**/static/**,**/media/**,**/tests/**"

Workflow Overview


Jobs Details

build_backend

ci_module_mssql_tests

ci_module_psql_test

flake-8-linter

sonar_scan


Notes on Code Quality Checks

Sonar Quality Gateway

Currently all modules are using default Quality Gateway provided by Sonar. It expects code to:

Suggestions for further process improvements

Disagreements & Escalation

While we anticipate most discussions to be constructive, disagreements might arise. When they do:

  1. Both parties should discuss their perspectives in the PR comments.

  2. If no agreement is reached, a third-party core team member will intervene and provide feedback.

  3. As a last resort, the project maintainers have the final say on including or excluding a piece of code.

Refactoring

As the project evolves, refactoring becomes necessary to maintain code quality:

  1. Regular Refactoring Sprints: Every three months, a sprint dedicated to refactoring and addressing tech debt can be beneficial.

  2. Community Involvement: While community contributions primarily focus on features and fixes, we should encourage community members to participate in refactoring. Picking up smaller refactoring tasks can be a great way to familiarize oneself with the codebase.

Module CI

Add functionality allowing passing openimis.json as call paramter. Currently it’s fixed for develop branch which will not be optimal for all builds. Ideally all modules should be executed with theirs dependencies and modules that are depending on given one in order to make sure that changes didn’t affect other modules.