ghapi

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_GITHUB_API_BASE_URL = "https://api.github.com"
)

Variables

Functions

func GenerateRepoList

func GenerateRepoList(ctx context.Context, ghAppInstallation *GitHubAppInstallation, config *types.RepositoryConfig) ([]string, error)

GenerateRepoList generates a list of repositories to target for inspection

func ValidateAndNormalizeRepositoryIdentifier

func ValidateAndNormalizeRepositoryIdentifier(identifier string) (string, bool)

ValidateAndNormalizeRepositoryIdentifier tries to extract the repository identifier in the <owner>/<repo> format and returns it, if possible

Types

type GHAPIRate added in v0.2.0

type GHAPIRate struct {
	Limit     int   `json:"limit"`
	Remaining int   `json:"remaining"`
	Reset     int64 `json:"reset"`
}

type GHAPIResponseAccount

type GHAPIResponseAccount struct {
	Login            string `json:"login"`
	ID               int    `json:"id"`
	NodeID           string `json:"node_id"`
	URL              string `json:"url"`
	ReposURL         string `json:"repos_url"`
	EventsURL        string `json:"events_url"`
	HooksURL         string `json:"hooks_url"`
	IssuesURL        string `json:"issues_url"`
	MembersURL       string `json:"members_url"`
	PublicMembersURL string `json:"public_members_url"`
	AvatarURL        string `json:"avatar_url"`
	Description      string `json:"description"`
}

type GHAPIResponseHook

type GHAPIResponseHook struct {
	Type         string                      `json:"type"`
	ID           int                         `json:"id"`
	Name         string                      `json:"name"`
	Active       bool                        `json:"active"`
	Events       []string                    `json:"events"`
	Config       GHAPIResponseHookConfig     `json:"config"`
	UpdatedAt    time.Time                   `json:"updated_at"`
	CreatedAt    time.Time                   `json:"created_at"`
	URL          string                      `json:"url"`
	TestURL      string                      `json:"test_url"`
	PingURL      string                      `json:"ping_url"`
	LastResponse GHAPIResponseHookLastStatus `json:"last_response"`
}

GHAPIResponseHook represents a single list item of the GitHub repository webhook API response

type GHAPIResponseHookConfig

type GHAPIResponseHookConfig struct {
	ContentType string `json:"content_type"`
	InsecureSSL string `json:"insecure_ssl"`
	URL         string `json:"url"`
}

type GHAPIResponseHookLastStatus

