github

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IssueCreator = "maintainer-s-little-helper"
)

Variables

This section is empty.

Functions

func GetActionsCfg added in v1.3.1

func GetActionsCfg(ghClient *Client, owner, repoName, ghSha string) (string, []byte, error)

func IsHTTPErrorCode added in v1.1.0

func IsHTTPErrorCode(err error, httpCode int) bool

func IsNotFound added in v1.1.0

func IsNotFound(err error) bool

IsNotFound returns true if the given error is a NotFound.

Types

type AutoMerge added in v1.1.0

type AutoMerge struct {
	Label            string `yaml:"label"`
	MinimalApprovals int    `yaml:"min-approvals"`
}

type BlockPRWith added in v1.1.0

type BlockPRWith struct {
	// LabelsUnset blocks the PR if any of the Labels are not set, i.e., if any
	// of the regex does not match any label set in the PR.
	LabelsUnset []PRLabelConfig `yaml:"labels-unset,omitempty"`
	// LabelsSet blocks the PR if any of the Labels are set, i.e., if any of the
	// regex matches any label set in the PR.
	LabelsSet []PRLabelConfig `yaml:"labels-set,omitempty"`
}

type Client added in v1.1.0

type Client struct {
	GHClient *gh.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ghToken string, orgName, repo string, logger *zerolog.Logger) *Client

func NewClientFromGHClient added in v1.1.0

func NewClientFromGHClient(ghClient *gh.Client, orgName, repo string, logger *zerolog.Logger) *Client

func (*Client) AutoLabel added in v1.1.0

func (c *Client) AutoLabel(labels []string, owner string, repoName string, prNumber int, prLabels PRLabels) error

AutoLabel sets the labels automatically in a PR that is opened or reopened.

func (*Client) AutoMerge added in v1.1.0

func (c *Client) AutoMerge(
	cfg AutoMerge,
	owner, repoName string,
	base,
	head *gh.PullRequestBranch,
	prNumber int,
	prLabels PRLabels,
	review *gh.PullRequestReview,
) error

func (*Client) BlockPRWith added in v1.1.0

func (c *Client) BlockPRWith(blockPRConfig BlockPRWith, owner, repoName string, prNumber int, prLabels PRLabels) (bool, []string, error)

BlockPRWith returns true if the PR needs to be blocked based on the logic stored under config.BlockPRWith.

func (*Client) CommentAndOpenIssue added in v1.1.0

func (c *Client) CommentAndOpenIssue(ctx context.Context, owner, repo string, issueNumber int, body string) error

CommentAndOpenIssue creates a comment and (re-)opens a GH issue in case it is closed.

func (*Client) CommitContains added in v1.1.0

func (c *Client) CommitContains(msgsInCommit []MsgInCommit, owner, repoName string, prNumber int) error

CommitContains checks if all commits of the given PR Number contains the each msg provided for each MsgInCommit.

func (*Client) CreateIssue added in v1.1.0

func (c *Client) CreateIssue(ctx context.Context, owner, repo string, title, body string, labels []string) (int, error)

CreateIssue creates a new GH issue. Returns the issue number created.

func (*Client) CreateOrAppendComment added in v1.1.0

func (c *Client) CreateOrAppendComment(ctx context.Context, prNumber int, comment string, triggerRegexp *regexp.Regexp) error

CreateOrAppendComment creates or appends the 'comment' into the last comment from the PR 'prNumber' that matches the regex 'triggerRegexp'. If 'triggerRegexp' is not found then a new comment is created in the PR 'prNumber'.

func (*Client) CreateOrAppendCommentIssueComment added in v1.1.0

func (c *Client) CreateOrAppendCommentIssueComment(ctx context.Context, prNumber int, issueComment *gh.IssueComment, comment string) error

CreateOrAppendCommentIssueComment appends the 'comment' into 'issueComment'. If 'issueComment' is nil, it will create a new comment in the PR with the 'prNumber'.

func (*Client) FindPRInProject added in v1.1.0

func (c *Client) FindPRInProject(owner, repoName string, prNumber int, project Project) (int64, int64, error)

FindPRInProject finds the given PR number in the project. Returns the column and card ID for the given PR number. If not found, returns 0.

func (*Client) GetColumnID added in v1.1.0

func (c *Client) GetColumnID(owner, repoName string, project Project) (int64, int64, error)

GetColumnID returns the ProjectID and ColumnID for the given Project.

func (*Client) GetConfigFile added in v1.1.0

func (c *Client) GetConfigFile(owner, repoName, file, sha string) ([]byte, error)

func (*Client) GetFailedJenkinsURLs added in v1.1.0

func (c *Client) GetFailedJenkinsURLs(parentCtx context.Context, owner, repoName string, sha string) ([]string, error)

