ghutil

package
v0.0.0-...-eae4eb0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ghutil provides utility methods for determining CLA compliance of pull requests on GitHub repositories, and adding/removing labels and comments.

Index

Constants

View Source
const (
	LabelClaYes      = "cla: yes"
	LabelClaNo       = "cla: no"
	LabelClaExternal = "cla: external"
)

The CLA-related labels we expect to be predefined on a given repository.

Variables

This section is empty.

Functions

func AuthorLogin

func AuthorLogin(c *github.RepositoryCommit) string

AuthorLogin retrieves the author from a `RepositoryCommit`.

Per go-github project docs in `github/repos_commits.go`:

> RepositoryCommit represents a commit in a repo. > Note that it's wrapping a Commit, so author/committer information is > in two places, but contain different details about them: in > RepositoryCommit "github details", in Commit - "git details".

func CanonicalizeEmail

func CanonicalizeEmail(email string) string

CanonicalizeEmail returns a canonical version of the email address. For all addresses, it will lowercase the email. For Gmail addresses, it will also remove the periods in the email address, as those are ignored, and hence "user.name@gmail.com" is equivalent to "username@gmail.com" .

func CommitterLogin

func CommitterLogin(c *github.RepositoryCommit) string

CommitterLogin retrieves the committer from a `RepositoryCommit`.

See also the docs for `AuthorLogin` for additional information.

func IsExternal

func IsExternal(commit *github.RepositoryCommit, claSigners config.ClaSigners, unknownAsExternal bool) bool

IsExternal computes whether the given commit should be processed by this tool, or if it should be covered by an external CLA management tool.

func MatchAccount

func MatchAccount(account config.Account, accounts []config.Account) bool

MatchAccount returns whether the provided account matches any of the accounts in the passed-in configuration for enforcing the CLA.

Types

type CommitStatus

type CommitStatus struct {
	Compliant           bool
	NonComplianceReason string
	External            bool
}

CommitStatus provides a signal as to the CLA-compliance of a specific commit.

func ProcessCommit

func ProcessCommit(commit *github.RepositoryCommit, claSigners config.ClaSigners) CommitStatus

ProcessCommit processes a single commit and returns compliance status and failure reason, if any.

type GitHubClient

type GitHubClient struct {
	// Note: we can't simply use `*GitHubUtilApi` to import all the
	// interface methods here, as they will not be assignable fields and
	// compile will error out with:
	//
	//     cannot use promoted field GitHubUtilApi.GetAllRepos in struct literal of type GitHubClient
	//
	// for each of the methods listed here.
	GetAllRepos                func(*GitHubClient, string, string) []*github.Repository
	CheckPullRequestCompliance func(*GitHubClient, GitHubProcessSinglePullSpec, config.ClaSigners) (PullRequestStatus, error)
	ProcessPullRequest         func(*GitHubClient, GitHubProcessSinglePullSpec, config.ClaSigners, RepoClaLabelStatus) error
	ProcessOrgRepo             func(*GitHubClient, GitHubProcessOrgRepoSpec, config.ClaSigners)
	GetIssueClaLabelStatus     func(*GitHubClient, string, string, int) IssueClaLabelStatus
	GetRepoClaLabelStatus      func(*GitHubClient, string, string) RepoClaLabelStatus

	Organizations OrganizationsService
	Repositories  RepositoriesService
	Issues        IssuesService
	PullRequests  PullRequestsService
}

GitHubClient provides an interface to the GitHub APIs used in this module.

func NewBasicClient

func NewBasicClient() *GitHubClient

NewBasicClient returns a new client with only local methods bound; no external methods (which require an `http.Client`) are available so this client is only partially-constructed and can be used either in production with additional bindings added in `NewClient` or for testing by assigning mocked methods for the other services.

func NewClient

func NewClient(tc *http.Client) *GitHubClient

NewClient creates a client to work with the GitHub API.

type GitHubProcessOrgRepoSpec

type GitHubProcessOrgRepoSpec struct {
	Org               string
	Repo              string
	Pulls             []int
	UpdateRepo        bool
	UnknownAsExternal bool
}

GitHubProcessOrgRepoSpec is the specification of the work to be done for an organization and repo (possibly multiple PRs).

type GitHubProcessSinglePullSpec

type GitHubProcessSinglePullSpec struct {
	Org               string
	Repo              string
	Pull              *github.PullRequest
	UpdateRepo        bool
	UnknownAsExternal bool
}

GitHubProcessSinglePullSpec is the specification of work to be processed for a single PR, carrying over the rest of the configuration settings from GitHubProcessOrgRepoSpec.

type GitHubUtilApi

GitHubUtilApi is the locally-defined API for interfacing with GitHub, using the methods in GitHubClient.

type IssueClaLabelStatus

type IssueClaLabelStatus struct {
	HasYes      bool
	HasNo       bool
	HasExternal bool
}

IssueClaLabelStatus provides the settings of CLA-related labels for a particular issue.

type IssuesService

type IssuesService interface {
	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)
	GetLabel(ctx context.Context, owner string, repo string, name string) (*github.Label, *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)
}

IssuesService is the subset of `github.IssuesService` used by this module.

type OrganizationsService

type OrganizationsService interface {
}

OrganizationsService is the subset of `github.OrganizationsService` used by this module.

type PullRequestStatus

type PullRequestStatus struct {
	Compliant           bool
	NonComplianceReason string
	External            bool
}

PullRequestStatus provides the CLA status for the entire PR, which considers all of the commits. In this case, any single commit being out of compliance (or external) marks the entire PR as being out of compliance (or external). The only way to have a fully-compliant PR is to have all commits on the PR compliant.

type PullRequestsService

type PullRequestsService interface {
	List(ctx context.Context, owner string, repo string, opt *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error)
	ListCommits(ctx context.Context, owner string, repo string, number int, opt *github.ListOptions) ([]*github.RepositoryCommit, *github.Response, error)
	Get(ctx context.Context, owner string, repo string, number int) (*github.PullRequest, *github.Response, error)
}

PullRequestsService is the subset of `github.PullRequestsService` used by this module.

type RepoClaLabelStatus

type RepoClaLabelStatus struct {
	HasYes      bool
	HasNo       bool
	HasExternal bool
}

RepoClaLabelStatus provides the availability of CLA-related labels in the repo.

type RepositoriesService

type RepositoriesService interface {
	Get(ctx context.Context, owner string, repo string) (*github.Repository, *github.Response, error)
	List(ctx context.Context, user string, opt *github.RepositoryListOptions) ([]*github.Repository, *github.Response, error)
}

RepositoriesService is the subset of `github.RepositoriesService` used by this module.

Jump to

Keyboard shortcuts

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