scmprovider

package
v1.21.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// RoleAll lists both members and admins
	RoleAll = "all"
	// RoleAdmin specifies the user is an org admin, or lists only admins
	RoleAdmin = "admin"
	// RoleMaintainer specifies the user is a team maintainer, or lists only maintainers
	RoleMaintainer = "maintainer"
	// RoleMember specifies the user is a regular user, or only lists regular users
	RoleMember = "member"
	// StatePending specifies the user has an invitation to the org/team.
	StatePending = "pending"
	// StateActive specifies the user's membership is active.
	StateActive = "active"
)
View Source
const (
	// EventGUID is sent by Github in a header of every webhook request.
	// Used as a log field across prow.
	EventGUID = "event-GUID"
	// PrLogField is the number of a PR.
	// Used as a log field across prow.
	PrLogField = "pr"
	// OrgLogField is the organization of a PR.
	// Used as a log field across prow.
	OrgLogField = "org"
	// RepoLogField is the repository of a PR.
	// Used as a log field across prow.
	RepoLogField = "repo"

	// SearchTimeFormat is a time.Time format string for ISO8601 which is the
	// format that GitHub requires for times specified as part of a search query.
	SearchTimeFormat = "2006-01-02T15:04:05Z"
)
View Source
const (
	// GenericCommentActionCreated means something was created/opened/submitted
	GenericCommentActionCreated GenericCommentEventAction = "created" // "opened", "submitted"
	// GenericCommentActionEdited means something was edited.
	GenericCommentActionEdited = "edited"
	// GenericCommentActionDeleted means something was deleted/dismissed.
	GenericCommentActionDeleted = "deleted" // "dismissed"
)

Comments indicate values that are coerced to the specified value.

View Source
const (
	// IssueActionAssigned means assignees were added.
	IssueActionAssigned IssueEventAction = "assigned"
	// IssueActionUnassigned means assignees were added.
	IssueActionUnassigned = "unassigned"
	// IssueActionLabeled means labels were added.
	IssueActionLabeled = "labeled"
	// IssueActionUnlabeled means labels were removed.
	IssueActionUnlabeled = "unlabeled"
	// IssueActionOpened means issue was opened/created.
	IssueActionOpened = "opened"
	// IssueActionEdited means issue body was edited.
	IssueActionEdited = "edited"
	// IssueActionMilestoned means the milestone was added/changed.
	IssueActionMilestoned = "milestoned"
	// IssueActionDemilestoned means a milestone was removed.
	IssueActionDemilestoned = "demilestoned"
	// IssueActionClosed means issue was closed.
	IssueActionClosed = "closed"
	// IssueActionReopened means issue was reopened.
	IssueActionReopened = "reopened"
)
View Source
const (
	StatusPending = "pending"
	StatusSuccess = "success"
	StatusError   = "error"
	StatusFailure = "failure"
)

These are possible State entries for a Status.

Variables

View Source
var (
	// FoundingYear is the year GitHub was founded. This is just used so that
	// we can lower bound dates related to PRs and issues.
	FoundingYear, _ = time.Parse(SearchTimeFormat, "2007-01-01T00:00:00Z")
)
View Source
var NormLogin = strings.ToLower

NormLogin normalizes GitHub login strings

View Source
var TestBotName = "k8s-ci-robot"

TestBotName is the default bot name used in tests

Functions

func AddLabelToComment added in v0.0.591

func AddLabelToComment(spc SCMClient, org, repo string, number int, label string) error

AddLabelToComment adds a label to the tracking comment

func CreateLabelComment added in v0.0.591

func CreateLabelComment(labels []string) string

CreateLabelComment creates the appropriate comment structure for the relevant labels

func DeleteLabelFromComment added in v0.0.591

func DeleteLabelFromComment(spc SCMClient, org, repo string, number int, label string) error

DeleteLabelFromComment removes a label from the tracking comment

func GetLabelReportComment added in v0.0.591

func GetLabelReportComment(spc SCMClient, org, repo string, number int) (*scm.Comment, error)

GetLabelReportComment gets the scm.Comment, if present, containing the label report.

