yaleman / github_linter

Automating all the little things I need to check in my repos.
MIT License
2 stars 0 forks source link
automation github linter python shell shellcheck terraform

github_linter

This is mainly for me, but it's a way of going through the Github repositories that you have access to, to check all the things you'd usually expect.

Because I've got like ~100 repos and keep changing how I do things, and it annoys me to work on an old one and hit all the weird edge cases I've fixed elsewhere.

Current Modules

Dependabot

Generic Things

GitHub Actions

(GitHub) Issues

pyproject.toml

Only runs if you've got Python.

Terraform

Testing

mkdocs

Configuration

The config file is called github_linter.json - you can put it in the local dir or ~/.config/github_linter.json - I've included my configuration in the repository.

Each test module has its defaults, in the DEFAULT_CONFIG attribute.

For an example:

>>> import github_linter.tests.pyproject
>>> print(github_linter.tests.pyproject.DEFAULT_CONFIG)
{'build-system': ['flit_core.buildapi', 'poetry.core.masonry.api'], 'readme': 'README.md'}

Authentication

Using a Personal Access Token (Recommended)

"github" : { 
    "token" : "<pat>"
}

Using username/password

"github" : { 
    "username" : "<your_username>", 
    "password" : "<your_password>" 
}

Set the following in your config file to bypass auth and YOLO it

"github" : { 
    "ignore_auth" : true 
}

Adding new test modules

  1. Add a module under github_linter/tests/
  2. Set CATEGORY: str = "nameofmodule" to a name which will go in the reports.
  3. Set LANGUAGES: List[str] = [] to a list of lower case languages, eg: python / javascript / rust / shell / "all" which matches all. This is based on GitHub's auto-detection.
  4. Call check functions check_<something>
  5. Call fix functions fix_<something>
  6. Import the module in tests/__init__.py as part of the big from . import () block.
  7. Eat cake.

Docker container

The container runs an entrypoint of poetry shell which puts you in an environment where the package and non-dev deps are installed.

The container name to pull is ghcr.io/yaleman/github_linter:latest.

Building the docker container

This should auto-build with github actions (soon!) but here's a handy command:

docker build -t 'ghcr.io/yaleman/github_linter' .

Running things in the docker container

Running the web server.

docker run --rm -it \
* e "GITHUB_TOKEN=${GITHUB_TOKEN}" \
* v "$(pwd)/github_linter.json:/home/useruser/github_linter.json" \
* p '8000:8000' \
    ghcr.io/yaleman/github_linter:latest \
    python -m github_linter.web