github

package
v0.0.0-...-8fc2537 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Key is a name of the github plugin variable
	Key                  = Namespace("github")
	KeyWatchPullRequests = "PullRequests"
	KeyWatchBranches     = "Branches"
	KeySetup             = "Setup"
	KeyPostStatusOf      = "PostStatusOf"
	KeyPostStatus        = "PostStatusOf"
)
View Source
const (
	// KeyCommit is a commit used in logs
	KeyCommit = "commit"
	// KeyBranch
	KeyBranch = "branch"
	// KeyPR is a pull request key used in logs
	KeyPR = "pr"
)
View Source
const (
	StateSuccess = "success"
	StatePending = "pending"
	StateFailure = "failure"
	StateError   = "error"

	DefaultContext = "Force CI"
)
View Source
const (
	// MasterBranch is a default github master branch to watch
	MasterBranch = "master"
)

Variables

This section is empty.

Functions

func Github

func Github(cfg interface{}) (force.Action, error)

Github creates a new action setting up a github plugin

func Scope

func Scope() (force.Group, error)

Scope returns a new scope with all the functions and structs defined, this is the entrypoint into plugin as far as force is concerned

Types

type Approval

type Approval struct {
	Required bool
	Teams    []string
	Pattern  string
}

Approval configures approval flow

func (*Approval) Regexp

func (a *Approval) Regexp() (*regexp.Regexp, error)

Regexp returns approval regexp

type Branch

type Branch struct {
	RefObject
	CommitObject
}

Branch represents a branch that was updated

type BranchEvent

type BranchEvent struct {
	Commit force.String
	Branch force.String

	Source Source
	// contains filtered or unexported fields
}

BranchEvent is a commit event

func (*BranchEvent) AddMetadata

func (r *BranchEvent) AddMetadata(ctx force.ExecutionContext)

AddMetadata adds metadata to the logger and the context, such as commit id and PR number

func (*BranchEvent) Created

func (r *BranchEvent) Created() time.Time

Created returns a time when the event was originated

func (*BranchEvent) GetCommit

func (r *BranchEvent) GetCommit() string

GetCommit returns commit associated with the event

func (*BranchEvent) GetSource

func (r *BranchEvent) GetSource() Source

GetSource returns source associated with the event

func (*BranchEvent) String

func (r *BranchEvent) String() string

type BranchWatcher

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

BranchWatcher is a repository watcher

func (*BranchWatcher) Done

func (r *BranchWatcher) Done() <-chan struct{}

Done returns channel closed when repository watcher is closed

func (*BranchWatcher) Events

func (r *BranchWatcher) Events() <-chan force.Event

Events returns events stream on a repository

func (*BranchWatcher) MarshalCode

func (r *BranchWatcher) MarshalCode(ctx force.ExecutionContext) ([]byte, error)

MarshalCode marshals things to code

func (*BranchWatcher) Start

func (r *BranchWatcher) Start(pctx context.Context) error

Start starts watch on a repo

func (*BranchWatcher) String

func (r *BranchWatcher) String() string

String returns user friendly representation of the watcher

type CommentObject

type CommentObject struct {
	ID        string
	CreatedAt githubv4.DateTime
	UpdatedAt githubv4.DateTime
	Body      string
	Author    struct {
		Login string
	}
}

CommentObject represents the GraphQL commit node. https://developer.github.com/v4/object/commit/

type CommitGetter

type CommitGetter interface {
	// GetCommit returns commit associated with the event
	GetCommit() string
	// GetSource returns source associated with the event
	GetSource() Source
}

type CommitObject

type CommitObject struct {
	ID            string
	OID           string
	CommittedDate githubv4.DateTime
	Message       string
	Author        struct {
		User struct {
			Login string
		}
	}
}

CommitObject represents the GraphQL commit node. https://developer.github.com/v4/object/commit/

type Config

type Config struct {
	// Token is an access token
	Token string
	// TokenFile is a path to access token
	TokenFile string
}

Config is a github plugin config

func (*Config) CheckAndSetDefaults

func (cfg *Config) CheckAndSetDefaults() error

CheckAndSetDefaults checks and sets default values

type GithubClient

type GithubClient struct {
	V3 *github.Client
	V4 *githubv4.Client
}

GithubClient for handling requests to the Github V3 and V4 APIs.

func (*GithubClient) GetBranches

func (m *GithubClient) GetBranches(ctx context.Context, repo Repository, path string) ([]Branch, error)