func GetLabelsFromComment added in v0.0.591

func GetLabelsFromComment(spc SCMClient, org, repo string, number int) ([]*scm.Label, error)

GetLabelsFromComment extracts the applied "labels" from a pull request from a comment

func HasLabel

func HasLabel(label string, issueLabels []*scm.Label) bool

HasLabel checks if label is in the label set "issueLabels".

func ImageTooBig

func ImageTooBig(url string) (bool, error)

ImageTooBig checks if image is bigger than github limits

func NoLabelProviders added in v0.0.591

func NoLabelProviders() sets.String

NoLabelProviders returns a set of provider names that don't support labels.

func PushHookBranch

func PushHookBranch(pe *scm.PushHook) string

PushHookBranch returns the name of the branch to which the user pushed.

Types

type Client

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

Client represents an interface that prow plugins expect on top of go-scm

func ToClient

func ToClient(client *scm.Client, botName string) *Client

ToClient converts the scm client to an API that the prow plugins expect

func (*Client) AddLabel

func (c *Client) AddLabel(owner, repo string, number int, label string, pr bool) error

AddLabel adds a label

func (*Client) AssignIssue

func (c *Client) AssignIssue(owner, repo string, number int, logins []string) error

AssignIssue assigns issue

func (*Client) AssignPR added in v0.0.865

func (c *Client) AssignPR(owner, repo string, number int, logins []string) error

AssignPR assigns pr

func (*Client) BotName

func (c *Client) BotName() (string, error)

BotName returns the bot name

func (*Client) ClearMilestone

func (c *Client) ClearMilestone(org, repo string, num int, isPR bool) error

ClearMilestone clears milestone

func (*Client) CloseIssue

func (c *Client) CloseIssue(owner, repo string, number int) error

CloseIssue close issue

func (*Client) ClosePR

func (c *Client) ClosePR(owner, repo string, number int) error

ClosePR closes a pull request

func (*Client) CreateComment

func (c *Client) CreateComment(owner, repo string, number int, pr bool, comment string) error

CreateComment create a comment

func (*Client) CreateGraphQLStatus

func (c *Client) CreateGraphQLStatus(owner, repo, ref string, s *Status) (*scm.Status, error)

CreateGraphQLStatus create a status into a repository

func (*Client) CreateStatus

func (c *Client) CreateStatus(owner, repo, ref string, s *scm.StatusInput) (*scm.Status, error)

CreateStatus create a status into a repository

func (*Client) DeleteComment

func (c *Client) DeleteComment(org, repo string, number, ID int, pr bool) error

DeleteComment delete comments

func (*Client) DeleteRef

func (c *Client) DeleteRef(owner, repo, ref string) error

DeleteRef deletes the ref from repository

func (*Client) DeleteStaleComments

func (c *Client) DeleteStaleComments(org, repo string, number int, comments []*scm.Comment, pr bool, isStale func(*scm.Comment) bool) error

DeleteStaleComments iterates over comments on an issue/PR, deleting those which the 'isStale' function identifies as stale. If 'comments' is nil, the comments will be fetched from GitHub.

func (*Client) EditComment added in v0.0.553

func (c *Client) EditComment(owner, repo string, number int, id int, comment string, pr bool) error

EditComment edit a comment

func (*Client) FindIssues

func (c *Client) FindIssues(query, sort string, asc bool) ([]scm.Issue, error)

FindIssues find issues

func (*Client) FindPullRequestsByAuthor added in v0.0.819

func (c *Client) FindPullRequestsByAuthor(owner, repo string, author string) ([]*scm.PullRequest, error)

FindPullRequestsByAuthor finds all pull requests for a given author

func (*Client) GetCombinedStatus

func (c *Client) GetCombinedStatus(owner, repo, ref string) (*scm.CombinedStatus, error)

GetCombinedStatus returns the combined status

func (*Client) GetFile

func (c *Client) GetFile(owner, repo, filepath, commit string) ([]byte, error)

GetFile returns the file from git

func (*Client) GetIssueLabels

func (c *Client) GetIssueLabels(org, repo string, number int, pr bool) ([]*scm.Label, error)

