Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAndWrapForKnownErrors(resp *github.Response, err error) (bool, error)
- func ClearCaches()
- func Configure(api *operations.ClaAPI, clientID, clientSecret, accessToken string, ...)
- func EditIssueCommentIfChanged(ctx context.Context, client *github.Client, owner, repo string, prNum int, ...) (bool, error)
- func ExpandWithCoAuthors(ctx context.Context, client *github.Client, usersService users.Service, ...) bool
- func GetCoAuthorsFromCommit(ctx context.Context, commit *github.RepositoryCommit) [][2]string
- func GetCommitAuthorSignedStatus(ctx context.Context, usersService users.Service, ...)
- func GetCommitAuthorsSignedStatuses(ctx context.Context, usersService users.Service, ...) ([]*UserCommitSummary, []*UserCommitSummary)
- func GetGitHubRepository(ctx context.Context, installationID, githubRepositoryID int64) (*github.Repository, error)
- func GetGithubUserByID(ctx context.Context, client *github.Client, githubID int64) (*github.User, error)
- func GetGithubUserByLogin(ctx context.Context, client *github.Client, login string) (*github.User, error)
- func GetInstallationRepositories(ctx context.Context, installationID int64) ([]*github.Repository, error)
- func GetMembership(ctx context.Context, user, organizationName string) (*github.Membership, error)
- func GetOrganization(ctx context.Context, organizationName string) (*github.Organization, error)
- func GetOrganizationMembers(ctx context.Context, orgName string, installationID int64) ([]string, error)
- func GetPRCommitSHA(ctx context.Context, gh *github.Client, owner, repo string, prNumber int) (string, error)
- func GetPullRequest(ctx context.Context, pullRequestID int, owner, repo string, ...) (*github.PullRequest, error)
- func GetRepositories(ctx context.Context, organizationName string) ([]*github.Repository, error)
- func GetRepositoryByExternalID(ctx context.Context, installationID, id int64) (*github.Repository, error)
- func GetReturnURL(ctx context.Context, installationID, repositoryID int64, pullRequestID int) (string, error)
- func GetUserDetails(user string) (*github.User, error)
- func Init(ghAppID int, ghAppPrivateKey string, secAccessToken string)
- func IsCoAuthorsEnabledForRepo(enableCoAuthors map[string]bool, orgRepo string) bool
- func IsValidGitHubUsername(username string) bool
- func ListPullRequestCommitsCompare(ctx context.Context, client *github.Client, owner, repo string, ...) ([]*github.RepositoryCommit, error)
- func ListUserPublicOrgs(ctx context.Context, user string) ([]string, error)
- func NewGithubAppClient(installationID int64) (*github.Client, error)
- func NewGithubOauthClient() *github.Client
- func NewGithubOauthClientWithAccessToken(accessToken string) *github.Client
- func NewGithubV4AppClient(installationID int64) (*githubv4.Client, error)
- func NormalizeComment(s string) string
- func ProjectUserKey(projectID, id, login, email string) [4]string
- func SearchGithubUserByEmail(ctx context.Context, client *github.Client, email string) (*github.User, error)
- func SkipAllowlistedBots(ev events.Service, orgModel *models.GithubOrganization, ...) ([]*UserCommitSummary, []*UserCommitSummary)
- func TrimComment(html string, maxItems, head, tail int, ellipsis string) string
- func UpdateCacheAfterSignature(ctx context.Context, user *models.User, projectID string) error
- func UpdatePullRequest(ctx context.Context, installationID int64, pullRequestID int, ...) error
- func UpdatePullRequestLegacyCompat(ctx context.Context, installationID int64, pullRequestID int, ...) error
- func UserKey(id, login, email string) [3]string
- type Cache
- type GraphQLError
- type ProjectUserCache
- func (c *ProjectUserCache) Cleanup()
- func (c *ProjectUserCache) Clear()
- func (c *ProjectUserCache) Delete(key [4]string)
- func (c *ProjectUserCache) Get(key [4]string) (*models.User, bool, bool, bool)
- func (c *ProjectUserCache) InvalidateByProject(projectID string) int
- func (c *ProjectUserCache) InvalidateByUser(projectID, id, login string) int
- func (c *ProjectUserCache) Set(key [4]string, value *models.User, signed, affiliated bool)
- func (c *ProjectUserCache) SetWithTTL(key [4]string, value *models.User, signed, affiliated bool, tl time.Duration)
- type Status
- type UserCache
- func (c *UserCache) Cleanup()
- func (c *UserCache) Clear()
- func (c *UserCache) Delete(key [3]string)
- func (c *UserCache) Get(key [3]string) (*models.User, bool)
- func (c *UserCache) InvalidateByUser(id, login string) int
- func (c *UserCache) Set(key [3]string, value *models.User)
- func (c *UserCache) SetWithTTL(key [3]string, value *models.User, tl time.Duration)
- type UserCommitSummary
- func DedupAndSortCommitSummaries(items []*UserCommitSummary) []*UserCommitSummary
- func GetCoAuthorCommits(ctx context.Context, client *github.Client, usersService users.Service, ...) (*UserCommitSummary, bool)
- func GetPullRequestCommitAuthors(ctx context.Context, usersService users.Service, installationID int64, ...) ([]*UserCommitSummary, bool, error)
- func GetPullRequestCommitAuthorsCompare(ctx context.Context, usersService users.Service, installationID int64, ...) ([]*UserCommitSummary, bool, error)
- func GetPullRequestCommitAuthorsREST(ctx context.Context, usersService users.Service, installationID int64, ...) ([]*UserCommitSummary, bool, error)
Constants ¶
const ( NegativeCacheTTL = 2 * time.Minute // Used for negative caching of missing/not-signed users ProjectCacheTTL = 15 * time.Minute // Used for per-project caching of signed users MaxCommentLength = 0xff00 // 65520 characters - leave some buffer under 64KB limit )
const MissingCoAuthorsMessage = `` /* 1154-byte string literal not displayed */
Note: we use | and ||| as placeholders for inline and fenced code, then swap to backticks at render time.
const (
// SessionStoreKey is the key used to lookup the session
SessionStoreKey = "cla-github"
)
Variables ¶
var ( // ErrAccessDenied is returned whenever github return 403 or 401 ErrAccessDenied = errors.New("access denied") // ErrRateLimited is returned when github detects rate limit abuse ErrRateLimited = errors.New("rate limit") )
var ( // ErrGitHubRepositoryNotFound is returned when github repository is not found ErrGitHubRepositoryNotFound = errors.New("github repository not found") NoreplyIDPattern = regexp.MustCompile(`^(\d+)\+([a-zA-Z0-9-]+)@users\.noreply\.github\.com$`) NoreplyUserPattern = regexp.MustCompile(`^([a-zA-Z0-9-]+)@users\.noreply\.github\.com$`) GithubUsernameRegex = regexp.MustCompile(`^[A-Za-z0-9-]{3,39}$`) ListCommitsParallelLimit = 4 )
var (
ErrGithubOrganizationNotFound = errors.New("github organization name not found")
)
errors
var GithubUserCache = NewCache(12 * time.Hour)
var ModelProjectUserCache = NewProjectUserCache(3 * time.Hour)
var ModelUserCache = NewUserCache(12 * time.Hour)
Functions ¶
func CheckAndWrapForKnownErrors ¶
CheckAndWrapForKnownErrors checks for some of the known error types
func ClearCaches ¶
func ClearCaches()
ClearCaches clears all in-memory caches maintained by the GitHub module.
func Configure ¶
func Configure(api *operations.ClaAPI, clientID, clientSecret, accessToken string, sessionStore *dynastore.Store)
Configure API call
func EditIssueCommentIfChanged ¶
func EditIssueCommentIfChanged(ctx context.Context, client *github.Client, owner, repo string, prNum int, commentID int64, newBody string) (bool, error)
EditIssueCommentIfChanged fetches the existing comment and edits only if NormalizeComment(existing) != NormalizeComment(newBody). Returns true if edited.
func ExpandWithCoAuthors ¶
func ExpandWithCoAuthors( ctx context.Context, client *github.Client, usersService users.Service, commit *github.RepositoryCommit, pr int, installationID int64, commitAuthors *[]*UserCommitSummary, mu *sync.Mutex, ) bool
ExpandWithCoAuthors appends UserCommitSummary objects for all co-authors to commitAuthors slice.
func GetCoAuthorsFromCommit ¶
func GetCoAuthorsFromCommit( ctx context.Context, commit *github.RepositoryCommit, ) [][2]string
GetCoAuthorsFromCommit returns a slice of [2]string, each representing [name, email] of a co-author.
func GetCommitAuthorSignedStatus ¶
func GetCommitAuthorSignedStatus( ctx context.Context, usersService users.Service, hasUserSigned func(context.Context, *models.User, string) (*bool, *bool, error), projectID string, userSummary *UserCommitSummary, signed *[]*UserCommitSummary, unsigned *[]*UserCommitSummary, mu *sync.Mutex, )
GetCommitAuthorSignedStatus checks if the commit author has signed the CLA for the given project
func GetGitHubRepository ¶
func GetGithubUserByID ¶
func GetGithubUserByID(ctx context.Context, client *github.Client, githubID int64) (*github.User, error)
GetGitHubUserByID fetches a GitHub user by their GitHubID. Returns (*github.User, nil) if found, (nil, nil) if not found, or (nil, error) on error.
func GetGithubUserByLogin ¶
func GetGithubUserByLogin(ctx context.Context, client *github.Client, login string) (*github.User, error)
GetGitHubUserByLogin fetches a GitHub user by their login (username). Returns (*github.User, nil) if found, (nil, nil) if not found, or (nil, error) on error.
func GetInstallationRepositories ¶
func GetInstallationRepositories(ctx context.Context, installationID int64) ([]*github.Repository, error)
GetInstallationRepositories returns list of repositories for github app installation
func GetMembership ¶
GetOrganization gets github organization
func GetOrganization ¶
GetOrganization gets github organization
func GetOrganizationMembers ¶
func GetOrganizationMembers(ctx context.Context, orgName string, installationID int64) ([]string, error)
GetOrganizationMembers gets members in organization
func GetPRCommitSHA ¶
func GetPRCommitSHA(ctx context.Context, gh *github.Client, owner, repo string, prNumber int) (string, error)
Commit SHA for a PR (authoritative "last commit")
func GetPullRequest ¶
func GetRepositories ¶
GetRepositories gets github repositories by organization
func GetRepositoryByExternalID ¶
func GetRepositoryByExternalID(ctx context.Context, installationID, id int64) (*github.Repository, error)
GetRepositoryByExternalID finds github repository by github repository id
func GetReturnURL ¶
func GetUserDetails ¶
GetUserDetails return github users details
func IsCoAuthorsEnabledForRepo ¶
IsCoAuthorsEnabledForRepo returns whether co-authors are enabled for this repo
func IsValidGitHubUsername ¶
IsValidGitHubUsername checks if the provided username is a valid GitHub username.
func ListUserPublicOrgs ¶
ListUserPublicOrgs returns the GitHub organization logins that <user> is a publicly visible member of. It calls GET /users/<user>/orgs, which is the same endpoint the pre-cutover Python helper cla.utils.lookup_github_organizations used. Membership in private orgs is invisible to this endpoint unless the user has set their membership to public on github.com.
Returns an empty slice (with a nil error) when the user has no visible org memberships. The github-org approval-list check must be done against this list (case-insensitive) rather than against /orgs/<org>/memberships/<user>, because the EasyCLA OAuth bot is not itself a member of customer orgs and gets a 403 from the latter endpoint.
An empty user is rejected with an error: go-github routes an empty user to GET /user/orgs (the authenticated bot's own orgs), which would silently approve unrelated callers if it ever leaked through.
func NewGithubAppClient ¶
NewGithubAppClient creates a new github client from the supplied installationID
func NewGithubOauthClient ¶
NewGithubOauthClient creates github client from global accessToken
func NewGithubOauthClientWithAccessToken ¶
NewGithubOauthClientWithAccessToken creates github client from specified accessToken
func NewGithubV4AppClient ¶
NewGithubV4AppClient creates a new github v4 client from the supplied installationID
func NormalizeComment ¶
NormalizeComment mirrors Python normalize_comment
func ProjectUserKey ¶
func SearchGithubUserByEmail ¶
func SearchGithubUserByEmail(ctx context.Context, client *github.Client, email string) (*github.User, error)
SearchGithubUserByEmail searches for a GitHub user by email using the GitHub search API. Returns the first found *github.User, or nil if not found or on error.
func SkipAllowlistedBots ¶
func SkipAllowlistedBots(ev events.Service, orgModel *models.GithubOrganization, orgRepo, projectID string, actorsMissingCLA []*UserCommitSummary) ([]*UserCommitSummary, []*UserCommitSummary)
SkipAllowlistedBots- check if the actors are allowlisted based on the skip_cla configuration. Returns two lists: - actors still missing cla: actors who still need to sign the CLA after checking skip_cla - allowlisted actors: actors who are skipped due to skip_cla configuration :param orgModel: The GitHub organization model instance. :param orgRepo: The repository name in the format 'org/repo'. :param actorsMissingCla: List of UserCommitSummary objects representing actors who are missing CLA. :return: two arrays (actors still missing CLA, allowlisted actors) : in cla-{stage}-github-orgs table there can be a skip_cla field which is a dict with the following structure:
{
"repo-name": "<login_pattern>;<email_pattern>;<name_pattern>",
"re:repo-regexp": "[<login_pattern>;<email_pattern>;<name_pattern>||...]",
"*": "<login_pattern>"
}
where:
- repo-name is the exact repository name under given org (e.g., "my-repo" not "my-org/my-repo")
- re:repo-regexp is a regex pattern to match repository names
- * is a wildcard that applies to all repositories
- <login_pattern> is a GitHub login pattern (exact match or regex prefixed by re: or match all '*') if not specified defaults to ""
- <email_pattern> is a GitHub email pattern (exact match or regex prefixed by re: or match all '*') if not specified defaults to ""
- <name_pattern> is a GitHub name pattern (exact match or regex prefixed by re: or match all '*') if not specified defaults to "" "" matches empty value, null value or missing property The login, email and name patterns are separated by a semicolon (;). Email and name parts are optional. There can be an array of patterns for a single repository, separated by ||. It must start with a '[' and end with a ']': "[...||...||...]" If the skip_cla is not set, it will skip the allowlisted bots check.
func TrimComment ¶
TrimComment collapses any "(sha1, sha2, ...)" group where all tokens look like SHAs (7–40 hex). If a group has > maxItems, it keeps the first `head`, then an ellipsis, then the last `tail`.
func UpdateCacheAfterSignature ¶
UpdateCacheAfterSignature marks the user as authorized for the given project
func UpdatePullRequest ¶
Types ¶
type GraphQLError ¶
type GraphQLError struct {
Errs []gqlError
}
func (*GraphQLError) Error ¶
func (e *GraphQLError) Error() string
type ProjectUserCache ¶
type ProjectUserCache struct {
// contains filtered or unexported fields
}
func NewProjectUserCache ¶
func NewProjectUserCache(ttl time.Duration) *ProjectUserCache
func (*ProjectUserCache) Cleanup ¶
func (c *ProjectUserCache) Cleanup()
func (*ProjectUserCache) Clear ¶
func (c *ProjectUserCache) Clear()
func (*ProjectUserCache) Delete ¶
func (c *ProjectUserCache) Delete(key [4]string)
func (*ProjectUserCache) InvalidateByProject ¶
func (c *ProjectUserCache) InvalidateByProject(projectID string) int
InvalidateByProject removes every entry for the given project, regardless of user. Used after an approval-list mutation (UpdateApprovalList), since any cached signed/authorized decision under that project may now be stale: users newly added to email/domain/org/github approvals must flip red→green, and users removed must flip green→red. Cache misses for affected webhooks are then resolved against fresh DDB state on next read.
func (*ProjectUserCache) InvalidateByUser ¶
func (c *ProjectUserCache) InvalidateByUser(projectID, id, login string) int
InvalidateByUser removes every entry whose (projectID, id, login) prefix matches, regardless of the email component. The login is lowercased internally to match how ProjectUserKey stores it, so callers may pass either the original GitHub login or a pre-lowercased form. Used after a signature event to drop stale per-project entries keyed on commit-email shapes the caller cannot enumerate (e.g. the GitHub noreply form emitted when a user has email privacy enabled).
func (*ProjectUserCache) Set ¶
func (c *ProjectUserCache) Set(key [4]string, value *models.User, signed, affiliated bool)
func (*ProjectUserCache) SetWithTTL ¶
type Status ¶
type UserCache ¶
type UserCache struct {
// contains filtered or unexported fields
}
func NewUserCache ¶
func (*UserCache) InvalidateByUser ¶
InvalidateByUser removes every entry whose (id, login) prefix matches, regardless of the email component. The login is lowercased internally to match how UserKey stores it, so callers may pass either the original GitHub login or a pre-lowercased form. Used after a signature event to drop stale entries keyed on commit-email shapes the caller cannot enumerate (e.g. the GitHub noreply form emitted when a user has email privacy enabled).
type UserCommitSummary ¶
type UserCommitSummary struct {
SHA string
CommitAuthor *github.User
Affiliated bool
Authorized bool
}
UserCommitSummary data model
func DedupAndSortCommitSummaries ¶
func DedupAndSortCommitSummaries(items []*UserCommitSummary) []*UserCommitSummary
DedupAndSortCommitSummaries mirrors Python dedup_and_sort Dedupe key: (author_id, login, email, sha) Sort key: login, name, email, sha (all case-insensitive)
func GetCoAuthorCommits ¶
func (UserCommitSummary) GetCommitAuthorEmail ¶
func (u UserCommitSummary) GetCommitAuthorEmail() string
GetCommitAuthorEmail returns commit author email if available, otherwise returns empty string
func (UserCommitSummary) GetCommitAuthorID ¶
func (u UserCommitSummary) GetCommitAuthorID() string
GetCommitAuthorID commit author username ID (numeric value as a string) if available, otherwise returns empty string
func (UserCommitSummary) GetCommitAuthorUsername ¶
func (u UserCommitSummary) GetCommitAuthorUsername() string
GetCommitAuthorUsername returns commit author username if available, otherwise returns empty string
func (UserCommitSummary) GetDisplayText ¶
func (u UserCommitSummary) GetDisplayText(tagUser bool) string
GetDisplayText returns the display text for the user commit summary
func (UserCommitSummary) IsValid ¶
func (u UserCommitSummary) IsValid() bool
IsValid returns true if the commit author information is available
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package branch_protection is a generated GoMock package.
|
Package branch_protection is a generated GoMock package. |