GetFailedJenkinsURLs returns a slice of URLs of tests that failed for the given commit SHA.

func (*Client) GetFlakeIssues added in v1.1.0

func (c *Client) GetFlakeIssues(ctx context.Context, owner, repo, creator string, labels []string) (map[int]jenkins.GHIssue, error)

GetFlakeIssues gets all "open" issues that are consider Jenkins flakes. and all "closed" and "open" issues created by the "creator".

func (*Client) GetOrCreateColumnID added in v1.1.0

func (c *Client) GetOrCreateColumnID(owner, repoName string, proj Project) (int64, error)

GetOrCreateColumnID returns the column ID for the given project. If the column is not found in the project then it will be automatically created.

func (*Client) GetPRFailure added in v1.1.0

func (c *Client) GetPRFailure(ctx context.Context, pr *gh.PullRequest) ([]string, error)

func (*Client) GetPRFailures added in v1.1.0

func (c *Client) GetPRFailures(ctx context.Context, prNumber int) ([]string, error)

GetPRFailures gets the jenkins URL failures of the given PR number.

func (*Client) GetPRsFailures added in v1.1.0

func (c *Client) GetPRsFailures(ctx context.Context, base string) (map[int][]string, error)

GetPRsFailures returns a map of 'open' non-draft PRs Numbers that maps to jenkins failures URLs.

func (*Client) HandleCheckRunEvent added in v1.3.1

func (c *Client) HandleCheckRunEvent(cfg PRBlockerConfig, e *gh.CheckRunEvent) error

func (*Client) HandleIssueCommentEvent added in v1.3.1

func (c *Client) HandleIssueCommentEvent(ctx context.Context, cfg *FlakeConfig, jobName string, pr *gh.PullRequest, event *gh.IssueCommentEvent) error

func (*Client) HandlePullRequestEvent added in v1.3.1

func (c *Client) HandlePullRequestEvent(cfg PRBlockerConfig, pre *gh.PullRequestEvent) error

func (*Client) HandlePullRequestReviewEvent added in v1.3.1

func (c *Client) HandlePullRequestReviewEvent(cfg PRBlockerConfig, pre *gh.PullRequestReviewEvent) error

func (*Client) HandleStatusEvent added in v1.3.1

func (c *Client) HandleStatusEvent(cfg PRBlockerConfig, se *gh.StatusEvent) error

func (*Client) Log added in v1.1.0

func (c *Client) Log() *zerolog.Logger

func (*Client) PutPRInProject added in v1.1.0

func (c *Client) PutPRInProject(owner, repoName string, prID int64, project Project) error

PutPRInProject puts the given prID (not PR number) into the given project.

func (*Client) SyncPRProjects added in v1.1.0

func (c *Client) SyncPRProjects(
	moveToProjectsForLabelsXORed map[string]map[string]Project,
	owner,
	repoName string,
	prID int64,
	prNumber int,
	prLabels PRLabels,
) error

SyncPRProjects syncs the given prID (not PR Number) across all projects defined in the moveToProjectsForLabelsXORed

func (*Client) TriagePRFailure added in v1.1.0

func (c *Client) TriagePRFailure(
	ctx context.Context,
	jc *jenkins.JenkinsClient,
	flakeCfg *FlakeConfig,
	prNumber int,
	jobFailURL string,
	issueKnownFlakes map[int]jenkins.GHIssue,
	jobNameToJenkinsFails map[string]jenkins.JenkinsFailures,
) (
	prJobName string,
	flakesFound map[int][]string,
	flakesNotFound []jenkins.BuildFailure,
	err error,
)

func (*Client) TriagePRFailures added in v1.1.0

func (c *Client) TriagePRFailures(
	ctx context.Context,
	jc *jenkins.JenkinsClient,
	flakeCfg *FlakeConfig,
	prNumber int,
	urlFails []string,
	issueKnownFlakes map[int]jenkins.GHIssue,
	jobNameToJenkinsFails map[string]jenkins.JenkinsFailures,
	triggerRegexp *regexp.Regexp) error

func (*Client) UpdateMergeabilityCheck added in v1.1.0

func (c *Client) UpdateMergeabilityCheck(
	owner string,
	repoName string,
	prNumber int,
	head *gh.PullRequestBranch,
	blockPR bool,
	blockReasons []string,
) error

UpdateMergeabilityCheck sets the mergeability checker with "Success" or "Failure" in case the PR needs to be blocked from mergeability.

type ErrProjectNotFound added in v1.1.0

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

func (ErrProjectNotFound) Error added in v1.1.0

func (e ErrProjectNotFound) Error() string

func (*ErrProjectNotFound) Is added in v1.1.0

func (e *ErrProjectNotFound) Is(target error) bool

