github

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2014 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Any git push to a Repository.
	HookPush = "push"

	// Any time an Issue is opened or closed.
	HookIssues = "issues"

	// Any time an Issue is commented on.
	HookIssueComment = "issue_comment"

	// Any time a Commit is commented on.
	HookCommitComment = "commit_comment"

	// Any time a Pull Request is opened, closed, or synchronized.
	HookPullRequest = "pull_request"

	// Any time a Commit is commented on while inside a Pull Request review.
	HookRequestReivewComment = "pull_request_review_comment"

	// Any time a Wiki page is updated.
	HookGollum = "gollum"

	// Any time a User watches the Repository.
	HookWatch = "watch"

	// Any time a Download is added to the Repository.
	HookDownload = "download"

	// Any time a Repository is forked.
	HookForm = "fork"

	// Any time a patch is applied to the Repository from the Fork Queue.
	HookForkApply = "fork_apply"

	// Any time a User is added as a collaborator to a non-Organization Repository.
	HookMember = "member"

	// Any time a Repository changes from private to public.
	HookPublic = "public"

	// Any time a team is added or modified on a Repository.
	HookTeamAdd = "team_add"

	// Any time a Repository has a status update from the API
	HookStatus = "status"
)

Different types of Hooks. See http://developer.github.com/v3/repos/hooks/

Variables

View Source
var (
	// Returned if the specified resource does not exist.
	ErrNotFound = errors.New("Not Found")

	// Returned if the caller attempts to make a call or modify a resource
	// for which the caller is not authorized.
	//
	// The request was a valid request, the caller's authentication credentials
	// succeeded but those credentials do not grant the caller permission to
	// access the resource.
	ErrForbidden = errors.New("Forbidden")

	// Returned if the call requires authentication and either the credentials
	// provided failed or no credentials were provided.
	ErrNotAuthorized = errors.New("Unauthorized")

	// Returned if the caller submits a badly formed request. For example,
	// the caller can receive this return if you forget a required parameter.
	ErrBadRequest = errors.New("Bad Request")
)
View Source
var DefaultClient = http.DefaultClient

DefaultClient uses DefaultTransport, and is used internall to execute all http.Requests. This may be overriden for unit testing purposes.

IMPORTANT: this is not thread safe and should not be touched with the exception overriding for mock unit testing.

View Source
var ErrInvalidPostReceiveHook = errors.New("Invalid Post Receive Hook")
View Source
var Guest = New("")

Guest Client that can be used to access public APIs that do not require authentication.

Functions

func IsValidSender

func IsValidSender(ip string) bool

Check's to see if the Post-Receive Build Hook is coming from a valid sender (IP Address)

Types

type Author

type Author struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type Base

type Base struct {
	Label string      `json:"label"`
	Ref   string      `json:"ref"`
	Sha   string      `json:"sha"`
	User  *User       `json:"user"`
	Repo  *CommitRepo `json:"repo"`
}

type Client

type Client struct {
	ApiUrl string
	Token  string

	Repos    *RepoResource
	Users    *UserResource
	Orgs     *OrgResource
	Emails   *EmailResource
	Keys     *KeyResource
	Hooks    *HookResource
	Contents *ContentResource
	RepoKeys *RepoKeyResource
}

func New

func New(token string) *Client

New creates an instance of the Github Client

type Commit

type Commit struct {
	Id        string   `json:"id"`
	Url       string   `json:"url"`
	Message   string   `json:"message"`
	Timestamp string   `json:timestamp`
	Author    *Author  `json:"author"`
	Added     []string `json:"added"`
}

type CommitRepo

type CommitRepo struct {
	Url   string `json:"url"`
	Name  string `json:"name"`
	Desc  string `json:"description"`
	Owner *Owner `json:"owner"`
}

type CommitStatus

type CommitStatus struct {
	State       string `json:"state"` // pending, success, error, failure
	TargetUrl   string `json:"target_url"`
	Description string `json:"description"`
}

type Content

type Content struct {
	Type     string `json:"type"`
	Name     string `json:"name"`
	Path     string `json:"path"`
	Encoding string `json:"encoding"`
	Content  string `json:"content"`
	Size     int64  `json:"size"`
	Sha      string `json:"sha"`
}

func (*Content) DecodeContent

func (c *Content) DecodeContent() ([]byte, error)

type ContentResource

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

These API methods let you retrieve the contents of files within a repository as Base64 encoded content.

func (*ContentResource) Find

func (r *ContentResource) Find(owner, repo, path string) (*Content, error)

This method returns the contents of a file or directory in a repository.

func (*ContentResource) FindRef

func (r *ContentResource) FindRef(owner, repo, path, ref string) (*Content, error)

This method returns the contents of a file or directory in a repository.

func (*ContentResource) ReadMe

func (r *ContentResource) ReadMe(owner, repo string) (*Content, error)

