Coder Social home page Coder Social logo

gitlab-lint's Introduction

gitlab-lint API and collector

An open source gitlab linting utility

Frontend

https://github.com/globocom/gitlab-lint-react

How to install

Install dependencies

  • Golang
  • Docker
  • pre-commit
  • golangci-lint

Dev dependencies:

make setup

Create Gitlab access token

You should create a personal access token:

  1. Sign in to GitLab.
  2. In the top-right corner, select your avatar.
  3. Select Edit profile.
  4. In the left sidebar, select Access Tokens.
  5. Choose a name and optional expiry date for the token.
  6. Choose the read_api scope.
  7. Select Create personal access token.
  8. 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"

Run it

make run-docker

Collecting the data

make collector

Managing rules

What are rules

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.

Creating new rules

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.

Registering rules

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"
  }
]

Contribute

Fork the repository and send your pull-requests.

gitlab-lint's People

Contributors

cristiandean avatar janiltonmaciel avatar luccamendonca avatar marcelometal avatar tcarreira avatar thepabloaguilar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gitlab-lint's Issues

Collector: Process rules in parallel

Today the collector get all projects list and process it for each rule.

Maybe, we can transform each rule in a worker and process it for all projects

Save all projects during the collection

When searching for projects, I would expect to see my project with every passing rules (no matching rules).
But only projects with any matching (failing) rule are persisted.

It would be nice to save every project, even if no rule was matched

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.