server

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 38 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(c *Config) error

Types

type ChecksService

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

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
	GitConfigMergeRenameLimit   string
	GithubAccessTokenCherryPick string
	GitHubWebhookSecret         string
	Org                         string
	Username                    string
	AutoAssignerTeam            string
	AutoAssignerTeamID          int64

	TickRateMinutes int

	DriverName string
	DataSource string

	Repositories      []*Repository
	CloudRepositories []*CloudRepository

	BlockPRMergeLabels []string
	AutoPRMergeLabel   string

	BuildAppTag           string
	BuildAppInitMessage   string
	BuildAppDoneMessage   string
	BuildAppFailedMessage string
	BuildAppBranchPrefix  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 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 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
	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) 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