server

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogFileLocation

func GetLogFileLocation(fileLocation string) string

func NewBool

func NewBool(b bool) *bool

func NewInt

func NewInt(n int) *int

func NewInt32

func NewInt32(n int32) *int32

func NewInt64

func NewInt64(n int64) *int64

func NewString

func NewString(s string) *string

func PingEventFromJSON

func PingEventFromJSON(data io.Reader) *github.PingEvent

func SetupLogging

func SetupLogging(config *Config) error

Types

type BlockPathValidationError added in v0.2.7

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

func (*BlockPathValidationError) BlockListFiles added in v0.2.7

func (e *BlockPathValidationError) BlockListFiles() []string

BlockListFiles return an array of block files

func (*BlockPathValidationError) Error added in v0.2.7

func (e *BlockPathValidationError) Error() string

Error implements the error interface.

func (*BlockPathValidationError) ReportBlockFiles added in v0.2.7

func (e *BlockPathValidationError) ReportBlockFiles() string

ReportBlockFiles return a message based on how many files are in the block list to be send out

type BuildMobileAppJob

type BuildMobileAppJob struct {
	JobName           string
	ExpectedArtifacts int
}

type Builds

type Builds struct{}

Builds implements buildsInterface for working with external CI/CD systems.

type ChecksService

type ChecksService interface {
	ListCheckRunsForRef(ctx context.Context, owner, repo, ref string, opts *github.ListCheckRunsOptions) (*github.ListCheckRunsResults, *github.Response, error)
}

type CircleCIService added in v0.2.9

type CircleCIService interface {
	// ListRecentBuildsForProject fetches the list of recent builds for the given repository
	// The status and branch parameters are used to further filter results if non-empty
	// If limit is -1, fetches all builds.
	ListRecentBuildsForProjectWithContext(ctx context.Context, vcsType circleci.VcsType, account, repo, branch, status string, limit, offset int) ([]*circleci.Build, error)
	// BuildByProjectWithContext triggers a build by project.
	BuildByProjectWithContext(ctx context.Context, vcsType circleci.VcsType, account, repo string, opts map[string]interface{}) error
	// ListBuildArtifactsWithContext fetches the build artifacts for the given build.
	ListBuildArtifactsWithContext(ctx context.Context, vcsType circleci.VcsType, account, repo string, buildNum int) ([]*circleci.Artifact, error)
	// TriggerPipeline triggers a new pipeline for the given project for the given branch or tag.
	TriggerPipelineWithContext(ctx context.Context, vcsType circleci.VcsType, account, repo, branch, tag string, params map[string]interface{}) (*circleci.Pipeline, error)
	// GetPipelineWorkflowWithContext returns a list of paginated workflows by pipeline ID
	GetPipelineWorkflowWithContext(ctx context.Context, pipelineID, pageToken string) (*circleci.WorkflowList, error)
}

CircleCIService exposes an interface of CircleCI client. Useful to mock in tests.

type Config

