core

package
v2.0.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name        = "gitrob"
	Version     = "2.0.0-beta"
	Author      = "Michael Henriksen"
	Website     = "https://github.com/michenriksen/gitrob"
	ASCIIBanner = "        _ __           __\n" +
		"  ___ _(_) /________  / /\n" +
		" / _ `/ / __/ __/ _ \\/ _ \\\n" +
		" \\_, /_/\\__/_/  \\___/_.__/\n" +
		"/___/ by @michenriksen"
)
View Source
const (
	FATAL     = 5
	ERROR     = 4
	WARN      = 3
	IMPORTANT = 2
	INFO      = 1
	DEBUG     = 0
)
View Source
const (
	GithubBaseUri   = "https://raw.githubusercontent.com"
	MaximumFileSize = 102400
	CspPolicy       = "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'"
	ReferrerPolicy  = "no-referrer"
)
View Source
const (
	AccessTokenEnvVariable = "GITROB_ACCESS_TOKEN"

	StatusInitializing = "initializing"
	StatusGathering    = "gathering"
	StatusAnalyzing    = "analyzing"
	StatusFinished     = "finished"
)
View Source
const (
	TypeSimple  = "simple"
	TypePattern = "pattern"

	PartExtension = "extension"
	PartFilename  = "filename"
	PartPath      = "path"
)
View Source
const (
	EmptyTreeCommitId = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
)

Variables

View Source
var NewlineRegex = regexp.MustCompile(`\r?\n`)
View Source
var Signatures = []Signature{
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	SimpleSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
	PatternSignature{
		// contains filtered or unexported fields
	},
}

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func BinaryFileSystem

func BinaryFileSystem(root string) *binaryFileSystem

func CloneRepository

func CloneRepository(url *string, branch *string, depth int) (*git.Repository, string, error)

func FileExists

func FileExists(path string) bool

func GetChangeAction

func GetChangeAction(change *object.Change) string

func GetChangePath

func GetChangePath(change *object.Change) string

func GetChanges

func GetChanges(commit *object.Commit, repo *git.Repository) (object.Changes, error)

func GetParentCommit

func GetParentCommit(commit *object.Commit, repo *git.Repository) (*object.Commit, error)

func GetRepositoryHistory

func GetRepositoryHistory(repository *git.Repository) ([]*object.Commit, error)

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewRouter

func NewRouter(s *Session) *gin.Engine

func Pluralize

func Pluralize(count int, singular string, plural string) string

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func TruncateString

func TruncateString(str string, maxLength int) string

Types

type Finding

type Finding struct {
	Id              string
	FilePath        string
	Action          string
	Description     string
	Comment         string
	RepositoryOwner string
	RepositoryName  string
	CommitHash      string
	CommitMessage   string
	CommitAuthor    string
	FileUrl         string
	CommitUrl       string
	RepositoryUrl   string
}

func (*Finding) Initialize

func (f *Finding) Initialize()

type GithubOwner

type GithubOwner struct {
	Login     *string
	ID        *int
	Type      *string
	Name      *string
	AvatarURL *string
	URL       *string
	Company   *string
	Blog      *string
	Location  *string
	Email     *string
	Bio       *string
}

func GetOrganizationMembers

func GetOrganizationMembers(login *string, client *github.Client) ([]*GithubOwner, error)

func GetUserOrOrganization

func GetUserOrOrganization(login string, client *github.Client) (*GithubOwner, error)

type GithubRepository

type GithubRepository struct {
	Owner         *string
	ID            *int
	Name          *string
	FullName      *string
	CloneURL      *string
	URL           *string
	DefaultBranch *string
	Description   *string
	Homepage      *string
}

func GetRepositoriesFromOwner

func GetRepositoriesFromOwner(login *string, client *github.Client) ([]*GithubRepository, error)

type Logger

type Logger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(format string, args ...interface{})

func (*Logger) Important

func (l *Logger) Important(format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

func (*Logger) Log

func (l *Logger) Log(level int, format string, args ...interface{})

func (*Logger) SetDebug

func (l *Logger) SetDebug(d bool)

func (*Logger) SetSilent

func (l *Logger) SetSilent(s bool)

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...interface{})

type MatchFile

type MatchFile struct {
	Path      string
	Filename  string
	Extension string
}

func NewMatchFile

func NewMatchFile(path string) MatchFile

type Options

type Options struct {
	CommitDepth       *int
	GithubAccessToken *string `json:"-"`
	NoExpandOrgs      *bool
	Threads           *int
	Save              *string `json:"-"`
	Load              *string `json:"-"`
	BindAddress       *string
	Port              *int
	Silent            *bool
	Debug             *bool
	Logins            []string
}

func ParseOptions

func ParseOptions() (Options, error)

type PatternSignature

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

func (PatternSignature) Comment

func (s PatternSignature) Comment() string

func (PatternSignature) Description

func (s PatternSignature) Description() string

func (PatternSignature) Match

func (s PatternSignature) Match(file MatchFile) bool

type Session

type Session struct {
	sync.Mutex

	Version           string
	Options           Options `json:"-"`
	Out               *Logger `json:"-"`
	Stats             *Stats
	GithubAccessToken string         `json:"-"`
	GithubClient      *github.Client `json:"-"`
	Router            *gin.Engine    `json:"-"`
	Targets           []*GithubOwner
	Repositories      []*GithubRepository
	Findings          []*Finding
}

func NewSession

func NewSession() (*Session, error)

func (*Session) AddFinding

func (s *Session) AddFinding(finding *Finding)

func (*Session) AddRepository

func (s *Session) AddRepository(repository *GithubRepository)

func (*Session) AddTarget

func (s *Session) AddTarget(target *GithubOwner)

func (*Session) Finish

func (s *Session) Finish()

func (*Session) InitGithubAccessToken

func (s *Session) InitGithubAccessToken()

func (*Session) InitGithubClient

func (s *Session) InitGithubClient()

func (*Session) InitLogger

func (s *Session) InitLogger()

func (*Session) InitRouter

func (s *Session) InitRouter()

func (*Session) InitStats

func (s *Session) InitStats()

func (*Session) InitThreads

func (s *Session) InitThreads()

func (*Session) SaveToFile

func (s *Session) SaveToFile(location string) error

func (*Session) Start

func (s *Session) Start()

type Signature

type Signature interface {
	Match(file MatchFile) bool
	Description() string
	Comment() string
}

type SimpleSignature

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

func (SimpleSignature) Comment

func (s SimpleSignature) Comment() string

func (SimpleSignature) Description

func (s SimpleSignature) Description() string

func (SimpleSignature) Match

func (s SimpleSignature) Match(file MatchFile) bool

type Stats

type Stats struct {
	sync.Mutex

	StartedAt    time.Time
	FinishedAt   time.Time
	Status       string
	Progress     float64
	Targets      int
	Repositories int
	Commits      int
	Files        int
	Findings     int
}

func (*Stats) IncrementCommits

func (s *Stats) IncrementCommits()

func (*Stats) IncrementFiles

func (s *Stats) IncrementFiles()

func (*Stats) IncrementFindings

func (s *Stats) IncrementFindings()

func (*Stats) IncrementRepositories

func (s *Stats) IncrementRepositories()

func (*Stats) IncrementTargets

func (s *Stats) IncrementTargets()

func (*Stats) UpdateProgress

func (s *Stats) UpdateProgress(current int, total int)

Jump to

Keyboard shortcuts

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