GetBranches gets the last commit on branches with changes matching the path

func (*GithubClient) GetOpenPullRequests

func (m *GithubClient) GetOpenPullRequests(ctx context.Context, repo Repository) ([]PullRequest, error)

GetOpenPullRequests gets the last commit on all open pull requests.

func (*GithubClient) GetPullRequestComments

func (m *GithubClient) GetPullRequestComments(ctx context.Context, repo Repository, prNumber int) ([]CommentObject, error)

GetPullRequestComments returns PR comments

func (*GithubClient) GetTeamMembers

func (m *GithubClient) GetTeamMembers(ctx context.Context, org, slug string) ([]UserObject, error)

GetTeamMembers returns all team members for a given org

func (*GithubClient) ListModifiedFiles

func (m *GithubClient) ListModifiedFiles(repo Repository, prNumber int) ([]string, error)

ListModifiedFiles in a pull request (not supported by V4 API).

func (*GithubClient) PostComment

func (m *GithubClient) PostComment(repo Repository, prNumber, comment string) error

PostComment to a pull request or issue.

func (*GithubClient) UpdateCommitStatus

func (m *GithubClient) UpdateCommitStatus(repo Repository, commitRef, baseContext, statusContext, status, targetURL, description string) error

UpdateCommitStatus for a given commit (not supported by V4 API).

type Namespace

type Namespace string

Namespace is a wrapper around string to namespace a variable in the context

type NewBranchWatch

type NewBranchWatch struct {
}

NewBranchWatch finds the initialized github plugin and returns a new commit watch

func (*NewBranchWatch) NewInstance

func (n *NewBranchWatch) NewInstance(group force.Group) (force.Group, interface{})

NewInstance returns a function creating new watchers

type NewPostStatus

type NewPostStatus struct {
}

NewPostStatus creates actions that posts new status

func (*NewPostStatus) NewInstance

func (n *NewPostStatus) NewInstance(group force.Group) (force.Group, interface{})

NewInstance returns a function that creates new post status actions

type NewPostStatusOf

type NewPostStatusOf struct {
}

NewPostStatusOf returns a function that wraps underlying action and tracks the result, posting the result back

func (*NewPostStatusOf) NewInstance

func (n *NewPostStatusOf) NewInstance(group force.Group) (force.Group, interface{})

NewInstance returns a function creating new post status actions

type NewPullRequestWatch

type NewPullRequestWatch struct {
}

NewPullRequestWatch finds the initialized github plugin and returns a new watch

func (*NewPullRequestWatch) NewInstance

func (n *NewPullRequestWatch) NewInstance(group force.Group) (force.Group, interface{})

NewInstance returns a function creating new watchers

type Plugin

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

Plugin is a new plugin

type PostStatusAction

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

PostStatusAction posts github status

func (*PostStatusAction) Eval

func (p *PostStatusAction) Eval(ctx force.ExecutionContext) (interface{}, error)

Run posts github status

func (*PostStatusAction) MarshalCode

func (p *PostStatusAction) MarshalCode(ctx force.ExecutionContext) ([]byte, error)

MarshalCode marshals the action into code representation

func (*PostStatusAction) Type

func (p *PostStatusAction) Type() interface{}

type PostStatusOfAction

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

PostStatusOfAction executes an action and posts its status to the github

func (*PostStatusOfAction) Eval

func (p *PostStatusOfAction) Eval(ctx force.ExecutionContext) (interface{}, error)

func (*PostStatusOfAction) MarshalCode

func (p *PostStatusOfAction) MarshalCode(ctx force.ExecutionContext) ([]byte, error)

MarshalCode marshals the action into code representation

func (*PostStatusOfAction) Type

func (p *PostStatusOfAction) Type() interface{}

type PullRequest

type PullRequest struct {
	PullRequestObject
	LastCommit  CommitObject
	LastComment CommentObject
}

PullRequest represents a pull request and includes the last commit and the last comment

func (*PullRequest) LastUpdated

func (p *PullRequest) LastUpdated() time.Time

LastUpdated returns either the last commit date or the last comment date whatever happened later

type PullRequestEvent

type PullRequestEvent struct {
	PR          force.Int
	Commit      force.String
	Source      Source
	PullRequest PullRequest
	// contains filtered or unexported fields
}

PullRequestEvent is a pull request event

func (*PullRequestEvent) AddMetadata