type Config struct {
	ListenAddress               string
	MattermodURL                string
	GithubAccessToken           string
	GitHubTokenReserve          int
	GithubUsername              string
	GithubAccessTokenCherryPick string
	GitHubWebhookSecret         string
	Org                         string
	Username                    string
	AutoAssignerTeam            string
	AutoAssignerTeamID          int64
	CircleCIToken               string

	TickRateMinutes        int
	SpinmintExpirationHour int

	DriverName string
	DataSource string

	Repositories []*Repository

	BlockPRMergeLabels []string
	AutoPRMergeLabel   string

	SetupSpinmintTag                   string
	SetupSpinmintMessage               string
	SetupSpinmintDoneMessage           string
	SetupSpinmintFailedMessage         string
	DestroyedSpinmintMessage           string
	DestroyedExpirationSpinmintMessage string
	SpinmintsUseHTTPS                  bool

	SetupSpinmintUpgradeTag         string
	SetupSpinmintUpgradeMessage     string
	SetupSpinmintUpgradeDoneMessage string

	BuildMobileAppTag           string
	BuildMobileAppInitMessage   string
	BuildMobileAppDoneMessage   string
	BuildMobileAppFailedMessage string
	BuildMobileAppBranchPrefix  string
	BuildMobileAppJobs          []*BuildMobileAppJob

	EnterpriseReponame            string
	EnterpriseTriggerReponame     string
	EnterpriseWebappReponame      string
	EnterpriseTriggerLabel        string
	EnterpriseGithubStatusContext string
	EnterpriseGithubStatusTETests string
	EnterpriseGithubStatusEETests string
	EnterpriseWorkflowName        string

	TranslationsMattermostWebhookURL string
	TranslationsMattermostMessage    string
	TranslationsBot                  string

	StartLoadtestTag     string
	StartLoadtestMessage string

	CLAExclusionsList      []string
	CLAGithubStatusContext string

	SignedCLAURL          string
	NeedsToSignCLAMessage string

	PrLabels    []LabelResponse
	IssueLabels []LabelResponse

	IssueLabelsToCleanUp []string

	JenkinsCredentials map[string]*JenkinsCredentials

	DockerRegistryURL string
	DockerUsername    string
	DockerPassword    string

	BlockListPathsGlobal  []string
	BlockListPathsPerRepo map[string][]string // BlockListPathsPerRepo is a per repository list of blocked files

	AWSCredentials struct {
		ID     string
		Secret string
		Token  string
	}

	AWSRegion        string
	AWSImageID       string
	AWSKeyName       string
	AWSInstanceType  string
	AWSHostedZoneID  string
	AWSSecurityGroup string
	AWSDnsSuffix     string
	AWSSubNetID      string

	MattermostWebhookURL    string
	MattermostWebhookFooter string

	LogSettings struct {
		EnableConsole   bool
		ConsoleJSON     bool
		ConsoleLevel    string
		EnableFile      bool
		FileJSON        bool
		FileLevel       string
		FileLocation    string
		AdvancedLogging mlog.LogTargetCfg
	}

	DaysUntilStale    int
	ExemptStaleLabels []string
	StaleLabel        string
	StaleComment      string

	MetricsServerPort string

	RepoFolder    string // folder containing local checkouts of repositories for cherry-picking
	ScriptsFolder string // folder containing the cherry-pick.sh script
}

func GetConfig

func GetConfig(fileName string) (*Config, error)

type EETriggerInfo

type EETriggerInfo struct {
	BaseBranch   string
	EEBranch     string
	ServerOwner  string
	ServerBranch string
	WebappOwner  string
	WebappBranch string
}

type GitService

type GitService interface {
	CreateRef(ctx context.Context, owner string, repo string, ref *github.Reference) (*github.Reference, *github.Response, error)
	DeleteRef(ctx context.Context, owner string, repo string, ref string) (*github.Response, error)
	GetRef(ctx context.Context, owner string, repo string, ref string) (*github.Reference, *github.Response, error)
}

type GithubClient

type GithubClient struct {
	Checks        ChecksService
	Git           GitService
	Issues        IssuesService
	Organizations OrganizationsService
	PullRequests  PullRequestsService
	Repositories  RepositoriesService
	// contains filtered or unexported fields
}

GithubClient wraps the github.Client with relevant interfaces.

func NewGithubClient

func NewGithubClient(accessToken string, limitTokens int, metrics MetricsProvider) (*GithubClient, error)

NewGithubClient returns a new Github client that will use a fixed 10 req/sec / 10 burst tokens rate limiter configuration

func NewGithubClientWithLimiter

func NewGithubClientWithLimiter(accessToken string, limit rate.Limit, burstTokens int, metricsProvider MetricsProvider) *GithubClient

NewGithubClientWithLimiter returns a new Github client with the provided limit and burst tokens that will be used by the rate limit transport.

func (*GithubClient) RateLimits

func (c *GithubClient) RateLimits(ctx context.Context) (*github.RateLimits, *github.Response, error)

type Integration

type Integration struct {
	RepositoryName  string
	Files           []string
	IntegrationLink string
	Message         string
}

type IssuesService

type IssuesService interface {
	AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*github.Issue, *github.Response, error)
	AddLabelsToIssue(ctx context.Context, owner string, repo string, number int, labels []string) ([]*github.Label, *github.Response, error)
	CreateComment(ctx context.Context, owner string, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
	DeleteComment(ctx context.Context, owner string, repo string, commentID int64) (*github.Response, error)
	Edit(ctx context.Context, owner string, repo string, number int, issue *github.IssueRequest) (*github.Issue, *github.Response, error)
	Get(ctx context.Context, owner string, repo string, number int) (*github.Issue, *github.Response, error)
	ListByRepo(ctx context.Context, owner string, repo string, opts *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error)
	ListComments(ctx context.Context, owner string, repo string, number int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)
	ListLabelsByIssue(ctx context.Context, owner string, repo string, number int, opt *github.ListOptions) ([]*github.Label, *github.Response, error)
	RemoveLabelForIssue(ctx context.Context, owner string, repo string, number int, label string) (*github.Response, error)
}