GetIssueLabels returns the issue labels

func (*Client) GetPullRequest

func (c *Client) GetPullRequest(owner, repo string, number int) (*scm.PullRequest, error)

GetPullRequest returns the pull request

func (*Client) GetPullRequestChanges

func (c *Client) GetPullRequestChanges(org, repo string, number int) ([]*scm.Change, error)

GetPullRequestChanges returns the changes in a pull request

func (*Client) GetRef

func (c *Client) GetRef(owner, repo, ref string) (string, error)

GetRef returns the ref from repository

func (*Client) GetRepoLabels

func (c *Client) GetRepoLabels(owner, repo string) ([]*scm.Label, error)

GetRepoLabels returns the repository labels

func (*Client) GetRepositoryByFullName added in v0.0.575

func (c *Client) GetRepositoryByFullName(fullName string) (*scm.Repository, error)

GetRepositoryByFullName returns the repository details

func (*Client) GetSingleCommit

func (c *Client) GetSingleCommit(owner, repo, SHA string) (*scm.Commit, error)

GetSingleCommit returns a single commit

func (*Client) GetUserPermission

func (c *Client) GetUserPermission(org, repo, user string) (string, error)

GetUserPermission returns the user's permission level for a repo

func (*Client) HasPermission

func (c *Client) HasPermission(org, repo, user string, roles ...string) (bool, error)

HasPermission returns true if GetUserPermission() returns any of the roles.

func (*Client) IsCollaborator

func (c *Client) IsCollaborator(owner, repo, login string) (bool, error)

IsCollaborator check if a user is collaborator to a repository

func (*Client) IsMember

func (c *Client) IsMember(org, user string) (bool, error)

IsMember checks if a user is a member of the organisation

func (*Client) IsOrgAdmin added in v0.0.602

func (c *Client) IsOrgAdmin(org, user string) (bool, error)

IsOrgAdmin returns whether this user is an admin of the org

func (*Client) ListAllPullRequestsForFullNameRepo added in v0.0.575

func (c *Client) ListAllPullRequestsForFullNameRepo(fullName string, opts scm.PullRequestListOptions) ([]*scm.PullRequest, error)

ListAllPullRequestsForFullNameRepo lists all pull requests in a full-name repository

func (*Client) ListCollaborators

func (c *Client) ListCollaborators(owner, repo string) ([]scm.User, error)

ListCollaborators list the collaborators to a repository

func (*Client) ListFiles added in v0.0.825

func (c *Client) ListFiles(owner, repo, filepath, commit string) ([]*scm.FileEntry, error)

ListFiles returns the files from git

func (*Client) ListIssueComments

func (c *Client) ListIssueComments(org, repo string, number int) ([]*scm.Comment, error)

ListIssueComments list comments associated with an issue

func (*Client) ListIssueEvents

func (c *Client) ListIssueEvents(org, repo string, number int) ([]*scm.ListedIssueEvent, error)

ListIssueEvents list issue events

func (*Client) ListMilestones

func (c *Client) ListMilestones(org, repo string) ([]*scm.Milestone, error)

ListMilestones list milestones

func (*Client) ListOrgMembers added in v0.0.546

func (c *Client) ListOrgMembers(org string) ([]*scm.TeamMember, error)

ListOrgMembers list the org members

func (*Client) ListPullRequestComments

func (c *Client) ListPullRequestComments(owner, repo string, number int) ([]*scm.Comment, error)

ListPullRequestComments list pull request comments

func (*Client) ListReviews

func (c *Client) ListReviews(owner, repo string, number int) ([]*scm.Review, error)

ListReviews list the reviews

func (*Client) ListStatuses

func (c *Client) ListStatuses(owner, repo, ref string) ([]*scm.Status, error)

ListStatuses list the statuses

func (*Client) ListTeamMembers

func (c *Client) ListTeamMembers(id int, role string) ([]*scm.TeamMember, error)

ListTeamMembers list the team members

func (*Client) ListTeams

func (c *Client) ListTeams(org string) ([]*scm.Team, error)

ListTeams list teams in the organisation

