Documentation ¶
Index ¶
- Variables
- func NewTestClient(fn RoundTripFunc) *http.Client
- func RecursivePrint(t Node) (string, error)
- func TreeServer(tree *Tree, repo *Repository) (map[string]func(*http.Request) (*http.Response, error), error)
- func WriteTreeToDirectory(top Node, basePath string) error
- type API
- func (a *API) Authenticate(oauth io.Reader) error
- func (a *API) BlobURL(owner, repo, fileSha string) string
- func (a *API) GetBlob(owner, repo, sha string) ([]byte, error)
- func (a *API) GetTree(owner, repo, sha string) ([]byte, error)
- func (a *API) GetURL(url string) ([]byte, error)
- func (a *API) NewGistURL() string
- func (a *API) PostGists(body []byte) ([]byte, error)
- func (a *API) PostStatus(owner, repo, commitSha string, body []byte) error
- func (a *API) PublishedGistURL(id, user string) string
- func (a *API) StatusURL(owner, repo, sha string) string
- func (a *API) TreeURL(owner, repo, treeSha string) string
- func (a *API) UpdateGist(body []byte, ID string) ([]byte, error)
- func (a *API) UpdateGistURL(ID string) string
- type Blob
- type Cache
- type ChildRef
- type Client
- type Comment
- type Commit
- type CommitState
- type Event
- type File
- type GhObject
- type Gist
- type GistWriter
- type GithubClientError
- type Node
- type Push
- type Reference
- type Repository
- type RoundTripFunc
- type Status
- type Tree
- type TreeMarshal
Constants ¶
This section is empty.
Variables ¶
var ( //ErrInvalidResp occurs when server reply does not contain all required fields ErrInvalidResp error = errors.New("did not receive required fields") )
Functions ¶
func NewTestClient ¶
func NewTestClient(fn RoundTripFunc) *http.Client
NewTestClient returns *http.Client with Transport replaced to avoid making real calls
func RecursivePrint ¶
RecursivePrint helper function for printing out nodes in tree order
func TreeServer ¶
func TreeServer(tree *Tree, repo *Repository) (map[string]func(*http.Request) (*http.Response, error), error)
TreeServer generates mock server tree responses based on input tree structure. Use this when function being tested makes API calls to retrieve a github tree. Use in conjunction with NewTestClient()
func WriteTreeToDirectory ¶
WriteTreeToDirectory write tree to specified directory path
Types ¶
type API ¶
API generates github URLS
func (*API) Authenticate ¶
Authenticate set and test authentication with Oauth token
func (*API) NewGistURL ¶
func (*API) PostStatus ¶
PostStatus sends post request to status
func (*API) PublishedGistURL ¶
func (*API) UpdateGist ¶
UpdateGist updates gist with ID
func (*API) UpdateGistURL ¶
type Blob ¶
type Blob struct { Sha string `json:"sha"` Encoding string `json:"encoding"` Content string `json:"content"` Path string `json:"Path"` // contains filtered or unexported fields }
Blob encoded contents of a file
func NewBlobFromJSON ¶
NewBlobFromJSON blob factory
func (*Blob) GetChildren ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache one way cache for tracking github trees
func (*Cache) WriteCommits ¶
type ChildRef ¶
type ChildRef struct { Path string `json:"path"` Type string `json:"type"` Sha string `json:"sha"` }
Interim object for holding tree data from api calls in expected format
type Client ¶
type Client struct { EventChan chan Event User string Api API Cache Cache Repositories map[string]*Repository // contains filtered or unexported fields }
Client github client object
func (*Client) GetTree ¶
func (c *Client) GetTree(sha string, repo Repository) (*Tree, error)
GetTree checks cache for tree, else pulls tree from github
func (*Client) UpdateCommitStatus ¶
func (c *Client) UpdateCommitStatus(repo Repository, commit Commit) error
UpdateCommitStatus update status of commit in repository
type Comment ¶
type Comment struct { Ref Reference Repo Repository Action string RefName string Body string CommitSHA string User string }
Comment implements Event interface. Represents a github comment webhook
type Commit ¶
type Commit struct { Sha string `json:"sha"` Message string `json:"message"` URL string `json:"url"` ID string `json:"id"` Status Status Author struct { Name string `json:"name"` Email string `json:"email"` Username string `json:"username"` } // contains filtered or unexported fields }
Commit resource tracking a github commit
func NewCommitFromJSON ¶
NewCommitFromJSON build commit from json byte slice
func (*Commit) SetContext ¶
SetContext set context of commit status
type CommitState ¶
type CommitState int
const ( ERROR CommitState = iota FAILURE PENDING SUCCESS NONE )
func (CommitState) String ¶
func (cs CommitState) String() string
type Event ¶
Event definitions from github
func EventFactory ¶
EventFactory create github event based on string name
type File ¶
type File struct {
Content string `json:"content"`
}
File represents file object in github gist
type GhObject ¶
type GhObject interface {
String() string
}
GhObject generic type representing all github objects
type Gist ¶
type Gist struct { Description string `json:"description"` Public bool `json:"public"` Files map[string]*File `json:"files"` }
Gist github gist object. Contains collection of files
type GistWriter ¶
type GistWriter struct { API *API // contains filtered or unexported fields }
GistWriter implements io.Writer type for writing to a single file in a github gists. Gists last the lifetime of this object. That is, first calls to write will create a new gist, and subsequent calls will update the existing gist until this object is destroyed.
This should be used in conjuction with a buffered writer to avoid frequent API calls
func NewGistWriter ¶
func NewGistWriter(api *API, g Gist, filename string) (*GistWriter, error)
NewGistWriter GistWriter constructor
func (*GistWriter) GetServerGistID ¶
func (gw *GistWriter) GetServerGistID() string
GetServerGistID returns ID of gist on github server
type GithubClientError ¶
type GithubClientError struct {
// contains filtered or unexported fields
}
GithubClientError all returned errors from this package are of this type
func (*GithubClientError) Error ¶
func (e *GithubClientError) Error() string
type Node ¶
type Node interface { GetParent() Node GetChildren() []Node GetPath() string SetChild(Node) // contains filtered or unexported methods }
Node represents node in file tree
type Push ¶
type Push struct { Ref Reference RefName string Repo Repository User string }
Push implements github Event interface
type Reference ¶
type Reference struct {
// contains filtered or unexported fields
}
Reference analogous to a git reference. Points to a commit list
type Repository ¶
type Repository struct { Name string `json:"name"` Fork bool `json:"fork"` Owner struct { Login string `json:"login"` } // contains filtered or unexported fields }
Repository object for tracking remote repository
func NewRepositoryFromJSON ¶
func NewRepositoryFromJSON(repoJSON []byte) (*Repository, error)
NewRepositoryFromJSON create new repository from json byte slice
func NewRepositoryFromMap ¶
func NewRepositoryFromMap(m map[string]interface{}) (*Repository, error)
NewRepositoryFromMap create new repository from map
func (*Repository) GetReference ¶
func (r *Repository) GetReference(refName string) *Reference
GetReference retrieve git reference by ID
func (*Repository) String ¶
func (r *Repository) String() string
type RoundTripFunc ¶
RoundTripFunc mock http Transport
type Status ¶
type Status struct { State string `json:"state"` TargetURL string `json:"target_url"` Description string `json:"description"` Context string `json:"context"` }
Status github status object
type Tree ¶
type Tree struct { Sha string `json:"sha"` Path string `json:"path"` // contains filtered or unexported fields }
Tree github tree type
func NewTreeFromJSON ¶
NewTreeFromJSON tree factory