github

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2016 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultURL      = "https://github.com"
	DefaultAPI      = "https://api.github.com"
	DefaultScope    = "repo,repo:status,user:email"
	DefaultMergeRef = "merge"
)
View Source
const (
	StatusPending = "pending"
	StatusSuccess = "success"
	StatusFailure = "failure"
	StatusError   = "error"
)
View Source
const (
	DescPending = "this build is pending"
	DescSuccess = "the build was successful"
	DescFailure = "the build failed"
	DescError   = "oops, something went wrong"
)

Variables

This section is empty.

Functions

func CreateHook

func CreateHook(client *github.Client, owner, name, url string) (*github.Hook, error)

CreateHook is a heper function that creates a post-commit hook for the specified repository.

func CreateKey

func CreateKey(client *github.Client, owner, name, title, key string) (*github.Key, error)

CreateKey is a helper function that creates a deploy key for the specified repository.

func CreateUpdateHook

func CreateUpdateHook(client *github.Client, owner, name, url string) (*github.Hook, error)

CreateUpdateHook is a heper function that creates a post-commit hook for the specified repository if it does not already exist, otherwise it updates the existing hook

func CreateUpdateKey

func CreateUpdateKey(client *github.Client, owner, name, title, key string) (*github.Key, error)

CreateUpdateKey is a helper function that creates a deployment key for the specified repository if it does not already exist, otherwise it updates the existing key

func DeleteHook

func DeleteHook(client *github.Client, owner, name, url string) error

func DeleteKey

func DeleteKey(client *github.Client, owner, name, title string) error

DeleteKey is a helper function that deletes a deploy key for the specified repository.

func GetAllRepos

func GetAllRepos(client *github.Client) ([]github.Repository, error)

GetAllRepos is a helper function that returns an aggregated list of all user and organization repositories.

func GetFile

func GetFile(client *github.Client, owner, name, path, ref string) ([]byte, error)

GetFile is a heper function that retrieves a file from GitHub and returns its contents in byte array format.

func GetHook

func GetHook(client *github.Client, owner, name, url string) (*github.Hook, error)

GetHook is a heper function that retrieves a hook by hostname. To do this, it will retrieve a list of all hooks and iterate through the list.

func GetKey

func GetKey(client *github.Client, owner, name, title string) (*github.Key, error)

GetKey is a heper function that retrieves a public Key by title. To do this, it will retrieve a list of all keys and iterate through the list.

func GetKeyTitle

func GetKeyTitle(rawurl string) (string, error)

GetKeyTitle is a helper function that generates a title for the RSA public key based on the username and domain name.

func GetOrgRepos

func GetOrgRepos(client *github.Client, org string) ([]github.Repository, error)

GetOrgRepos is a helper function that returns a list of all org repositories. Paginated results are aggregated into a single list.

func GetOrgs

func GetOrgs(client *github.Client) ([]github.Organization, error)

GetOrgs is a helper function that returns a list of all orgs that a user belongs to.

func GetPayload

func GetPayload(req *http.Request) []byte

GetPayload is a helper function that will parse the JSON payload. It will first check for a `payload` parameter in a POST, but can fallback to a raw JSON body as well.

func GetRandom

func GetRandom() string

GetRandom is a helper function that generates a 32-bit random key, base32 encoded as a string value.

func GetRepo

func GetRepo(client *github.Client, owner, repo string) (*github.Repository, error)

GetRepo is a helper function that returns a named repo

func GetUserEmail

func GetUserEmail(client *github.Client) (*github.User, error)

GetUserEmail is a heper function that retrieves the currently authenticated user from GitHub + Email address.

func GetUserRepos

func GetUserRepos(client *github.Client) ([]github.Repository, error)

GetUserRepos is a helper function that returns a list of all user repositories. Paginated results are aggregated into a single list.

func NewClient

func NewClient(uri, token string, skipVerify bool) *github.Client

NewClient is a helper function that returns a new GitHub client using the provided OAuth token.

func UserBelongsToOrg

func UserBelongsToOrg(client *github.Client, permittedOrgs []string) (bool, error)

UserBelongsToOrg returns true if the currently authenticated user is a member of any of the organizations provided.

Types

type Github

type Github struct {
	URL         string
	API         string
	Client      string
	Secret      string
	Scope       string
	MergeRef    string
	Orgs        []string
	Open        bool
	PrivateMode bool
	SkipVerify  bool
	GitSSH      bool
}

func Load

func Load(config string) *Github

func (*Github) Activate

func (g *Github) Activate(u *model.User, r *model.Repo, k *model.Key, link string) error

Activate activates a repository by creating the post-commit hook and adding the SSH deploy key, if applicable.

func (*Github) Auth

func (g *Github) Auth(token, secret string) (string, error)

Auth authenticates the session and returns the remote user login for the given token and secret

func (*Github) Deactivate

func (g *Github) Deactivate(u *model.User, r *model.Repo, link string) error

Deactivate removes a repository by removing all the post-commit hooks which are equal to link and removing the SSH deploy key.

func (*Github) File added in v0.4.2

func (g *Github) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error)

File fetches a file from the remote repository and returns in string format.

func (*Github) Hook

func (g *Github) Hook(r *http.Request) (*model.Repo, *model.Build, error)

Hook parses the post-commit hook from the Request body and returns the required data in a standard format.

func (*Github) Login

func (g *Github) Login(res http.ResponseWriter, req *http.Request) (*model.User, bool, error)

Login authenticates the session and returns the remote user details.

func (*Github) Netrc

func (g *Github) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error)

Netrc returns a .netrc file that can be used to clone private repositories from a remote system.

func (*Github) Perm

func (g *Github) Perm(u *model.User, owner, name string) (*model.Perm, error)

Perm fetches the named repository permissions from the remote system for the specified user.

func (*Github) Repo

func (g *Github) Repo(u *model.User, owner, name string) (*model.Repo, error)

Repo fetches the named repository from the remote system.

func (*Github) Repos

func (g *Github) Repos(u *model.User) ([]*model.RepoLite, error)

Repos fetches a list of repos from the remote system.

func (*Github) Status

func (g *Github) Status(u *model.User, r *model.Repo, b *model.Build, link string) error

Status sends the commit status to the remote system. An example would be the GitHub pull request status.

func (*Github) String added in v0.4.2

func (g *Github) String() string

Jump to

Keyboard shortcuts

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