func (*Client) Merge

func (c *Client) Merge(owner, repo string, number int, details MergeDetails) error

Merge reopens a pull request

func (*Client) PRRefFmt added in v0.0.707

func (c *Client) PRRefFmt() string

PRRefFmt returns the "refs/(something)/%d/(something)" sprintf format used for constructing PR refs for this provider

func (*Client) ProviderType added in v0.0.575

func (c *Client) ProviderType() string

ProviderType returns the type of the underlying SCM provider

func (*Client) Query

func (c *Client) Query(ctx context.Context, q interface{}, vars map[string]interface{}) error

Query performs a GraphQL query on the git provider

func (*Client) QuoteAuthorForComment added in v0.0.632

func (c *Client) QuoteAuthorForComment(author string) string

QuoteAuthorForComment will quote the author login for use in "@author" if appropriate for the provider.

func (*Client) RemoveLabel

func (c *Client) RemoveLabel(owner, repo string, number int, label string, pr bool) error

RemoveLabel removes labesl

func (*Client) ReopenIssue

func (c *Client) ReopenIssue(owner, repo string, number int) error

ReopenIssue reopen an issue

func (*Client) ReopenPR

func (c *Client) ReopenPR(owner, repo string, number int) error

ReopenPR reopens a pull request

func (*Client) RequestReview

func (c *Client) RequestReview(org, repo string, number int, logins []string) error

RequestReview requests a review

func (*Client) Search

func (c *Client) Search(opts scm.SearchOptions) ([]*scm.SearchIssue, *RateLimits, error)

Search query issues/PRs using a query string

func (*Client) ServerURL added in v0.0.632

func (c *Client) ServerURL() *url.URL

ServerURL returns the server URL for the client

func (*Client) SetBotName

func (c *Client) SetBotName(botName string)

SetBotName sets the bot name

func (*Client) SetMilestone

func (c *Client) SetMilestone(org, repo string, issueNum, milestoneNum int, isPR bool) error

SetMilestone sets milestone

func (*Client) SupportsGraphQL added in v0.0.575

func (c *Client) SupportsGraphQL() bool

SupportsGraphQL returns true if the underlying provider supports our GraphQL queries Currently, that means it has to be GitHub.

func (*Client) SupportsPRLabels added in v0.0.591

func (c *Client) SupportsPRLabels() bool

SupportsPRLabels returns true if the underlying provider supports PR labels

func (*Client) ToScmClient added in v0.0.825

func (c *Client) ToScmClient() *scm.Client

ToScmClient gets the underlying SCM client

func (*Client) UnassignIssue

func (c *Client) UnassignIssue(owner, repo string, number int, logins []string) error

UnassignIssue unassigns issue

func (*Client) UnassignPR added in v0.0.865

func (c *Client) UnassignPR(owner, repo string, number int, logins []string) error

UnassignPR unassigns pr

func (*Client) UnrequestReview

func (c *Client) UnrequestReview(org, repo string, number int, logins []string) error

UnrequestReview unrequest a review

type DraftReview

type DraftReview struct {
	// If unspecified, defaults to the most recent commit in the PR.
	CommitSHA string `json:"commit_id,omitempty"`
	Body      string `json:"body"`
	// If unspecified, defaults to PENDING.
	Action   ReviewAction         `json:"event,omitempty"`
	Comments []DraftReviewComment `json:"comments,omitempty"`
}

DraftReview is what we give GitHub when we want to make a PR Review. This is different than what we receive when we ask for a Review.

type DraftReviewComment

type DraftReviewComment struct {
	Path string `json:"path"`
	// Position in the patch, not the line number in the file.
	Position int    `json:"position"`
	Body     string `json:"body"`
}

DraftReviewComment is a comment in a draft review.

type FileNotFound

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

FileNotFound happens when github cannot find the file requested by GetFile().

func (*FileNotFound) Error

func (e *FileNotFound) Error() string

Error formats a file not found error

type GenericCommentEvent