type JenkinsCredentials

type JenkinsCredentials struct {
	URL      string
	Username string
	APIToken string
}

type LabelResponse

type LabelResponse struct {
	Label   string
	Message string
}

type MetricsProvider

type MetricsProvider interface {
	// ObserverHTTPRequestDuration stores the elapsed time for an HTTP request
	ObserveHTTPRequestDuration(method, handler, statusCode string, elapsed float64)
	// IncreaseWebhookRequest increases the counter for the webhook requests
	// identified by name
	IncreaseWebhookRequest(name string)
	// IncreaseWebhookErrors stores the number of errors identified by name
	IncreaseWebhookErrors(name string)

	// ObserveGithubRequestDuration stores the elapsed time for github requests
	ObserveGithubRequestDuration(method, handler, statusCode string, elapsed float64)
	// IncreaseGithubCacheHits stores the number of cache hits when a github request
	// is done. The information is stored using the HTTP method and the request handler
	IncreaseGithubCacheHits(method, handler string)
	// IncreaseGithubCacheMisses stores the number of cache misses when a github request
	// is done. The information is stored using the HTTP method and the request handler
	IncreaseGithubCacheMisses(method, handler string)

	// IncreaseRateLimiterErrors stores the number of errors received when trying to
	// rate limit the requests
	IncreaseRateLimiterErrors()

	// ObserverCronTaskDuration stores the elapsed time for a cron task
	ObserveCronTaskDuration(name string, elapsed float64)
	// IncreaseCronTaskErrors stores the number of errors for a cron task
	IncreaseCronTaskErrors(name string)
}

MetricsProvider is the interface that exposes the communication with the metrics system this interface should be implemented by the different providers we want to include

type MetricsTransport

type MetricsTransport struct {
	Base http.RoundTripper
	// contains filtered or unexported fields
}

Transport is an HTTP transport that would check the requests and increase some metrics, cache errors, etc based on the requests and responses

func NewMetricsTransport

func NewMetricsTransport(base http.RoundTripper, metrics MetricsProvider) *MetricsTransport

NewTransport returns a transport using a provided http.RoundTripper as the base and a metrics provider

func (*MetricsTransport) Client

func (t *MetricsTransport) Client() *http.Client

Client returns a new http.Client using Transport as the default transport

func (*MetricsTransport) RoundTrip

func (t *MetricsTransport) RoundTrip(req *http.Request) (resp *http.Response, err error)

type MockedBuilds

type MockedBuilds struct {
	Version string
}

MockedBuilds implements buildsInterface but returns hardcoded information. This is used for local development and/or testing.

type OrganizationsService

type OrganizationsService interface {
	GetOrgMembership(ctx context.Context, user, org string) (*github.Membership, *github.Response, error)
	IsMember(ctx context.Context, org, user string) (bool, *github.Response, error)
	ListMembers(ctx context.Context, org string, opts *github.ListMembersOptions) ([]*github.User, *github.Response, error)
}

type Payload

type Payload struct {
	Username string `json:"username"`
	Text     string `json:"text"`
}

type PullRequestEvent

type PullRequestEvent struct {
	Action        string              `json:"action"`
	PRNumber      int                 `json:"number"`
	PullRequest   *github.PullRequest `json:"pull_request"`
	Issue         *github.Issue       `json:"issue"`
	Label         *github.Label       `json:"label"`
	Repo          *github.Repository  `json:"repository"`
	RepositoryURL string              `json:"repository_url"`
}

func PullRequestEventFromJSON

func PullRequestEventFromJSON(data io.Reader) *PullRequestEvent

type PullRequestsService

type PullRequestsService interface {
	Get(ctx context.Context, owner string, repo string, number int) (*github.PullRequest, *github.Response, error)
	List(ctx context.Context, owner string, repo string, opts *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error)
	ListFiles(ctx context.Context, owner string, repo string, number int, opts *github.ListOptions) ([]*github.CommitFile, *github.Response, error)
	ListReviewers(ctx context.Context, owner, repo string, number int, opts *github.ListOptions) (*github.Reviewers, *github.Response, error)
	ListReviews(ctx context.Context, owner, repo string, number int, opts *github.ListOptions) ([]*github.PullRequestReview, *github.Response, error)
	Merge(ctx context.Context, owner string, repo string, number int, commitMessage string, options *github.PullRequestOptions) (*github.PullRequestMergeResult, *github.Response, error)
	RequestReviewers(ctx context.Context, owner, repo string, number int, reviewers github.ReviewersRequest) (*github.PullRequest, *github.Response, error)
	UpdateBranch(ctx context.Context, owner, repo string, number int, opts *github.PullRequestBranchUpdateOptions) (*github.PullRequestBranchUpdateResponse, *github.Response, error)
}