type GHAPIResponseHookLastStatus struct {
	Code    int    `json:"code"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

GHAPIResponseHookLastStatus represents the last_response part of a single webhook item in the GitHub repository webhook API response

type GHAPIResponseInstallationDetails

type GHAPIResponseInstallationDetails struct {
	ID                  int                  `json:"id"`
	Account             GHAPIResponseAccount `json:"account"`
	AccessTokensURL     string               `json:"access_tokens_url"`
	RepositoriesURL     string               `json:"repositories_url"`
	HTMLURL             string               `json:"html_url"`
	AppID               int                  `json:"app_id"`
	TargetID            int                  `json:"target_id"`
	TargetType          string               `json:"target_type"`
	Permissions         map[string]string    `json:"permissions"`
	Events              []string             `json:"events"`
	SingleFileName      string               `json:"single_file_name"`
	RepositorySelection string               `json:"repository_selection"`
}

GHAPIResponseInstallationDetails for /app/installations/{installation_id}

type GHAPIResponseInstallationTokenSimplified

type GHAPIResponseInstallationTokenSimplified struct {
	Token               string            `json:"token"`
	ExpiresAt           time.Time         `json:"expires_at"`
	RepositorySelection string            `json:"repository_selection"`
	Permissions         map[string]string `json:"permissions"`
}

GHAPIResponseInstallationTokenSimplified is a simple representation of the response you get when requesting a GitHub App installation token (see https://docs.github.com/en/rest/reference/apps#create-an-installation-access-token-for-an-app)

type GHAPIResponseRateLimit added in v0.2.0

type GHAPIResponseRateLimit struct {
	Resources struct {
		Core struct {
			Limit     int `json:"limit"`
			Remaining int `json:"remaining"`
			Reset     int `json:"reset"`
		} `json:"core"`
		Search struct {
			Limit     int `json:"limit"`
			Remaining int `json:"remaining"`
			Reset     int `json:"reset"`
		} `json:"search"`
		Graphql struct {
			Limit     int `json:"limit"`
			Remaining int `json:"remaining"`
			Reset     int `json:"reset"`
		} `json:"graphql"`
		IntegrationManifest struct {
			Limit     int `json:"limit"`
			Remaining int `json:"remaining"`
			Reset     int `json:"reset"`
		} `json:"integration_manifest"`
		CodeScanningUpload struct {
			Limit     int `json:"limit"`
			Remaining int `json:"remaining"`
			Reset     int `json:"reset"`
		} `json:"code_scanning_upload"`
	} `json:"resources"`
	Rate GHAPIRate `json:"rate"`
}

GHAPIResponseRateLimit represents the API Response for the /rate_limit API

type GHAPIResponseRepos

type GHAPIResponseRepos struct {
	ID       int    `json:"id"`
	NodeID   string `json:"node_id"`
	Name     string `json:"name"`
	FullName string `json:"full_name"`
	Owner    struct {
		Login             string `json:"login"`
		ID                int    `json:"id"`
		NodeID            string `json:"node_id"`
		AvatarURL         string `json:"avatar_url"`
		GravatarID        string `json:"gravatar_id"`
		URL               string `json:"url"`
		HTMLURL           string `json:"html_url"`
		FollowersURL      string `json:"followers_url"`
		FollowingURL      string `json:"following_url"`
		GistsURL          string `json:"gists_url"`
		StarredURL        string `json:"starred_url"`
		SubscriptionsURL  string `json:"subscriptions_url"`
		OrganizationsURL  string `json:"organizations_url"`
		ReposURL          string `json:"repos_url"`
		EventsURL         string `json:"events_url"`
		ReceivedEventsURL string `json:"received_events_url"`
		Type              string `json:"type"`
		SiteAdmin         bool   `json:"site_admin"`
	} `json:"owner"`
	Private          bool        `json:"private"`
	HTMLURL          string      `json:"html_url"`
	Description      string      `json:"description"`
	Fork             bool        `json:"fork"`
	URL              string      `json:"url"`
	ArchiveURL       string      `json:"archive_url"`
	AssigneesURL     string      `json:"assignees_url"`
	BlobsURL         string      `json:"blobs_url"`
	BranchesURL      string      `json:"branches_url"`
	CollaboratorsURL string      `json:"collaborators_url"`
	CommentsURL      string      `json:"comments_url"`
	CommitsURL       string      `json:"commits_url"`
	CompareURL       string      `json:"compare_url"`
	ContentsURL      string      `json:"contents_url"`
	ContributorsURL  string      `json:"contributors_url"`
	DeploymentsURL   string      `json:"deployments_url"`
	DownloadsURL     string      `json:"downloads_url"`
	EventsURL        string      `json:"events_url"`
	ForksURL         string      `json:"forks_url"`
	GitCommitsURL    string      `json:"git_commits_url"`
	GitRefsURL       string      `json:"git_refs_url"`
	GitTagsURL       string      `json:"git_tags_url"`
	GitURL           string      `json:"git_url"`
	IssueCommentURL  string      `json:"issue_comment_url"`
	IssueEventsURL   string      `json:"issue_events_url"`
	IssuesURL        string      `json:"issues_url"`
	KeysURL          string      `json:"keys_url"`
	LabelsURL        string      `json:"labels_url"`
	LanguagesURL     string      `json:"languages_url"`
	MergesURL        string      `json:"merges_url"`
	MilestonesURL    string      `json:"milestones_url"`
	NotificationsURL string      `json:"notifications_url"`
	PullsURL         string      `json:"pulls_url"`
	ReleasesURL      string      `json:"releases_url"`
	SSHURL           string      `json:"ssh_url"`
	StargazersURL    string      `json:"stargazers_url"`
	StatusesURL      string      `json:"statuses_url"`
	SubscribersURL   string      `json:"subscribers_url"`
	SubscriptionURL  string      `json:"subscription_url"`
	TagsURL          string      `json:"tags_url"`
	TeamsURL         string      `json:"teams_url"`
	TreesURL         string      `json:"trees_url"`
	CloneURL         string      `json:"clone_url"`
	MirrorURL        string      `json:"mirror_url"`
	HooksURL         string      `json:"hooks_url"`
	SvnURL           string      `json:"svn_url"`
	Homepage         string      `json:"homepage"`
	Language         interface{} `json:"language"`
	ForksCount       int         `json:"forks_count"`
	StargazersCount  int         `json:"stargazers_count"`
	WatchersCount    int         `json:"watchers_count"`
	Size             int         `json:"size"`
	DefaultBranch    string      `json:"default_branch"`
	OpenIssuesCount  int         `json:"open_issues_count"`
	IsTemplate       bool        `json:"is_template"`
	Topics           []string    `json:"topics"`
	HasIssues        bool        `json:"has_issues"`
	HasProjects      bool        `json:"has_projects"`
	HasWiki          bool        `json:"has_wiki"`
	HasPages         bool        `json:"has_pages"`
	HasDownloads     bool        `json:"has_downloads"`
	Archived         bool        `json:"archived"`
	Disabled         bool        `json:"disabled"`
	Visibility       string      `json:"visibility"`
	PushedAt         time.Time   `json:"pushed_at"`
	CreatedAt        time.Time   `json:"created_at"`
	UpdatedAt        time.Time   `json:"updated_at"`
	Permissions      struct {
		Admin bool `json:"admin"`
		Push  bool `json:"push"`
		Pull  bool `json:"pull"`
	} `json:"permissions"`
	TemplateRepository  interface{} `json:"template_repository"`
	TempCloneToken      string      `json:"temp_clone_token"`
	DeleteBranchOnMerge bool        `json:"delete_branch_on_merge"`
	SubscribersCount    int         `json:"subscribers_count"`
	NetworkCount        int         `json:"network_count"`
	License             struct {
		Key    string `json:"key"`
		Name   string `json:"name"`
		SpdxID string `json:"spdx_id"`
		URL    string `json:"url"`
		NodeID string `json:"node_id"`
	} `json:"license"`
}

GHAPIResponseRepos auto-generated by https://mholt.github.io/json-to-go/ from https://docs.github.com/en/rest/reference/teams#list-team-repositories

type GitHubApp

type GitHubApp struct {
	ID      string
	PemFile string
}

GitHubApp holds all config options that we need to authenticate as a GitHub App installation

func (*GitHubApp) DoAPIRequest

func (ghApp *GitHubApp) DoAPIRequest(method, path string) (*http.Response, error)

DoAPIRequest does a request against the GitHub API and returns the response

type GitHubAppInstallation

type GitHubAppInstallation struct {
	ID                  string
	Token               string
	TokenExpirationTime time.Time
	Organization        string
	ParentApp           *GitHubApp
}

func (*GitHubAppInstallation) DoAPIRequest

func (ghAppInstallation *GitHubAppInstallation) DoAPIRequest(method, path string) (*http.Response, error)

func (*GitHubAppInstallation) GetAPIRateLimit added in v0.2.0

func (ghAppInstallation *GitHubAppInstallation) GetAPIRateLimit() (GHAPIRate, error)

GetAPIRateLimit fills the GitHub App Installation with some required details (like organization)

func (*GitHubAppInstallation) GetDetails

func (ghAppInstallation *GitHubAppInstallation) GetDetails() error

GetDetails fills the GitHub App Installation with some required details (like organization)

func (*GitHubAppInstallation) GetReposByTeamSlug

func (ghAppInstallation *GitHubAppInstallation) GetReposByTeamSlug(teamSlug string) ([]string, error)

func (*GitHubAppInstallation) RefreshToken

func (ghAppInstallation *GitHubAppInstallation) RefreshToken(ctx context.Context) error

RefreshToken uses a JWT token to eventually get an app installation token for git auth

Jump to

Keyboard shortcuts

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