Documentation ¶
Overview ¶
Package thirdparty defines interactions with third-party services but not cloud providers, which are in cloud.
Index ¶
- Constants
- Variables
- func AppAuthorizedForOrg(ctx context.Context, token, requiredOrganization, name string) (bool, error)
- func CheckGithubAPILimit(ctx context.Context, token string) (int64, error)
- func CreateCheckRun(ctx context.Context, owner, repo, headSHA, uiBase string, task *task.Task, ...) (*github.CheckRun, error)
- func FormGitURL(host, owner, repo, token string) string
- func FormGitURLForApp(host, owner, repo, token string) string
- func GetBranchEvent(ctx context.Context, token, owner, repo, branch string) (*github.Branch, error)
- func GetBranchProtectionRules(ctx context.Context, token, owner, repo, branch string) ([]string, error)
- func GetCheckRun(ctx context.Context, owner, repo string, checkRunID int64) (*github.CheckRun, error)
- func GetCommitDiff(ctx context.Context, token, owner, repo, sha string) (string, error)
- func GetCommitEvent(ctx context.Context, token, owner, repo, githash string) (*github.RepositoryCommit, error)
- func GetDiffsFromMboxPatch(patchContent string) (string, error)
- func GetEvergreenBranchProtectionRules(ctx context.Context, token, owner, repo, branch string) ([]string, error)
- func GetGithubCommits(ctx context.Context, token, owner, repo, ref string, until time.Time, ...) ([]*github.RepositoryCommit, int, error)
- func GetGithubFile(ctx context.Context, token, owner, repo, path, ref string) (*github.RepositoryContent, error)
- func GetGithubMergeBaseRevision(ctx context.Context, ...) (string, error)
- func GetGithubPullRequest(ctx context.Context, token, baseOwner, baseRepo string, prNumber int) (*github.PullRequest, error)
- func GetGithubUser(ctx context.Context, token, loginName string) (*github.User, error)
- func GetMergeablePullRequest(ctx context.Context, issue int, githubToken, owner, repo string) (*github.PullRequest, error)
- func GetPullRequestMergeBase(ctx context.Context, token string, data GithubPatch) (string, error)
- func GetTaggedCommitFromGithub(ctx context.Context, token, owner, repo, tag string) (string, error)
- func GitApplyNumstat(patch string) (*bytes.Buffer, error)
- func GitHubUserHasWritePermission(ctx context.Context, token, owner, repo, username string) (bool, error)
- func GithubUserInOrganization(ctx context.Context, token, requiredOrganization, username string) (bool, error)
- func IsFileNotFound(err error) bool
- func IsMergeBaseAllowed(ctx context.Context, ...) (bool, error)
- func IsUnblockedGithubStatus(status string) bool
- func IsUserInGithubTeam(ctx context.Context, teams []string, org, user, token, owner, repo string) bool
- func ListCheckRunCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) ([]int64, error)
- func MergePullRequest(ctx context.Context, token, appToken, owner, repo, commitMessage string, ...) error
- func ParseGitUrl(url string) (string, string, error)
- func PostCommentToPullRequest(ctx context.Context, token, owner, repo string, prNum int, comment string) error
- func RevokeInstallationToken(ctx context.Context, token string) error
- func SendCommitQueueGithubStatus(ctx context.Context, env evergreen.Environment, pr *github.PullRequest, ...) error
- func SendPendingStatusToGithub(ctx context.Context, input SendGithubStatusInput, urlBase string) error
- func UpdateCheckRun(ctx context.Context, owner, repo, uiBase string, checkRunID int64, ...) (*github.CheckRun, error)
- func ValidateCheckRunOutput(output *github.CheckRunOutput) error
- func ValidatePR(pr *github.PullRequest) error
- type APIRequestError
- type APIResponseError
- type APIUnmarshalError
- type Commit
- type FileDecodeError
- type FileNotFoundError
- type GithubAuthParameters
- type GithubAuthResponse
- type GithubLoginUser
- func (u *GithubLoginUser) DisplayName() string
- func (u *GithubLoginUser) Email() string
- func (u *GithubLoginUser) GetAPIKey() string
- func (u *GithubLoginUser) GetAccessToken() string
- func (u *GithubLoginUser) GetRefreshToken() string
- func (u *GithubLoginUser) HasPermission(gimlet.PermissionOpts) bool
- func (u *GithubLoginUser) IsNil() bool
- func (u *GithubLoginUser) Roles() []string
- func (u *GithubLoginUser) Username() string
- type GithubMergeGroup
- type GithubPatch
- type JiraCreateTicketResponse
- type JiraCustomField
- type JiraHandler
- func (jiraHandler *JiraHandler) CreateTicket(fields map[string]interface{}) (*JiraCreateTicketResponse, error)
- func (jiraHandler *JiraHandler) GetJIRATicket(key string) (*JiraTicket, error)
- func (jiraHandler *JiraHandler) HttpClient() *http.Client
- func (jiraHandler *JiraHandler) JQLSearch(query string, startAt, maxResults int) (*JiraSearchResults, error)
- func (jiraHandler *JiraHandler) JQLSearchAll(query string) ([]JiraTicket, error)
- func (jiraHandler *JiraHandler) JiraHost() string
- func (jiraHandler *JiraHandler) UpdateTicket(key string, fields map[string]interface{}) error
- type JiraProject
- type JiraResolution
- type JiraSearchResults
- type JiraStatus
- type JiraTicket
- type PapertrailClient
- type PapertrailProductVersion
- type PapertrailSpan
- type ResponseReadError
- type SearchReturnInfo
- type SendGithubStatusInput
- type Summary
- func GetGithubPullRequestDiff(ctx context.Context, token string, gh GithubPatch) (string, []Summary, error)
- func GetPatchSummaries(patchContent string) ([]Summary, error)
- func GetPatchSummariesFromMboxPatch(mboxPatch string) ([]Summary, []string, error)
- func ParseGitSummary(gitOutput fmt.Stringer) (summaries []Summary, err error)
- type TicketFields
- type TicketType
- type TraceArgs
- type User
- type YAMLFormatError
Constants ¶
const ( Github502Error = "502 Server Error" GithubInvestigation = "Github API Limit Investigation" PRDiffTooLargeErrorMessage = "the diff exceeded the maximum" )
const (
GithubPRBlocked = "blocked"
)
Variables ¶
var ( // BSON fields for GithubPatch GithubPatchPRNumberKey = bsonutil.MustHaveTag(GithubPatch{}, "PRNumber") GithubPatchBaseOwnerKey = bsonutil.MustHaveTag(GithubPatch{}, "BaseOwner") GithubPatchBaseRepoKey = bsonutil.MustHaveTag(GithubPatch{}, "BaseRepo") GithubPatchMergeCommitSHAKey = bsonutil.MustHaveTag(GithubPatch{}, "MergeCommitSHA") RepeatPatchIdNextPatchKey = bsonutil.MustHaveTag(GithubPatch{}, "RepeatPatchIdNextPatch") )
var UnblockedGithubStatuses = []string{
githubPRBehind,
githubPRClean,
githubPRDirty,
githubPRDraft,
githubPRHasHooks,
githubPRUnknown,
githubPRUnstable,
}
Functions ¶
func AppAuthorizedForOrg ¶
func AppAuthorizedForOrg(ctx context.Context, token, requiredOrganization, name string) (bool, error)
AppAuthorizedForOrg returns true if the given app name exists in the org's installation list, and has permission to write to pull requests. Returns an error if the app name exists but doesn't have permission.
func CheckGithubAPILimit ¶
CheckGithubAPILimit queries Github for the number of API requests remaining
func CreateCheckRun ¶
func CreateCheckRun(ctx context.Context, owner, repo, headSHA, uiBase string, task *task.Task, output *github.CheckRunOutput) (*github.CheckRun, error)
CreateCheckRun creates a checkRun and returns a Github CheckRun object
func FormGitURL ¶
func FormGitURLForApp ¶
func GetBranchEvent ¶
GetBranchEvent gets the head of the a given branch via an API call to GitHub
func GetBranchProtectionRules ¶
func GetBranchProtectionRules(ctx context.Context, token, owner, repo, branch string) ([]string, error)
GetBranchProtectionRules gets all branch protection checks as a list of strings.
func GetCheckRun ¶
func GetCheckRun(ctx context.Context, owner, repo string, checkRunID int64) (*github.CheckRun, error)
GetCheckRun gets a check run by ID
func GetCommitDiff ¶
GetCommitDiff gets the diff of the specified commit via an API call to GitHub
func GetCommitEvent ¶
func GetDiffsFromMboxPatch ¶
func GetEvergreenBranchProtectionRules ¶
func GetEvergreenBranchProtectionRules(ctx context.Context, token, owner, repo, branch string) ([]string, error)
GetEvergreenBranchProtectionRules gets all Evergreen branch protection checks as a list of strings.
func GetGithubCommits ¶
func GetGithubCommits(ctx context.Context, token, owner, repo, ref string, until time.Time, commitPage int) ([]*github.RepositoryCommit, int, error)
GetGithubCommits returns a slice of GithubCommit objects from the given commitsURL when provided a valid oauth token
func GetGithubFile ¶
func GetGithubFile(ctx context.Context, token, owner, repo, path, ref string) (*github.RepositoryContent, error)
GetGithubFile returns a struct that contains the contents of files within a repository as Base64 encoded content. Ref should be the commit hash or branch (defaults to master).
func GetGithubMergeBaseRevision ¶
func GetGithubMergeBaseRevision(ctx context.Context, token, owner, repo, baseRevision, currentCommitHash string) (string, error)
GetGithubMergeBaseRevision compares baseRevision and currentCommitHash in a GitHub repo and returns the merge base commit's SHA.
func GetGithubPullRequest ¶
func GetGithubUser ¶
GetGithubUser fetches the github user with the given login name
func GetMergeablePullRequest ¶
func GetMergeablePullRequest(ctx context.Context, issue int, githubToken, owner, repo string) (*github.PullRequest, error)
GetMergeablePullRequest gets the pull request and returns if the PR is valid and mergeable.
func GetPullRequestMergeBase ¶
GetPullRequestMergeBase returns the merge base hash for the given PR. This function will retry up to 5 times, regardless of error response (unless error is the result of hitting an api limit)
func GetTaggedCommitFromGithub ¶
GetTaggedCommitFromGithub gets the commit SHA for the given tag name.
func GitApplyNumstat ¶
GitApplyNumstat attempts to apply a given patch; it returns the patch's bytes if it is successful
func GitHubUserHasWritePermission ¶
func GitHubUserHasWritePermission(ctx context.Context, token, owner, repo, username string) (bool, error)
GitHubUserHasWritePermission returns true if the given user has write permission for the repo. Returns an error if the user isn't found or the token isn't authed for this repo.
func GithubUserInOrganization ¶
func GithubUserInOrganization(ctx context.Context, token, requiredOrganization, username string) (bool, error)
GithubUserInOrganization returns true if the given github user is in the given organization. The user with the attached token must have visibility into organization membership, including private members
func IsFileNotFound ¶
func IsMergeBaseAllowed ¶
func IsMergeBaseAllowed(ctx context.Context, token, owner, repo, oldestAllowedMergeBase, mergeBase string) (bool, error)
IsMergeBaseAllowed will return true if the input merge base is newer than the oldest allowed merge base configured in the project settings.
func IsUnblockedGithubStatus ¶
IsUnblockedGithubStatus returns true if the status is in the list of unblocked statuses
func IsUserInGithubTeam ¶
func ListCheckRunCheckSuite ¶
func ListCheckRunCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) ([]int64, error)
ListCheckRunCheckSuite returns a list of check run IDs for a given check suite
func MergePullRequest ¶
func MergePullRequest(ctx context.Context, token, appToken, owner, repo, commitMessage string, prNum int, mergeOpts *github.PullRequestOptions) error
MergePullRequest attempts to merge the given pull request. If commits are merged one after another, Github may not have updated that this can be merged, so we allow retries.
func PostCommentToPullRequest ¶
func PostCommentToPullRequest(ctx context.Context, token, owner, repo string, prNum int, comment string) error
PostCommentToPullRequest posts the given comment to the associated PR.
func RevokeInstallationToken ¶
revokeInstallationToken revokes an installation token.
func SendCommitQueueGithubStatus ¶
func SendCommitQueueGithubStatus(ctx context.Context, env evergreen.Environment, pr *github.PullRequest, state message.GithubState, description, versionID string) error
func SendPendingStatusToGithub ¶
func SendPendingStatusToGithub(ctx context.Context, input SendGithubStatusInput, urlBase string) error
SendPendingStatusToGithub sends a pending status to a Github PR patch associated with a given version.
func UpdateCheckRun ¶
func UpdateCheckRun(ctx context.Context, owner, repo, uiBase string, checkRunID int64, task *task.Task, output *github.CheckRunOutput) (*github.CheckRun, error)
UpdateCheckRun updates a checkRun and returns a Github CheckRun object UpdateCheckRunOptions must specify a name for the check run
func ValidateCheckRunOutput ¶
func ValidateCheckRunOutput(output *github.CheckRunOutput) error
func ValidatePR ¶
func ValidatePR(pr *github.PullRequest) error
Types ¶
type APIRequestError ¶
type APIRequestError struct { StatusCode int Message string `json:"message"` DocumentationUrl string `json:"documentation_url"` }
When attempting to access the some API using authentication, requests may return 404 Not Found, instead of 403 Forbidden, under certain circumstances. For example, see https://developer.github.com/v3/#authentication. This struct should be used for errors in fetching a requested remote config.
func (APIRequestError) Error ¶
func (are APIRequestError) Error() string
type APIResponseError ¶
type APIResponseError struct {
// contains filtered or unexported fields
}
func (APIResponseError) Error ¶
func (are APIResponseError) Error() string
type APIUnmarshalError ¶
type APIUnmarshalError struct {
// contains filtered or unexported fields
}
func (APIUnmarshalError) Error ¶
func (ue APIUnmarshalError) Error() string
type FileDecodeError ¶
type FileDecodeError struct {
Message string
}
func (FileDecodeError) Error ¶
func (f FileDecodeError) Error() string
type FileNotFoundError ¶
type FileNotFoundError struct {
// contains filtered or unexported fields
}
This error should be returned when the requested remote configuration file can not be found.
func (FileNotFoundError) Error ¶
func (nfe FileNotFoundError) Error() string
type GithubAuthParameters ¶
type GithubAuthResponse ¶
type GithubAuthResponse struct { AccessToken string `json:"access_token"` Scope string `json:"scope"` TokenType string `json:"token_type"` }
func GithubAuthenticate ¶
func GithubAuthenticate(ctx context.Context, code, clientId, clientSecret string) (githubResponse *GithubAuthResponse, err error)
GithubAuthenticate does a POST to github with the code that it received, the ClientId, ClientSecret And returns the response which contains the accessToken associated with the user.
type GithubLoginUser ¶
type GithubLoginUser struct { Login string Id int Company string EmailAddress string `json:"email"` Name string OrganizationsURL string }
func GetGithubTokenUser ¶
func GetGithubTokenUser(ctx context.Context, token string, requiredOrg string) (*GithubLoginUser, bool, error)
GetGithubTokenUser fetches a github user associated with an oauth token, and if requiredOrg is specified, checks that it belongs to that org. Returns user object, if it was a member of the specified org (or false if not specified), and error
func (*GithubLoginUser) DisplayName ¶
func (u *GithubLoginUser) DisplayName() string
func (*GithubLoginUser) Email ¶
func (u *GithubLoginUser) Email() string
func (*GithubLoginUser) GetAPIKey ¶
func (u *GithubLoginUser) GetAPIKey() string
func (*GithubLoginUser) GetAccessToken ¶
func (u *GithubLoginUser) GetAccessToken() string
func (*GithubLoginUser) GetRefreshToken ¶
func (u *GithubLoginUser) GetRefreshToken() string
func (*GithubLoginUser) HasPermission ¶
func (u *GithubLoginUser) HasPermission(gimlet.PermissionOpts) bool
func (*GithubLoginUser) IsNil ¶
func (u *GithubLoginUser) IsNil() bool
func (*GithubLoginUser) Roles ¶
func (u *GithubLoginUser) Roles() []string
func (*GithubLoginUser) Username ¶
func (u *GithubLoginUser) Username() string
type GithubMergeGroup ¶
type GithubMergeGroup struct { Org string `bson:"org"` Repo string `bson:"repo"` BaseBranch string `bson:"base_branch"` // BaseBranch is what GitHub merges to HeadBranch string `bson:"head_branch"` // HeadBranch is the merge group's gh-readonly-queue branch // HeadSHA is the SHA of the commit at the head of the merge group. For each // PR in the merge group, GitHub merges the commits from that PR together, // so there are as many commits as there are PRs in the merge group. This is // only the SHA of the first commit in the merge group. HeadSHA string `bson:"head_sha"` // HeadCommit is the title of the commit at the head of the merge group. For // each PR in the merge group, GitHub merges the commits from that PR // together, so there are as many commits as there are PRs in the merge // group. This is only the title of the first commit in the merge group. HeadCommit string `bson:"head_commit"` }
GithubMergeGroup stores patch data for patches created from GitHub merge groups
type GithubPatch ¶
type GithubPatch struct { PRNumber int `bson:"pr_number"` BaseOwner string `bson:"base_owner"` BaseRepo string `bson:"base_repo"` BaseBranch string `bson:"base_branch"` HeadOwner string `bson:"head_owner"` HeadRepo string `bson:"head_repo"` HeadHash string `bson:"head_hash"` HeadBranch string `bson:"head_branch"` Author string `bson:"author"` AuthorUID int `bson:"author_uid"` MergeCommitSHA string `bson:"merge_commit_sha"` CommitTitle string `bson:"commit_title"` CommitMessage string `bson:"commit_message"` MergeBase string `bson:"merge_base"` // the patchId to copy the definitions for for the next patch the pr creates RepeatPatchIdNextPatch string `bson:"repeat_patch_id_next_patch"` }
GithubPatch stores patch data for patches create from GitHub pull requests
type JiraCreateTicketResponse ¶
type JiraCreateTicketResponse struct { Id string `json:"id"` Key string `json:"key"` Self string `json:"self"` }
JiraCreateTicketResponse contains the results of a JIRA create ticket API call.
type JiraCustomField ¶
type JiraHandler ¶
type JiraHandler struct {
// contains filtered or unexported fields
}
func NewJiraHandler ¶
func NewJiraHandler(opts send.JiraOptions) JiraHandler
func (*JiraHandler) CreateTicket ¶
func (jiraHandler *JiraHandler) CreateTicket(fields map[string]interface{}) (*JiraCreateTicketResponse, error)
CreateTicket takes a map of fields to initialize a JIRA ticket with. Returns a response containing the new ticket's key, id, and API URL. See the JIRA API documentation for help.
func (*JiraHandler) GetJIRATicket ¶
func (jiraHandler *JiraHandler) GetJIRATicket(key string) (*JiraTicket, error)
GetJIRATicket returns the ticket with the given key.
func (*JiraHandler) HttpClient ¶
func (jiraHandler *JiraHandler) HttpClient() *http.Client
func (*JiraHandler) JQLSearch ¶
func (jiraHandler *JiraHandler) JQLSearch(query string, startAt, maxResults int) (*JiraSearchResults, error)
JQLSearch runs the given JQL query against the given jira instance and returns the results in a JiraSearchResults
func (*JiraHandler) JQLSearchAll ¶
func (jiraHandler *JiraHandler) JQLSearchAll(query string) ([]JiraTicket, error)
JQLSearchAll performs repeated JQL searches until the query has been exhausted
func (*JiraHandler) JiraHost ¶
func (jiraHandler *JiraHandler) JiraHost() string
JiraHost returns the hostname of the jira service as configured.
func (*JiraHandler) UpdateTicket ¶
func (jiraHandler *JiraHandler) UpdateTicket(key string, fields map[string]interface{}) error
UpdateTicket sets the given fields of the ticket with the given key. Returns any errors JIRA returns.
type JiraProject ¶
type JiraResolution ¶
type JiraSearchResults ¶
type JiraSearchResults struct { Expand string `json:"expand"` StartAt int `json:"startAt"` MaxResults int `json:"maxResults"` Total int `json:"total"` Issues []JiraTicket `json:"issues"` }
JiraSearchResults marshal to and unmarshal from the json search results returned by the rest api at /rest/api/2/search?jql={jql}
type JiraStatus ¶
type JiraTicket ¶
type JiraTicket struct { Key string `json:"key"` Expand string `json:"expand"` Fields *TicketFields `json:"fields"` }
JiraTickets marshal to and unmarshal from the json issue returned by the rest api at /rest/api/latest/issue/{ticket_id}
type PapertrailClient ¶
PapertrailClient is used to interact with the Papertrail service over HTTP. It is recommended to use NewPapertrailClient to initialize this struct.
func NewPapertrailClient ¶
func NewPapertrailClient(keyID, secretKey, address string) *PapertrailClient
NewPapertrailClient returns an initialized PapertrailClient. If address is empty, the default production address is used
func (*PapertrailClient) GetProductVersion ¶
func (c *PapertrailClient) GetProductVersion(ctx context.Context, product, version string) (*PapertrailProductVersion, error)
GetProductVersion calls the Papertrail /product-version endpoint, returning a PapertrailProductVersion with the collection of all spans associated with the product and version passed in.
type PapertrailProductVersion ¶
type PapertrailProductVersion struct { Product string `json:"product"` Version string `json:"version"` Spans []PapertrailSpan `json:"spans"` }
PapertrailProductVersion contains a particular product-version's complete list of spans from Papertrail's /product-versions endpoint
type PapertrailSpan ¶
type PapertrailSpan struct { ID string `json:"id"` SHA256sum string `json:"sha256sum"` Filename string `json:"filename"` Build string `json:"build"` Platform string `json:"platform"` Product string `json:"product"` Version string `json:"version"` Submitter string `json:"submitter"` KeyID string `json:"key_id"` Time uint64 `json:"time"` }
PapertrailSpan represents a span in json form from Papertrail.
type ResponseReadError ¶
type ResponseReadError struct {
// contains filtered or unexported fields
}
func (ResponseReadError) Error ¶
func (re ResponseReadError) Error() string
type SearchReturnInfo ¶
type SearchReturnInfo struct { Issues []JiraTicket `json:"issues"` Search string `json:"search"` Source string `json:"source"` FeaturesURL string `json:"features_url"` }
type SendGithubStatusInput ¶
type SendGithubStatusInput struct { VersionId string Owner string Repo string Ref string Desc string Caller string Context string }
SendGithubStatusInput is the input to the SendPendingStatusToGithub function and contains all the information associated with a version necessary to send a status to GitHub.
type Summary ¶
type Summary struct { Name string `bson:"filename"` Additions int `bson:"additions"` Deletions int `bson:"deletions"` Description string `bson:"description,omitempty"` }
Summary stores summary patch information
func GetGithubPullRequestDiff ¶
func GetGithubPullRequestDiff(ctx context.Context, token string, gh GithubPatch) (string, []Summary, error)
GetGithubPullRequestDiff downloads a diff from a Github Pull Request diff
func GetPatchSummaries ¶
type TicketFields ¶
type TicketFields struct { IssueType *TicketType `json:"issuetype"` Summary string `json:"summary"` Description string `json:"description"` Reporter *User `json:"reporter"` Assignee *User `json:"assignee"` Project *JiraProject `json:"project"` Resolution *JiraResolution `json:"resolution"` Created string `json:"created"` Updated string `json:"updated"` Status *JiraStatus `json:"status"` AssignedTeam []*JiraCustomField `json:"customfield_12751"` }
type TicketType ¶
type TraceArgs ¶
type TraceArgs struct { // Build is the unique identifier for a particular job run in a CI system. // For evergreen jobs, this is in the form "{task_id}_{execution}" Build string // Platform is the Papertrail-internal name for this CI service. It should // always be set to Evergreen unless doing testing Platform string // Filename is the basename of the file that is being traced Filename string // Sha256 is the hex-encoded checksum of the file that is being traced Sha256 string // Product is the product name to associate this file with (e.g. compass) Product string // Version is the version name to associate this file with (e.g. 1.0.0) Version string // Submitter is the username in the CI system to associate this trace with. Submitter string }
TraceArgs contain the list of items necessary to pass to Papertrail
type YAMLFormatError ¶
type YAMLFormatError struct {
Message string
}
func (YAMLFormatError) Error ¶
func (y YAMLFormatError) Error() string