codeowners

package module
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 7 Imported by: 0

README

Go Go Report Card Coverage Godoc

CODEOWNERS

CodeOwners package provides funcionality to evaluate CODEOWNERS file in Go. Also provides a CLI to lint.

Documentation

Package

To find package documentation follow https://godoc.org/github.com/fmenezes/codeowners

CLI
Installation

Simply run go get -u github.com/fmenezes/codeowners/cmd/codeownerslint

Usage

Simply calling codeownerslint will kick off the cli on the current directory.

Options
Option Default Value Description
d . Directory: specifies the directory you want to use to lint the CODEOWNERS file
f Format: specifies the format you want to return lint results
t Token: specifies the Github's token you want to use
tt bearer Token Type: specifies the Github's token type you want to use
Exit Codes
Exit Code Description
0 Success: no errors returned
1 Warnings: linter returned a few warnings but no errors
2 Errors: linter returned a few errors
3 Unexpected errors: errors that prevented the linter from running

Compatibility

⚠ This module is on a v0 mode and it is not ready to be used, once it reaches the v1 we will lock the API.

Documentation

Overview

Package codeowners provides funcionality to evaluate CODEOWNERS file.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultLocations = [...]string{"CODEOWNERS", "docs/CODEOWNERS", ".github/CODEOWNERS"}

DefaultLocations provides default locations for the CODEOWNERS file

Functions

func AvailableCheckers

func AvailableCheckers() []string

AvailableCheckers returns list of registered checkers

func ParseLine added in v0.2.0

func ParseLine(line string) (string, []string)

ParseLine parses a CODEOWNERS line into file pattern and owners

func RegisterChecker

func RegisterChecker(name string, checker Checker) error

RegisterChecker adds checker to be used later when checking CODEOWNERS files

Types

type CheckOptions added in v0.3.0

type CheckOptions struct {
	Directory       string
	Checkers        []string
	GithubTokenType string
	GithubToken     string
}

CheckOptions provides parameters for running a list of checks

type CheckResult

type CheckResult struct {
	Position  Position
	Message   string
	Severity  SeverityLevel
	CheckName string
}

CheckResult provides structured way to evaluate results of a CODEOWNERS validation check

func Check

func Check(options CheckOptions) ([]CheckResult, error)

Check evaluates the file contents against the checkers and return the results back.

Example
package main

import (
	"fmt"

	"github.com/fmenezes/codeowners"
)

func main() {
	checks, err := codeowners.Check(codeowners.CheckOptions{
		Directory: ".",
		Checkers:  codeowners.AvailableCheckers(),
	})
	if err != nil {
		panic(err)
	}
	for _, check := range checks {
		fmt.Printf("%s ::%s:: %s [%s]\n", check.Position.Format(), check.Severity.Name(), check.Message, check.CheckName)
	}
}
Output:

CODEOWNERS 0 ::Error:: No CODEOWNERS file found [NoCodeowners]

type Checker

type Checker interface {
	NewValidator(options ValidatorOptions) Validator
}

Checker provides tools for validating CODEOWNER file contents

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder providers functionality to read CODEOWNERS data

Example
package main

import (
	"fmt"
	"strings"

	"github.com/fmenezes/codeowners"
)

func main() {
	decoder := codeowners.NewDecoder(strings.NewReader(`* test@example.org
filepattern @owner`))
	for decoder.More() {
		token, line := decoder.Token()
		fmt.Printf("Line: %d\n", line)
		fmt.Printf("File Pattern: %s\n", token.Path())
		fmt.Printf("Owners: %v\n", token.Owners())
	}
}
Output:

Line: 1
File Pattern: *
Owners: [test@example.org]
Line: 2
File Pattern: filepattern
Owners: [@owner]

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder generates a new Decoder instance. The reader should contain the contents of the CODEOWNERS file

func (*Decoder) More

func (d *Decoder) More() bool

More returns true if there are available CODEOWNERS lines to be scanned. And also advances to the next line.

func (*Decoder) Token

func (d *Decoder) Token() (Token, int)

Token parses the next available line in the CODEOWNERS file. If More was never called it will return an empty token. After end of file Token will always return the last line.

type Position added in v0.2.0

type Position struct {
	FilePath    string
	StartLine   int
	StartColumn int
	EndLine     int
	EndColumn   int
}

Position provides structured way to evaluate where a given validation result is located in the CODEOWNERs file

func (Position) Format added in v0.3.2

func (p Position) Format() string

Format converts the position data into a string

type SeverityLevel

type SeverityLevel int

SeverityLevel exposes all possible levels of severity check results

const (
	Error   SeverityLevel = iota // Error serverity level
	Warning                      // Warning serverity level
)

All possible severiy levels

func (SeverityLevel) Name added in v0.3.2

func (l SeverityLevel) Name() string

Name returns the string representation of this severity level

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token providers reading capabilities for every CODEOWNERS line

func (Token) Owners

func (t Token) Owners() []string

Owners returns the owners

func (Token) Path

func (t Token) Path() string

Path returns the file path pattern

type Validator added in v0.3.0

type Validator interface {
	ValidateLine(lineNo int, line string) []CheckResult
}

Validator provides tools for validating CODEOWNER file contents

type ValidatorOptions added in v0.3.0

type ValidatorOptions struct {
	Directory              string
	CodeownersFileLocation string
	GithubTokenType        string
	GithubToken            string
}

ValidatorOptions provide input arguments for checkers to use

Directories

Path Synopsis
Package checkers contain pre built checkers to validate CODEOWNER files
Package checkers contain pre built checkers to validate CODEOWNER files
cmd
codeownerslint command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL