reviewdog

package module
v0.20.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

README

Woodpecker CI Reviewdog plugin library

Library to build Woodpecker CI plugins that integrate Reviewdog with specific tools.

Builtin settings

Settings Name Environment variable Default Description
token - none Forge API token
tool-name - none Custom tool name to report
debug - false Enable debug mode
log_level - info Sets log level (panic, fatal, error, warn, info, debug, trace)
skip_verify - false Skip verification of TLS certificate
SOCKS_PROXY none SOCKS5 proxy to use for connections
SOCKS_PROXY_OFF none Do not use SOCKS5 proxy

Creating a plugin

package main

import (
	"context"
	"io"

	plugin "codeberg.org/woodpecker-plugins/go-plugin-reviewdog"
	"github.com/reviewdog/reviewdog/parser"
	"github.com/urfave/cli/v3"
)

type Plugin struct {
	*plugin.Plugin
}

func (p *Plugin) Name() string {
	return "golint"
}

func (p *Plugin) Flags() []cli.Flag {
	return nil
}

func (p *Plugin) Parser() (parser.Parser, error) {
	return p.CustomFormat("%f:%l:%c: %m")
}

func (p *Plugin) Exec(ctx context.Context) (io.Reader, func(), error) {
	return p.ExecCommand(ctx, "golint", "./...")
}

func main() {
	p := &Plugin{}
	p.Plugin = plugin.New("plugin-reviewdog-golint", version, p)
	p.Run()
}

Contributors

Special thanks goes to all contributors. If you would like to contribute, please see the instructions.

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v0.17.4

type Option interface {
	// contains filtered or unexported methods
}

Option represents an option for the diagnostic result.

type Plugin

type Plugin struct {
	*plugin.Plugin
	Settings Settings
	// contains filtered or unexported fields
}

Plugin implements provide the plugin implementation.

func New

func New(name, version string, tool Tool) *Plugin

New initializes a plugin from the given Settings, Pipeline, and Network.

func (*Plugin) CommandOutput added in v0.4.0

func (p *Plugin) CommandOutput(ctx context.Context, name string, args ...string) ([]byte, error)

CommandOutput executes the given command and returns output.

func (*Plugin) CustomFormat

func (p *Plugin) CustomFormat(format ...string) (parser.Parser, error)

CustomFormat returns a parser for the given format(s).

func (*Plugin) ExecCommand

func (p *Plugin) ExecCommand(ctx context.Context, name string, args ...string) (io.Reader, func(), error)

ExecCommand executes the given command and returns output stream.

func (*Plugin) Execute

func (p *Plugin) Execute(ctx context.Context) error

Execute provides the implementation of the plugin.

func (*Plugin) Flags

func (p *Plugin) Flags() []cli.Flag

func (*Plugin) NamedFormat

func (p *Plugin) NamedFormat(name string) (parser.Parser, error)

NamedFormat returns a parser for the given format name.

func (*Plugin) ToolName added in v0.4.0

func (p *Plugin) ToolName() string

ToolName returns the name of the tool to report.

func (*Plugin) Validate

func (p *Plugin) Validate() error

Validate handles the settings validation of the plugin settings.

type RDF added in v0.17.4

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

RDF represents the reviewdog diagnostic results.

func (*RDF) AddLineResult added in v0.17.4

func (t *RDF) AddLineResult(path string, line int, message string, severity Severity, opts ...Option)

AddLineResult adds a diagnostic result with line number.

func (*RDF) AddPositionResult added in v0.17.4

func (t *RDF) AddPositionResult(path string, line, col int, message string, severity Severity, opts ...Option)

AddPositionResult adds a diagnostic result with line and column number.

func (*RDF) AddRangeResult added in v0.17.4

func (t *RDF) AddRangeResult(path string, start, end int, message string, severity Severity, opts ...Option)

AddRangeResult adds a diagnostic result with start and end line number.

func (*RDF) RDJSON added in v0.17.4

func (t *RDF) RDJSON() ([]byte, error)

RDJSON returns the reviewdog diagnostic results in JSON format.

func (*RDF) RDJSONL added in v0.17.4

func (t *RDF) RDJSONL() ([]byte, error)

RDJSONL returns the reviewdog diagnostic results in JSON Lines format.

type Rule added in v0.17.4

type Rule struct {
	// Code for the rule.
	Code string
	// URL for the additional rule information.
	URL string
}

Rule represents a rule for the diagnostic result.

type Settings

type Settings struct {
	Token    string
	Debug    bool
	ToolName string
}

Settings for the plugin.

type Severity added in v0.17.4

type Severity int

Severity represents the severity of the diagnostic result.

const (
	// SeverityUnknown represents unknown severity.
	SeverityUnknown Severity = iota
	// SeverityError represents error severity.
	SeverityError
	// SeverityWarning represents warning severity.
	SeverityWarning
	// SeverityInfo represents info severity.
	SeverityInfo
)

type Tool

type Tool interface {
	// Name returns the name of the tool.
	Name() string

	// Flags returns the flags for the tool.
	Flags() []cli.Flag

	// Parser to be used by reviewdog.
	Parser() (parser.Parser, error)

	// Exec executes the tool.
	Exec(ctx context.Context) (io.Reader, func(), error)
}

Tool to be used by the reviewdog.

Jump to

Keyboard shortcuts

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