type RateLimitTransport

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

RateLimitTransport will provide a layer based on http.RounTripper interface that provided rate limiting capability

func NewRateLimitTransport

func NewRateLimitTransport(limit rate.Limit, tokens int, base http.RoundTripper, metrics MetricsProvider) *RateLimitTransport

NewRateLimitTransport will return a new transport that provides rate limiting capability based on the provided limit and burst tokens. It also needs the base RountTripper that will be called in case the rate limit is not needed

func (*RateLimitTransport) RoundTrip

func (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error)

type RepositoriesService

type RepositoriesService interface {
	CreateStatus(ctx context.Context, owner, repo, ref string, status *github.RepoStatus) (*github.RepoStatus, *github.Response, error)
	Get(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error)
	GetBranch(ctx context.Context, owner, repo, branch string) (*github.Branch, *github.Response, error)
	GetCombinedStatus(ctx context.Context, owner, repo, ref string, opts *github.ListOptions) (*github.CombinedStatus, *github.Response, error)
	ListTeams(ctx context.Context, owner string, repo string, opts *github.ListOptions) ([]*github.Team, *github.Response, error)
	ListStatuses(ctx context.Context, owner, repo, ref string, opts *github.ListOptions) ([]*github.RepoStatus, *github.Response, error)
}

type Repository

type Repository struct {
	Owner                      string
	Name                       string
	BuildStatusContext         string
	JenkinsServer              string
	InstanceSetupScript        string
	InstanceSetupUpgradeScript string
	JobName                    string
}

func GetRepository

func GetRepository(repositories []*Repository, owner, name string) (*Repository, bool)

type Server

type Server struct {
	Config           *Config
	Store            store.Store
	GithubClient     *GithubClient
	CircleCiClient   CircleCIService
	CircleCiClientV2 CircleCIService
	OrgMembers       []string
	Builds           buildsInterface

	StartTime time.Time

	Metrics MetricsProvider
	// contains filtered or unexported fields
}

Server is the mattermod server.

func New

func New(config *Config, metrics MetricsProvider) (*Server, error)

func (*Server) AutoMergePR

func (s *Server) AutoMergePR() error

func (*Server) CheckPRActivity

func (s *Server) CheckPRActivity()

func (*Server) CheckTestServerLifeTime

func (s *Server) CheckTestServerLifeTime()

CheckTestServerLifeTime checks the age of the test server and kills if reach the limit

func (*Server) CleanOutdatedPRs

func (s *Server) CleanOutdatedPRs()

func (*Server) CleanUpLabels

func (s *Server) CleanUpLabels(pr *model.PullRequest)

func (*Server) GetAwsConfig

func (s *Server) GetAwsConfig() *aws.Config

func (*Server) GetIssueFromGithub

func (s *Server) GetIssueFromGithub(ctx context.Context, ghIssue *github.Issue) (*model.Issue, error)

func (*Server) GetPullRequestFromGithub

func (s *Server) GetPullRequestFromGithub(ctx context.Context, pullRequest *github.PullRequest) (*model.PullRequest, error)

func (*Server) GetUpdateChecks

func (s *Server) GetUpdateChecks(ctx context.Context, owner, repoName string, prNumber int) (*model.PullRequest, error)

func (*Server) IsBotUserFromCLAExclusionsList

func (s *Server) IsBotUserFromCLAExclusionsList(user string) bool

func (*Server) IsOrgMember

func (s *Server) IsOrgMember(user string) bool

func (*Server) RefreshMembers

func (s *Server) RefreshMembers()

func (*Server) Start

func (s *Server) Start()

Start starts a server

func (*Server) Stop

func (s *Server) Stop() error

Stop stops a server

func (*Server) Tick

func (s *Server) Tick()

Tick runs a check on objects in the database

type WebhookValidationError

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

WebhookValidationError contains an error in the webhook payload.

func (*WebhookValidationError) Error

func (e *WebhookValidationError) Error() string

Error implements the error interface.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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