server

package
v0.16.17 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PREventLabeled = "labeled"
)

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(c *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 BuildAppJob added in v0.8.0

type BuildAppJob struct {
	JobName           string
	RepoName          string
	ExpectedArtifacts int
}

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 CloudRepository added in v0.16.10

type CloudRepository struct {
	Name       string
	MainBranch string
}

type Config

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

	TickRateMinutes int

	DriverName string
	DataSource string

	Repositories      []*Repository
	CloudRepositories []*CloudRepository

	BlockPRMergeLabels []string
	AutoPRMergeLabel   string

	BuildAppTag           string
	BuildAppInitMessage   string
	BuildAppDoneMessage   string
	BuildAppFailedMessage string
	BuildAppBranchPrefix  string
	BuildAppJobs          []*BuildAppJob

	E2EDockerRepo                 string
	E2EGitLabProject              string
	E2EWebappRef                  string
	E2EServerRef                  string
	E2EWebappReponame             string
	E2EServerReponame             string
	E2EWebappStatusContext        string
	E2EServerStatusContext        string
	E2ETriggerLabel               []string
	E2ETestAutomationDashboardURL string

	E2EMobileCoreReponame          string
	E2EMobileGitLabProject         string
	E2EMobileGitLabProjectRefForPR string

	E2EDesktopCoreReponame          string
	E2EDesktopGitLabProject         string
	E2EDesktopGitLabProjectRefForPR string

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

	TranslationsMattermostWebhookURL string
	TranslationsMattermostMessage    string
	TranslationsBot                  string
	TranslationsDoNotMergeLabel      string
	TranslationsMergedMessage        string
	TranslationsMergeFailureMessage  string
	TranslationsMergePolicy          string

	StartLoadtestTag     string
	StartLoadtestMessage string

	CLAExclusionsList      []string
	CLAGithubStatusContext string

	SignedCLAURL     string
	PRWelcomeMessage string

	PrLabels    []LabelResponse
	IssueLabels []LabelResponse

	IssueLabelsToCleanUp []string

	BlockListPathsGlobal  []string
	BlockListPathsPerRepo map[string][]string // BlockListPathsPerRepo is a per repository list of blocked files
	BlockListBots         []string            // List of bots who are part of the org, but are not allowed to run slash commands.

	MattermostWebhookURL    string
	MattermostWebhookFooter string

	LogSettings struct {
		ConsoleLevel  string
		FileLevel     string
		FileLocation  string
		EnableConsole bool
		EnableColor   bool
		ConsoleJSON   bool
		EnableFile    bool
		FileJSON      bool
	}

	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
}

nolint:govet

func GetConfig

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

type E2ECancelError added in v0.14.0

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

func (*E2ECancelError) Error added in v0.14.0

func (e *E2ECancelError) Error() string

type E2ETestDesktopError added in v0.16.13

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

func (*E2ETestDesktopError) Error added in v0.16.13

func (e *E2ETestDesktopError) Error() string

type E2ETestDesktopTriggerInfo added in v0.16.13

type E2ETestDesktopTriggerInfo struct {
	TriggerBranch string
	TriggerPR     int
	TriggerRepo   string
	TriggerSHA    string
	RefToTrigger  string
	EnvVars       map[string]string
}

type E2ETestError added in v0.14.0

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

func (*E2ETestError) Error added in v0.14.0

func (e *E2ETestError) Error() string

type E2ETestFromLabelError added in v0.16.2

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

func (*E2ETestFromLabelError) Error added in v0.16.2

func (e *E2ETestFromLabelError) Error() string

type E2ETestMobileError added in v0.16.12

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

func (*E2ETestMobileError) Error added in v0.16.12

func (e *E2ETestMobileError) Error() string

type E2ETestMobileTriggerInfo added in v0.16.12

type E2ETestMobileTriggerInfo struct {
	TriggerBranch string
	TriggerPR     int
	TriggerRepo   string
	TriggerSHA    string
	RefToTrigger  string
	EnvVars       map[string]string
}

type E2ETestTriggerInfo added in v0.14.0

type E2ETestTriggerInfo struct {
	TriggerPR    int
	TriggerRepo  string
	TriggerSHA   string
	RefToTrigger string
	ServerBranch string
	ServerSHA    string
	WebappBranch string
	WebappSHA    string
	EnvVars      map[string]string
}

type EETriggerInfo

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

type GitLabClient added in v0.14.0

type GitLabClient struct {
	Pipelines PipelinesService
	// contains filtered or unexported fields
}

func NewGitLabClient added in v0.14.0

func NewGitLabClient(accessToken string, baseURL string) (*GitLabClient, error)

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)
	GetCommit(ctx context.Context, owner string, repo string, ref string) (*github.Commit, *github.Response, error)
	ListMatchingRefs(ctx context.Context, owner string, repo string, opts *github.ReferenceListOptions) ([]*github.Reference, *github.Response, error)
}

type GithubClient

type GithubClient struct {
	Checks        ChecksService
	Git           GitService
	Issues        IssuesService
	Organizations OrganizationsService
	PullRequests  PullRequestsService
	Repositories  RepositoriesService
	Teams         TeamsService
	// 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
	IntegrationLink string
	Message         string
	Files           []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 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 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 PipelinesService added in v0.14.0

type PipelinesService interface {
	CancelPipelineBuild(pid interface{}, pipeline int, options ...gitlab.RequestOptionFunc) (*gitlab.Pipeline, *gitlab.Response, error)
	CreatePipeline(pid interface{}, opt *gitlab.CreatePipelineOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Pipeline, *gitlab.Response, error)
	GetPipeline(pid interface{}, pipeline int, options ...gitlab.RequestOptionFunc) (*gitlab.Pipeline, *gitlab.Response, error)
	GetPipelineVariables(pid interface{}, pipeline int, options ...gitlab.RequestOptionFunc) ([]*gitlab.PipelineVariable, *gitlab.Response, error)
	ListProjectPipelines(pid interface{}, opt *gitlab.ListProjectPipelinesOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.PipelineInfo, *gitlab.Response, error)
}

PipelinesService exposes an interface of GitLabCI client. Useful to mock in tests.

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)
	CreateReview(ctx context.Context, owner, repo string, number int, review *github.PullRequestReviewRequest) (*github.PullRequestReview, *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, followRedirects bool) (*github.Branch, *github.Response, error)
	ListBranches(ctx context.Context, owner string, repo string, opts *github.BranchListOptions) ([]*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
	InstanceSetupScript        string
	InstanceSetupUpgradeScript string
	JobName                    string
	GreetingTeam               string   // GreetingTeam is the GitHub team responsible for triaging non-member PRs for this repo.
	GreetingLabels             []string // GreetingLabels are the labels applied automatically to non-member PRs for this repo.
}

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
	GitLabCIClientV4 *GitLabClient
	OrgMembers       []string

	StartTime time.Time
	Metrics   MetricsProvider
	// contains filtered or unexported fields
}

Server is the mattermod server. nolint:govet

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) CleanOutdatedCloudBranches added in v0.16.6

func (s *Server) CleanOutdatedCloudBranches()

func (*Server) CleanOutdatedPRs

func (s *Server) CleanOutdatedPRs()

func (*Server) CleanUpLabels

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

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, action string) (*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) IsInBotBlockList added in v0.16.16

func (s *Server) IsInBotBlockList(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 TeamsService added in v0.5.8

type TeamsService interface {
	ListTeamMembersBySlug(ctx context.Context, org, slug string, opts *github.TeamListTeamMembersOptions) ([]*github.User, *github.Response, error)
}

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