This method returns the preferred README for a repository.

type Email

type Email struct {
	// Indicates the user confirmed the email address (true).
	Verified bool `json:"verified"`

	// The email address.
	Email string `json:"email"`

	// Indicates the email is the main contact email address for the account.
	Primary bool `json:"primary"`
}

type EmailResource

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

An account can have one or more email addresses associated with it. Use this end point to list, change, or create an email address.

func (*EmailResource) Create

func (r *EmailResource) Create(address string) error

Adds additional email addresses to an account.

func (*EmailResource) Delete

func (r *EmailResource) Delete(address string) error

Deletes an email addresses from an account.

func (*EmailResource) Find

func (r *EmailResource) Find(address string) (*Email, error)

Gets an individual email address associated with an account.

func (*EmailResource) FindPrimary

func (r *EmailResource) FindPrimary() (*Email, error)

Gets an individual's primary email address.

func (*EmailResource) List

func (r *EmailResource) List() ([]*Email, error)

Gets the email addresses associated with the account.

type Head struct {
	Label string      `json:"label"`
	Ref   string      `json:"ref"`
	Sha   string      `json:"sha"`
	User  *User       `json:"user"`
	Repo  *CommitRepo `json:"repo"`
}

type Hook

type Hook struct {
	Id     int         `json:"id"`
	Name   string      `json:"name"`
	Active bool        `json:"active"`
	Events []string    `json:"events"`
	Config *HookConfig `json:"config"`
}

type HookConfig

type HookConfig struct {
	Url         string `json:"url"`
	ContentType string `json:"content_type"`
}

type HookResource

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

func (*HookResource) Create

func (r *HookResource) Create(owner, repo, link string) (*Hook, error)

func (*HookResource) CreateUpdate

func (r *HookResource) CreateUpdate(owner, repo, link string) (*Hook, error)

func (*HookResource) Delete

func (r *HookResource) Delete(owner, repo string, id int) error

func (*HookResource) DeleteUrl

func (r *HookResource) DeleteUrl(owner, repo, link string) error

func (*HookResource) Find

func (r *HookResource) Find(owner, repo string, id int) (*Hook, error)

func (*HookResource) FindUrl

func (r *HookResource) FindUrl(owner, repo, link string) (*Hook, error)

func (*HookResource) List

func (r *HookResource) List(owner, repo string) ([]*Hook, error)

func (*HookResource) Update

func (r *HookResource) Update(owner, repo string, hook *Hook) (*Hook, error)

type Key

type Key struct {
	Id    int    `json:"id"`
	Key   string `json:"key"`
	Url   string `json:"url"`
	Title string `json:"title"`
}

type KeyResource

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

func (*KeyResource) Create

func (r *KeyResource) Create(key, title string) (*Key, error)

Creates a key on the specified account. You must supply a valid key that is unique across the Github service.

func (*KeyResource) CreateUpdate

func (r *KeyResource) CreateUpdate(key, title string) (*Key, error)

Creates a key on the specified account, assuming it does not already exist in the system

func (*KeyResource) Delete

func (r *KeyResource) Delete(id int) error

Deletes the key specified by the id value.

func (*KeyResource) DeleteName

func (r *KeyResource) DeleteName(title string) error

Deletes the named key.

func (*KeyResource) Find

func (r *KeyResource) Find(id int) (*Key, error)

Gets the key associated with the specified id.

func (*KeyResource) FindName

func (r *KeyResource) FindName(title string) (*Key, error)

Gets the key associated with specified title.

func (*KeyResource) List

func (r *KeyResource) List() ([]*Key, error)

Gets a list of the keys associated with an account.

func (*KeyResource) Update

func (r *KeyResource) Update(key, title string, id int) (*Key, error)

Updates a key on the specified account.

type Org

type Org struct {
	Login  string `json:"login"`
	Url    string `json:"url"`
	Avatar string `json:"avatar_url"`
}

type OrgResource

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

func (*OrgResource) List

func (r *OrgResource) List() ([]*Org, error)

type Owner

type Owner struct {
	Type  string `json:"type"`
	Login string `json:"login"`
	Name  string `json:"name"`
}

Owner represents the owner of a Github Repository.

type Permissions

type Permissions struct {
	Push  bool `json:"push"`
	Pull  bool `json:"pull"`
	Admin bool `json:"admin"`
}

Permissions

type PostReceiveHook

type PostReceiveHook struct {
	Before  string      `json:"before"`
	After   string      `json:"after"`
	Ref     string      `json:"ref"`
	Repo    *CommitRepo `json:"repository"`
	Commits []*Commit   `json:"commits"`
	Head    *Commit     `json:"head_commit"`
	Deleted bool        `json:"deleted"`
}

func ParseHook

func ParseHook(raw []byte) (*PostReceiveHook, error)

func (*PostReceiveHook) Branch

func (h *PostReceiveHook) Branch() string