func (r *PullRequestEvent) AddMetadata(ctx force.ExecutionContext)

AddMetadata adds metadata to the logger and the context, such as commit id and PR number

func (*PullRequestEvent) Created

func (r *PullRequestEvent) Created() time.Time

Created returns a time when the event was originated

func (*PullRequestEvent) GetCommit

func (r *PullRequestEvent) GetCommit() string

GetCommit returns commit associated with the event

func (*PullRequestEvent) GetSource

func (r *PullRequestEvent) GetSource() Source

GetSource returns source associated with the event

func (*PullRequestEvent) String

func (r *PullRequestEvent) String() string

type PullRequestObject

type PullRequestObject struct {
	ID          string
	Number      int
	Title       string
	URL         string
	BaseRefName string
	HeadRefName string
	Repository  struct {
		URL string
	}
	IsCrossRepository bool
}

PullRequestObject represents the GraphQL commit node. https://developer.github.com/v4/object/pullrequest/

type PullRequestWatcher

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

PullRequestWatcher is a repository watcher

func (*PullRequestWatcher) Done

func (r *PullRequestWatcher) Done() <-chan struct{}

Done returns channel closed when repository watcher is closed

func (*PullRequestWatcher) Events

func (r *PullRequestWatcher) Events() <-chan force.Event

Events returns events stream on a repository

func (*PullRequestWatcher) MarshalCode

func (r *PullRequestWatcher) MarshalCode(ctx force.ExecutionContext) ([]byte, error)

MarshalCode marshals things to code

func (*PullRequestWatcher) Start

func (r *PullRequestWatcher) Start(pctx context.Context) error

Start starts watch on a repo

func (*PullRequestWatcher) String

func (r *PullRequestWatcher) String() string

String returns user friendly representation of the watcher

type RefObject

type RefObject struct {
	ID     string
	Name   string
	Prefix string
}

RefObject represents the GraphQL ref node https://developer.github.com/v4/object/ref/

type Repository

type Repository struct {
	// Owner is a repository owner
	Owner string
	// Name is a repository name
	Name string
}

Repository is a github repository

type Setup

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

Setup creates new instances of plugins

func (*Setup) Eval

func (n *Setup) Eval(ctx force.ExecutionContext) (interface{}, error)

func (*Setup) MarshalCode

func (n *Setup) MarshalCode(ctx force.ExecutionContext) ([]byte, error)

MarshalCode marshals plugin setup to code representation

func (*Setup) NewInstance

func (n *Setup) NewInstance(group force.Group) (force.Group, interface{})

NewInstance returns a new instance

func (*Setup) Type

func (n *Setup) Type() interface{}

type Source

type Source struct {
	// Repo is a repository name to watch
	Repo string
	// BranchPattern is a branch regexp pattern to watch PRs against
	BranchPattern string
	// Approval sets up approval process
	Approval Approval
	// Trigger configures trigger
	Trigger Trigger
	// Path filters out commits without changes matching the path (directory)
	Path string
}

Source is a source repository to watch

func (*Source) BranchRegexp

func (s *Source) BranchRegexp() (*regexp.Regexp, error)

BranchRegexp returns branch match regexp

func (*Source) CheckAndSetDefaults

func (s *Source) CheckAndSetDefaults() error

CheckAndSetDefaults checks and sets default values

func (Source) Repository

func (s Source) Repository() (*Repository, error)

Repository returns repository address

type Status

type Status struct {
	// State is a PR state
	State string
	// URL is a url of this web app, force should provide a web interface
	URL string
	// Description is an optional description
	Description string
	// Context is a special label that differentiates this application
	Context string
}

func (*Status) CheckAndSetDefaults

func (s *Status) CheckAndSetDefaults() error

func (Status) String

func (s Status) String() string

type Trigger

type Trigger struct {
	Disabled bool
	// RetestPattern triggers retest on a pattern
	RetestPattern string
	// SkipPattern skips pull request test
	SkipPattern string
}

Trigger sets up additional testing triggers

func (*Trigger) RetestRegexp

func (a *Trigger) RetestRegexp() (*regexp.Regexp, error)

RetestRegexp returns retest regexp

func (*Trigger) SkipRegexp

func (a *Trigger) SkipRegexp() (*regexp.Regexp, error)

SkipRegexp returns skip match regexp

type UserObject

type UserObject struct {
	Login string
}

UserObject is graphql user node

Jump to

Keyboard shortcuts

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