type GenericCommentEvent struct {
	IsPR        bool
	Action      scm.Action
	Body        string
	Link        string
	Number      int
	Repo        scm.Repository
	Author      scm.User
	IssueAuthor scm.User
	Assignees   []scm.User
	IssueState  string
	IssueBody   string
	IssueLink   string
	GUID        string
	HeadSha     string
}

GenericCommentEvent is a fake event type that is instantiated for any github event that contains comment like content. The specific events that are also handled as GenericCommentEvents are: - issue_comment events - pull_request_review events - pull_request_review_comment events - pull_request events with action in ["opened", "edited"] - issue events with action in ["opened", "edited"]

Issue and PR "closed" events are not coerced to the "deleted" Action and do not trigger a GenericCommentEvent because these events don't actually remove the comment content from GH.

type GenericCommentEventAction

type GenericCommentEventAction string

GenericCommentEventAction coerces multiple actions into its generic equivalent.

type IssueEventAction

type IssueEventAction string

IssueEventAction enumerates the triggers for this webhook payload type. See also: https://developer.github.com/v3/activity/events/types/#issuesevent

type MergeCommitsForbiddenError

type MergeCommitsForbiddenError string

MergeCommitsForbiddenError happens when the repo disallows the merge strategy configured for the repo in Keeper.

func (MergeCommitsForbiddenError) Error

type MergeDetails

type MergeDetails struct {
	SHA           string
	MergeMethod   string
	CommitTitle   string
	CommitMessage string
}

MergeDetails optional extra parameters

type MissingUsers

type MissingUsers struct {
	Users []string
	// contains filtered or unexported fields
}

MissingUsers is an error specifying the users that could not be unassigned.

func (MissingUsers) Error

func (m MissingUsers) Error() string

type ModifiedHeadError

type ModifiedHeadError string

ModifiedHeadError happens when github refuses to merge a PR because the PR changed.

func (ModifiedHeadError) Error

func (e ModifiedHeadError) Error() string

type RateLimits

type RateLimits struct {
	Remaining int
	Limit     int
	Reset     int
}

RateLimits contains rate limit information

type ReviewAction

type ReviewAction string

ReviewAction is the action that a review can be made with.

const (
	Approve        ReviewAction = "APPROVE"
	RequestChanges ReviewAction = "REQUEST_CHANGES"
	Comment        ReviewAction = "COMMENT"
)

Possible review actions. Leave Action blank for a pending review.

type SCMClient