type FlakeConfig added in v1.1.0

type FlakeConfig struct {
	IssueTracker     IssueTrackConfig `yaml:"issue-tracker-config"`
	JenkinsConfig    JenkinsConfig    `yaml:"jenkins-config"`
	MaxFlakesPerTest int              `yaml:"max-flakes-per-test"`
	FlakeSimilarity  float64          `yaml:"flake-similarity"`
	IgnoreFailures   []string         `yaml:"ignore-failures"`
}

func (*FlakeConfig) CommonFailure added in v1.1.0

func (fc *FlakeConfig) CommonFailure(str string) bool

CommonFailure returns true if the given 'str' is part of the list of failures that should be ignored.

func (*FlakeConfig) GetMaxFlakesPerTest added in v1.1.0

func (fc *FlakeConfig) GetMaxFlakesPerTest() int

type IssueTrackConfig added in v1.1.0

type IssueTrackConfig struct {
	// Contains the labels that are going to be used to create the GH issues
	// tracked by MLH.
	IssueLabels []string `yaml:"issue-labels"`
}

type JenkinsConfig added in v1.1.0

type JenkinsConfig struct {
	// JenkinsURL is the URL to access jenkins
	JenkinsURL string `yaml:"jenkins-url"`

	// RegexTrigger which is used to find which comment has triggered the CI
	// and so MLH can edit the comment with the tests failures.
	RegexTrigger string `yaml:"regex-trigger"`

	// StableJobNames contains the list of job names that are "stable" i.e. the
	// ones that have scheduled runs.
	StableJobNames []string `yaml:"stable-jobs"`

	// PRJobNames maps a PR job name to a list of stable jobs that are used to
	// correlate if a test failure is a flake or not.
	PRJobNames map[string]StableJobs `yaml:"pr-jobs"`
}

type MLHCommand added in v1.1.0

type MLHCommand string
const (
	MLHCommandNewFlake MLHCommand = "/mlh new-flake "
	MLHCommandNotFound MLHCommand = ""
)

func IsMLHCommand added in v1.1.0

func IsMLHCommand(s string) MLHCommand

type MsgInCommit added in v1.1.0

type MsgInCommit struct {
	// Msg is the message that should be found in the commit message. Mutually
	// exclusive with RegexpMsg.
	Msg string `yaml:"msg,omitempty"`
	// RegexpMsg is a regular expression to match the commit message. Mutually
	// exclusive with Msg.
	RegexpMsg string `yaml:"regexpMsg,omitempty"`
	// Helper is the message that should be printed if the commit message
	// doesn't contains 'Msg' or doesn't match 'RegexpMsg'.
	Helper string `yaml:"helper,omitempty"`
	// SetLabels are the labels to be set in the PR if the commit message
	// doesn't contains 'Msg' or doesn't match 'RegexpMsg'.
	SetLabels []string `yaml:"set-labels,omitempty"`
}

func (MsgInCommit) Regexp added in v1.3.3

func (m MsgInCommit) Regexp() (*regexp.Regexp, error)

Regexp returns a regular expression to be matched either based on Msg or RegexpMsg.

type PRBlockerConfig added in v1.1.0

type PRBlockerConfig struct {
	Project                      `yaml:",inline"`
	MoveToProjectsForLabelsXORed map[string]map[string]Project `yaml:"move-to-projects-for-labels-xored,omitempty"`
	RequireMsgsInCommit          []MsgInCommit                 `yaml:"require-msgs-in-commit,omitempty"`
	AutoLabel                    []string                      `yaml:"auto-label,omitempty"`
	BlockPRWith                  BlockPRWith                   `yaml:"block-pr-with,omitempty"`
	AutoMerge                    AutoMerge                     `yaml:"auto-merge,omitempty"`
	FlakeTracker                 *FlakeConfig                  `yaml:"flake-tracker,omitempty"`
}

type PRLabelConfig added in v1.1.0

type PRLabelConfig struct {
	// RegexLabel contains the regex that will be used to find for labels.
	RegexLabel string `yaml:"regex-label,omitempty"`
	// Helper will print the a helper message in case the regex-label is or
	// isn't matched.
	Helper string `yaml:"helper,omitempty"`
	// SetLabels will set the labels in case the RegexLabel matches the labels
	// of a PR.
	SetLabels []string `yaml:"set-labels,omitempty"`
}

type PRLabels added in v1.3.1

type PRLabels map[string]struct{}

type Project added in v1.1.0

type Project struct {
	ProjectName string `yaml:"project,omitempty"`
	ColumnName  string `yaml:"column,omitempty"`
}

type StableJobs added in v1.1.0

type StableJobs struct {
	JobNames []string `yaml:"correlated-with-stable-jobs"`
}

Jump to

Keyboard shortcuts

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