An open source gitlab linting utility
https://github.com/globocom/gitlab-lint-react
- Golang
- Docker
- pre-commit
- golangci-lint
make setup
You should create a personal access token:
- Sign in to GitLab.
- In the top-right corner, select your avatar.
- Select Edit profile.
- In the left sidebar, select Access Tokens.
- Choose a name and optional expiry date for the token.
- Choose the
read_api
scope. - Select Create personal access token.
- Save the personal access token somewhere safe. If you navigate away or refresh your page, and you did not save the token, you must create a new one.
Set the following environment variable with your token:
More info at Personal access tokens
export GITLAB_TOKEN="token"
make run-docker
make collector
Rules are how gitlab-lint
knows what to look for on each processed project.
Take for an example the Empty Repository
rule: its goal is to check if the
current project houses an empty repository.
Rules must implement the Ruler interface and they must have at least the following fields on their struct:
type Ruler interface {
Run(client *gitlab.Client, p *gitlab.Project) bool
GetSlug() string
GetLevel() string
}
type MyAwesomeRule struct {
Description string `json:"description"`
ID string `json:"ruleId"`
Level string `json:"level"`
Name string `json:"name"`
}
A good practice is to also have a NewMyAwesomeRule()
function that returns an
instatiaded rule's struct.
Notice that ID
and GetSlug()
should return a unique value to identify your
rule.
Also, there's already a couple of pre-determined Levels on levels. We must use those instead of random strings.
After creating the rule itself, we must register it so it's considered when we
parse the projects. In order to do it, we should just add it to the init()
function on my_registry, just like so:
func init() {
MyRegistry.AddRule(NewMyAwesomeRule())
...
}
Then, you should be able to save (or recompile, if running a binary) and check
your new rule being returned by running a GET to /api/v1/rules
:
[
{
"description": "",
"ruleId": "my-awesome-rule",
"level": "error",
"name": "My Awesome Rule"
}
]
Fork the repository and send your pull-requests.