type SCMClient interface {
	// Functions implemented in client.go
	BotName() (string, error)
	SetBotName(string)
	SupportsGraphQL() bool
	ProviderType() string
	PRRefFmt() string
	SupportsPRLabels() bool
	ServerURL() *url.URL
	QuoteAuthorForComment(string) string

	// Functions implemented in content.go
	GetFile(string, string, string, string) ([]byte, error)
	ListFiles(string, string, string, string) ([]*scm.FileEntry, error)

	// Functions implemented in git.go
	GetRef(string, string, string) (string, error)
	DeleteRef(string, string, string) error
	GetSingleCommit(string, string, string) (*scm.Commit, error)

	// Functions implemented in issues.go
	Query(context.Context, interface{}, map[string]interface{}) error
	Search(scm.SearchOptions) ([]*scm.SearchIssue, *RateLimits, error)
	ListIssueEvents(string, string, int) ([]*scm.ListedIssueEvent, error)
	AssignIssue(string, string, int, []string) error
	UnassignIssue(string, string, int, []string) error
	AddLabel(string, string, int, string, bool) error
	RemoveLabel(string, string, int, string, bool) error
	DeleteComment(string, string, int, int, bool) error
	DeleteStaleComments(string, string, int, []*scm.Comment, bool, func(*scm.Comment) bool) error
	ListIssueComments(string, string, int) ([]*scm.Comment, error)
	GetIssueLabels(string, string, int, bool) ([]*scm.Label, error)
	CreateComment(string, string, int, bool, string) error
	ReopenIssue(string, string, int) error
	FindIssues(string, string, bool) ([]scm.Issue, error)
	CloseIssue(string, string, int) error
	EditComment(owner, repo string, number int, id int, comment string, pr bool) error

	// Functions implemented in organizations.go
	ListTeams(string) ([]*scm.Team, error)
	ListTeamMembers(int, string) ([]*scm.TeamMember, error)
	ListOrgMembers(string) ([]*scm.TeamMember, error)
	IsOrgAdmin(string, string) (bool, error)

	// Functions implemented in pull_requests.go
	GetPullRequest(string, string, int) (*scm.PullRequest, error)
	ListPullRequestComments(string, string, int) ([]*scm.Comment, error)
	GetPullRequestChanges(string, string, int) ([]*scm.Change, error)
	Merge(string, string, int, MergeDetails) error
	ReopenPR(string, string, int) error
	ClosePR(string, string, int) error
	ListAllPullRequestsForFullNameRepo(string, scm.PullRequestListOptions) ([]*scm.PullRequest, error)
	FindPullRequestsByAuthor(string, string, string) ([]*scm.PullRequest, error)

	// Functions implemented in repositories.go
	GetRepoLabels(string, string) ([]*scm.Label, error)
	IsCollaborator(string, string, string) (bool, error)
	ListCollaborators(string, string) ([]scm.User, error)
	CreateStatus(string, string, string, *scm.StatusInput) (*scm.Status, error)
	CreateGraphQLStatus(string, string, string, *Status) (*scm.Status, error)
	ListStatuses(string, string, string) ([]*scm.Status, error)
	GetCombinedStatus(string, string, string) (*scm.CombinedStatus, error)
	HasPermission(string, string, string, ...string) (bool, error)
	GetUserPermission(string, string, string) (string, error)
	IsMember(string, string) (bool, error)
	GetRepositoryByFullName(string) (*scm.Repository, error)

	// Functions implemented in reviews.go
	ListReviews(string, string, int) ([]*scm.Review, error)
	RequestReview(string, string, int, []string) error
	UnrequestReview(string, string, int, []string) error

	// Functions implemented in milestones.go
	ClearMilestone(string, string, int, bool) error
	SetMilestone(string, string, int, int, bool) error
	ListMilestones(string, string) ([]*scm.Milestone, error)
}

SCMClient is an interface providing all functions on the Client struct.

type Status

type Status struct {
	State       string `json:"state"`
	TargetURL   string `json:"target_url,omitempty"`
	Description string `json:"description,omitempty"`
	Context     string `json:"context,omitempty"`
}

Status is used to set a commit status line.

type TestClient added in v0.0.591

type TestClient struct {
	Client

	Data *fake.Data
}

TestClient uses the go-scm fake client behind the scenes and allows access to its test data

func NewTestClientForLabelsInComments added in v0.0.591

func NewTestClientForLabelsInComments() *TestClient

NewTestClientForLabelsInComments returns a test client specifically for testing the scenario of labels not being available

func ToTestClient

func ToTestClient(client *scm.Client) *TestClient

ToTestClient converts the scm client to an API that the prow plugins expect

func (*TestClient) PopulateFakeLabelsFromComments added in v0.0.591

func (t *TestClient) PopulateFakeLabelsFromComments(org, repo string, number int, fakeLabel string, shouldUnlabel bool) error

PopulateFakeLabelsFromComments checks if there's Data for this test client, and if it doesn't support PR labels. If so, it populates the label-related fields in the data from the comments.

type UnauthorizedToPushError

type UnauthorizedToPushError string

UnauthorizedToPushError happens when client is not allowed to push to github.

func (UnauthorizedToPushError) Error

func (e UnauthorizedToPushError) Error() string

type UnmergablePRBaseChangedError

type UnmergablePRBaseChangedError string

UnmergablePRBaseChangedError happens when github refuses merging a PR because the base changed.

func (UnmergablePRBaseChangedError) Error

type UnmergablePRError

type UnmergablePRError string

UnmergablePRError happens when github refuses to merge a PR for other reasons (merge confclit).

func (UnmergablePRError) Error

func (e UnmergablePRError) Error() string

Directories

Path Synopsis
Package reporter contains helpers for writing comments in scm providers.
Package reporter contains helpers for writing comments in scm providers.

Jump to

Keyboard shortcuts

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