func (*PostReceiveHook) IsDeleted

func (h *PostReceiveHook) IsDeleted() bool

func (*PostReceiveHook) IsGithubPages

func (h *PostReceiveHook) IsGithubPages() bool

func (*PostReceiveHook) IsHead

func (h *PostReceiveHook) IsHead() bool

func (*PostReceiveHook) IsTag

func (h *PostReceiveHook) IsTag() bool

type PullRequest

type PullRequest struct {
	Id        int    `json:"int"`
	Number    int    `json:"int"`
	Url       string `json:"url"`
	State     string `json:"state"` // open, closed, etc
	Title     string `json:"title"`
	Merged    bool   `json:"merged"`
	Commits   int    `json:"commits"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Changed   int    `json:"changed_files"`

	Base *Base `json:"base"`
	Head *Head `json:"head"`
	User *User `json:"user"`
}

type PullRequestHook

type PullRequestHook struct {
	Action      string       `json:"action"`
	Number      int          `json:"number"`
	Sender      *User        `json:"sender"`
	Repo        *CommitRepo  `json:"repository"`
	PullRequest *PullRequest `json:"pull_request"`
}

func ParsePullRequestHook

func ParsePullRequestHook(raw []byte) (*PullRequestHook, error)

func (*PullRequestHook) IsOpened

func (h *PullRequestHook) IsOpened() bool

type Repo

type Repo struct {
	ID       int64  `json:"id"`
	Name     string `json:"name"`
	FullName string `json:"full_name"`
	Private  bool   `json:"private"`
	Fork     bool   `json:"fork"`
	SshUrl   string `json:"ssh_url"`
	GitUrl   string `json:"git_url"`
	CloneUrl string `json:"clone_url"`
	HtmlUrl  string `json:"html_url"`

	Owner       *Owner       `json:"owner"`
	Permissions *Permissions `json:"permissions"`
	Source      *Source      `json:"source"`
}

Repo represents a Github-hosted Git Repository.

type RepoKeyResource

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

func (*RepoKeyResource) Create

func (r *RepoKeyResource) Create(owner, repo, key, title string) (*Key, error)

Creates a key on the specified repo. You must supply a valid key that is unique across the Github service.

func (*RepoKeyResource) CreateUpdate

func (r *RepoKeyResource) CreateUpdate(owner, repo, key, title string) (*Key, error)

Creates a key for the specified repo, assuming it does not already exist in the system

func (*RepoKeyResource) Delete

func (r *RepoKeyResource) Delete(owner, repo string, id int) error

Deletes the key specified by the id value.

func (*RepoKeyResource) DeleteName

func (r *RepoKeyResource) DeleteName(owner, repo, label string) error

func (*RepoKeyResource) Find

func (r *RepoKeyResource) Find(owner, repo string, id int) (*Key, error)

Gets the key associated with the specified id.

func (*RepoKeyResource) FindName

func (r *RepoKeyResource) FindName(owner, repo, title string) (*Key, error)

Gets the key associated with specified title.

func (*RepoKeyResource) List

func (r *RepoKeyResource) List(owner, repo string) ([]*Key, error)

Gets a list of the keys associated with a repo.

func (*RepoKeyResource) Update

func (r *RepoKeyResource) Update(owner, repo, key, title string, id int) (*Key, error)

Updates a key on the specified repo.

type RepoResource

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

func (*RepoResource) CreateStatus

func (r *RepoResource) CreateStatus(owner, repo, state, link, comment, sha string) error

func (*RepoResource) Find

func (r *RepoResource) Find(owner, repo string) (*Repo, error)

func (*RepoResource) FindRaw

func (r *RepoResource) FindRaw(owner, repo string) ([]byte, error)

func (*RepoResource) List

func (r *RepoResource) List() ([]*Repo, error)

func (*RepoResource) ListAll

func (r *RepoResource) ListAll() ([]*Repo, error)

func (*RepoResource) ListOrg

func (r *RepoResource) ListOrg(orgname string) ([]*Repo, error)

func (*RepoResource) ListUser

func (r *RepoResource) ListUser(username string) ([]*Repo, error)

type Source

type Source struct {
	Owner *Owner `json:"owner"`
}

type User

type User struct {
	ID         int64  `json:"id"`
	Login      string `json:"login"`
	Type       string `json:"type"`
	Name       string `json:"name"`
	Email      string `json:"email"`
	Company    string `json:"company"`
	Location   string `json:"location"`
	Blog       string `json:"blog"`
	Avatar     string `json:"avatar_url"`
	GravatarId string `json:"gravatar_id"`
	Url        string `json:"html_url"`
}

type UserResource

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

func (*UserResource) Current

func (r *UserResource) Current() (*User, error)

func (*UserResource) Find

func (r *UserResource) Find(username string) (*User, error)

Jump to

Keyboard shortcuts

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