lint2hub

package module
v0.0.0-...-40261f5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: MIT Imports: 6 Imported by: 0

README

lint2hub

GoDoc

lint2hub automates creating GitHub pull request review comments in response to code linters. While other solutions exist, lint2hub is both free software and not tied to any specific linter.

Usage

lint2hub is both a command line tool and a go client for commenting on pull requests diffs.

export LINT2HUB_GITHUB_ACCESS_TOKEN="abc123"
lint2hub -owner alindeman \
  -repo lint2hub \
  -pull-request 1234 \
  -sha "adc83b19e793491b1c6ea0fd8b46cd9f32e592fc" \
  -file "foo.go" \
  -line 8 \
  -body "exported method Foo.Bar should have comment or be unexported"

lint2hub can also accept linter output from standard input, parsed with a custom regular expression to extract file, line and comment body. For instance, to pipe gometalinter:

gometalinter ./... |
  lint2hub -owner alindeman \
    -repo lint2hub \
    -pull-request 1234 \
    -sha "adc83b19e793491b1c6ea0fd8b46cd9f32e592fc" \
    -pattern '^(?P<file>[^:]+):(?P<line>\d+):(?P<column>\d*):(\S+:)* (?P<body>.*)$'

Documentation

Overview

Package lint2hub automates creating GitHub pull requests review comments in response to code linters.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSHANotLatest is returned if the latest pull request SHA does not
	// match the provided SHA
	ErrSHANotLatest = errors.New("latest pull request SHA does not match provided SHA")
)

Functions

This section is empty.

Types

type Commenter

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

Commenter is a high level GitHub client capable of commenting on pull request diffs. It caches the diff at a particular SHA and also attempts to prevent duplicate line comments from being posted.

func NewCommenter

func NewCommenter(ctx context.Context, gh *github.Client, owner string, repo string, prNumber int, sha string) (*Commenter, error)

NewCommenter creates a new commenting client. If the provided sha is not the latest SHA, ErrSHANotLatest is returned to avoid commenting on an outdated diff.

func (*Commenter) GetPosition

func (c *Commenter) GetPosition(file string, lineNum int) (position int, ok bool)

GetPosition retrieves the diff position for a given file and lineNum. Returns (0, false) if the position is not present in the diff, meaning a comment cannot be posted on that lineNum within the pull request.

func (*Commenter) Post

func (c *Commenter) Post(ctx context.Context, file string, position int, body string) error

Post posts a comment at the given file and position. If a comment with the same body is already present at that position, Post does nothing.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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