Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

ministryofjustice/github-repository-standards

Repository files navigation

ARCHIVED REPOSITORY: Ministry of Justice GitHub Repository Standards

Please see: https://github.com/ministryofjustice/operations-engineering/blob/main/python/services/standards_service.py

repo standards badge

This repository queries the Ministry of Justice (MoJ) GitHub Org API to find all the non archived repositories, and checks whether or not they comply with our standards.

These checks run on a regular schedule, and sends the results to the Operations Engineering Reports web application.

Repositories should:

  • should be licenced (recommended: MIT Licence)
  • have main as the default branch
  • have a non-empty description (shouldn't be null or "")
  • have issues enabled
  • have branch protection enabled on main, with:
    1. Require a pull request before merging
    2. Require approvals option and a minimum number of user to approve the pull request.
    3. Include administrators option

Architecture

  • A GraphQL query retrieves information about MoJ GitHub repositories
  • Data for each repository is used to instantiate a StandardsReport object
  • Code in StandardsReport creates a report based on the data supplied
  • The data is saved to two files
  • The two files are encrypted and sent to the Operations Engineering Reports web application.

Documentation

Yard is used for documentation. It creates a html report within the doc folder:

gem install yard
yardoc 'lib/**/*.rb'

Development

Environment Variables

To run app from the terminal:

For the Ruby code:

  • ADMIN_GITHUB_TOKEN must contain a GitHub personal access token (PAT) enabled for MoJ SSO

For the Python code:

  • OPERATIONS_ENGINEERING_REPORTS_API_KEY is a shared key between this App and the Operations Engineering Report, placed into the message header to verify the messages are from this App.
  • OPERATIONS_ENGINEERING_REPORTS_HOST is the URL to the Operations Engineering Report on the Cloud Platform.
  • ENCRYPTION_KEY a shared encryption key to encrypt the data in transit.

bin/repository-checker

This script runs on daily basis via the GitHub Actions workflow. You can also run it manually by triggering the action. This script will create the two files of data that are to be sent to the Operations Engineering Reports application.

To run it locally:

ruby bin/repository-checker

scripts/python/encrypt_send_data.py

This script will encrypt and send the two files of data to the Operations Engineering Reports application.

To run it locally:

python3 -m venv venv
source venv/bin/activate
python3 -m pip install -r scripts/python/requirements.txt
python3 scripts/python/encrypt_send_data.py

Tests

Install bundler (gem install bundler) then run bundle install to install the dependencies.

To run the unit tests use bundle exec rspec or rspec.

rspec will generate a code coverage report using simplecov and create a coverage folder. Open the report using open coverage/index.html

Install rspec and ruby-debug-ide (locally for VS-Code to debug the tests):

gem install rspec --install-dir ./bin
sudo gem install ruby-debug-ide

VS Code Debugging

To debug in VS Code use the below launch configrations within .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python",
      "type": "python",
      "python": "${workspaceFolder}/venv/bin/python3",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "program": "${workspaceFolder}/scripts/python/encrypt_send_data.py",
      "console": "integratedTerminal",
      "env": {
        "OPERATIONS_ENGINEERING_REPORTS_API_KEY": "THE_HEADER_API_KEY",
        "OPERATIONS_ENGINEERING_REPORTS_HOST": "THE_OPS_ENG_API_URL",
        "ENCRYPTION_KEY": "THE_ENCRYPTION_KEY"
      }
    },
    {
      "name": "Ruby - file",
      "type": "Ruby",
      "request": "launch",
      "program": "${workspaceRoot}/bin/repository-checker",
      "env": {
        "ADMIN_GITHUB_TOKEN": "add-token",
      }
    },
    {
      "name": "RSpec - file",
      "type": "Ruby",
      "request": "launch",
      "program": "${workspaceRoot}/bin/bin/rspec",
      "args": ["${file}"]
    },
    {
      "name": "RSpec - all",
      "type": "Ruby",
      "request": "launch",
      "program": "${workspaceRoot}/bin/bin/rspec",
      "args": ["-I", "${workspaceRoot}"]
    }
  ]
}