github

package
v0.0.0-...-50752a0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const AppStudioAppDataOrg = "redhat-appstudio-appdata"

Variables

View Source
var Clients map[string]*GitHubClient

Tokens is mapping of token names to GitHub tokens

Functions

func GenerateNewRepositoryName

func GenerateNewRepositoryName(displayName, uniqueHash string) string

GenerateNewRepositoryName creates a new gitops repository name, based on the following format: <display-name>-<partial-hash-of-clustername-and-namespace>-<random-word>-<random-word>

func GetMockedClient

func GetMockedClient() *github.Client

GetMockedClient returns a simple mocked go-github client

func GetMockedPrimaryRateLimitedClient

func GetMockedPrimaryRateLimitedClient() *github.Client

func GetMockedResetPrimaryRateLimitedClient

func GetMockedResetPrimaryRateLimitedClient() *github.Client

func GetMockedSecondaryRateLimitedClient

func GetMockedSecondaryRateLimitedClient() *github.Client

func GetRepoAndOrgFromURL

func GetRepoAndOrgFromURL(repoURL string) (string, string, error)

GetRepoAndOrgFromURL returns both the github org and repository name from a given github URL Format must be of the form: <github-domain>/owner/repository(.git) If .git is appended to the end, it will be removed from the returned repo name

func GetRepoNameFromURL

func GetRepoNameFromURL(repoURL string, orgName string) (string, error)

GetRepoNameFromURL returns the repository name from the Git repo URL

func ParseGitHubTokens

func ParseGitHubTokens() error

ParseGitHubTokens parses all of the possible GitHub tokens available to HAS and makes them available within the "github" package This function should *only* be called once: at operator startup.

func WriteError

func WriteError(
	w http.ResponseWriter,
	httpStatus int,
	msg string,
	errors ...github.Error,
)

WriteError - based on the mock implementation to handle writing back a response workaround until PR https://github.com/migueleliasweb/go-github-mock/pull/41 is merged

Types

type ContextKey

type ContextKey string
const (
	GHClientKey ContextKey = "ghClient"
)

type GitHubClient

type GitHubClient struct {
	TokenName          string
	Token              string
	Client             *github.Client
	SecondaryRateLimit SecondaryRateLimit
	PrimaryRateLimited bool // flag to denote if the token has been near primary rate limited
}

GitHubClient represents a Go-GitHub client, along with the name of the GitHub token that was used to initialize it

func (*GitHubClient) DeleteRepository

func (g *GitHubClient) DeleteRepository(ctx context.Context, orgName string, repoName string) error

Delete Repository takes in the given repository URL and attempts to delete it

func (*GitHubClient) GenerateNewRepository

func (g *GitHubClient) GenerateNewRepository(ctx context.Context, orgName string, repoName string, description string) (string, error)

func (*GitHubClient) GetBranchFromURL

func (g *GitHubClient) GetBranchFromURL(repoURL string, ctx context.Context, branchName string) (*github.Branch, error)

GetBranchFromURL returns the requested branch of a given repoURL

func (*GitHubClient) GetDefaultBranchFromURL

func (g *GitHubClient) GetDefaultBranchFromURL(repoURL string, ctx context.Context) (string, error)

GetDefaultBranchFromURL returns the default branch of a given repoURL

func (*GitHubClient) GetGitStatus

func (g *GitHubClient) GetGitStatus(ctx context.Context) (bool, error)

GetGitStatus returns the status of the Git API with a simple noop call

func (*GitHubClient) GetLatestCommitSHAFromRepository

func (g *GitHubClient) GetLatestCommitSHAFromRepository(ctx context.Context, repoName string, orgName string, branch string) (string, error)

GetLatestCommitSHAFromRepository gets the latest Commit SHA from the repository

type GitHubSystemErr

type GitHubSystemErr struct {
	Err string
}

GitHubSystemErr is a system related error for the GitHub related operations

func (*GitHubSystemErr) Error

func (e *GitHubSystemErr) Error() string

type GitHubToken

type GitHubToken interface {
	GetNewGitHubClient(token string) (*GitHubClient, error)
}

type GitHubTokenClient

type GitHubTokenClient struct {
}

func (GitHubTokenClient) GetNewGitHubClient

func (g GitHubTokenClient) GetNewGitHubClient(token string) (*GitHubClient, error)

GetNewGitHubClient returns a Go-GitHub client If a token is passed in (non-empty string) it will use that token for the GitHub client If no token is passed in (empty string), a token will be randomly selected by HAS. It returns the GitHub client, and (if a token was randomly selected) the name of the token used for the client If an error is encountered retrieving the token, or initializing the client, an error is returned

type GitHubUserErr

type GitHubUserErr struct {
	Err string
}

GitHubUserErr is a user related error for the GitHub related operations

func (*GitHubUserErr) Error

func (e *GitHubUserErr) Error() string

type MockGitHubTokenClient

type MockGitHubTokenClient struct {
}

func (MockGitHubTokenClient) GetNewGitHubClient

func (g MockGitHubTokenClient) GetNewGitHubClient(token string) (*GitHubClient, error)

GetNewGitHubClient returns a mocked Go-GitHub client. No actual tokens are passed in or used when this function is called

type MockPrimaryRateLimitGitHubTokenClient

type MockPrimaryRateLimitGitHubTokenClient struct {
}

func (MockPrimaryRateLimitGitHubTokenClient) GetNewGitHubClient

func (g MockPrimaryRateLimitGitHubTokenClient) GetNewGitHubClient(token string) (*GitHubClient, error)

type MockResetPrimaryRateLimitGitHubTokenClient

type MockResetPrimaryRateLimitGitHubTokenClient struct {
}

func (MockResetPrimaryRateLimitGitHubTokenClient) GetNewGitHubClient

func (g MockResetPrimaryRateLimitGitHubTokenClient) GetNewGitHubClient(token string) (*GitHubClient, error)

type SecondaryRateLimit

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

type ServerError

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

ServerError is used to identify gitops repo creation failures caused by server errors

func (*ServerError) Error

func (e *ServerError) Error() string

Jump to

Keyboard shortcuts

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