gothub

package module
v0.0.0-...-f0c8240 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2014 License: MIT Imports: 12 Imported by: 0

README

GotHub

What is it?

GotHub is a library for interfacing with GitHub, for the Go programming language.

How do I pronounce the name?

You can pronounce it like "got hub", "goth hub" for those darker times, or really, however the heck you feel like pronouncing it.

"go thub" is also acceptable.

Why are you working on this?

Well, simply because I wanted a client-side library with which to utilize GitHub's APIs, in a similar fashion to the PyGithub library for Python.

How do I get it?

A simple go get github.com/nesv/gothub should be sufficient.

I can haz docs plz?

Documentation is automatically generated, and can be found here: http://godoc.org/github.com/nesv/gothub

kthxbai.

Can I use this within my company's proprietary software?

You betcha. Check out the LICENSE.md file — the code and documentation for this project is kept under the MIT license. In other words, feel free to copy it, sell it, do whatever you want, just make sure to include the provided LICENSE.md file if you incorporate it into your stuff (or your company's stuff).

Look, I need to run some tests on this to verify it even works...

And you can! No Go project can really be "complete" without tests.

To run the tests, you need to set two environment variables: GITHUB_USERNAME and GITHUB_PASSWORD. Here is how you can run the tests without having to save these trinkets of information anywhere:

$ GITHUB_USERNAME=<login> GITHUB_PASSWORD=<password> go test -v

Afterwards, be sure to delete your shell's history file, so that your credentials aren't laying around anywhere.

I wanna help

Help is always appreciated!

If you have a bug or a feature request, please create an issue here in GitHub.

All of the development tasks are planned out in Trello. If you would like to keep track of what is being worked on, check out the GotHub Development board. The tasks in Trello are broken down much further than they are in GitHub.

Once a feature, or bug, is completed in Trello, we will update the GitHub issue accordingly.

…I actually wanna write code

Even better! Sign up for an account on Trello and assign yourself to a card so the work can be appropriately coordinated, then fork the repository. After your code is done, tests have passed and all that good stuff, submit a pull request and your code will be merged in.

Documentation

Index

Constants

View Source
const (
	GitHubUrl       string = "https://api.github.com"
	DefaultPageSize int    = 30
	AcceptHeader    string = "application/vnd.github.beta+json"
)

The HTTP host that we will hit to use the GitHub API.

Variables

View Source
var (
	ErrRateLimitReached = errors.New("Rate limit reached")
	ErrNoJSON           = errors.New("GitHub did not return a JSON response")
)
View Source
var (
	ErrSearchInvalidParam = errors.New("Invalid parameter for search")
	ErrSearchOmitParam    = errors.New("Omit mandatory paramter for search")
)

Functions

This section is empty.

Types

type EmailSearchParam

type EmailSearchParam struct {
	Email string
	// contains filtered or unexported fields
}

Types which represents result for search email http://developer.github.com/v3/search/#email-users

type EmailSearchResult

type EmailSearchResult struct {
	PublicRepoCount int       `json:"public_repo_count"`
	PublicGistCount int       `json:"public_gist_count"`
	FollowersCount  int       `json:"followers_count"`
	FollowingCount  int       `json:"following_count"`
	Created         time.Time `json:"created"`
	CreatedAt       time.Time `json:"created_at"`
	Name            string    `json:"name"`
	Company         string    `json:"company"`
	BLog            string    `json:"blog"`
	Location        string    `json:"location"`
	Email           string    `json:"email"`
	Id              int       `json:"id"`
	Login           string    `json:"login"`
	Type            string    `json:"type"`
	GravatarId      string    `json:"gravatar_id"`
}

type Follower

type Follower struct {
	Login             string `json:"login"`
	Id                int    `json:"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"`
}

A minimized form of the User struct, for holding information about a follower.

type GitHub

type GitHub struct {
	Authorization      string
	RateLimit          int
	RateLimitRemaining int
	// contains filtered or unexported fields
}

The GitHub struct represents an active session to the GitHub API.

func BasicLogin

func BasicLogin(username, password string) (*GitHub, error)

Log in to GitHub using basic, username/password authentication.

func Guest

func Guest() (*GitHub, error)

Use API without authentication

func (*GitHub) AddEmails

func (g *GitHub) AddEmails(emails []string) (err error)

Associate a list of emails with the currently-authenticated user's account.

func (GitHub) AddPublicKey

func (g GitHub) AddPublicKey(title, key string) (id int, err error)

Add a public key to your account.

When the creation of your new key is successful, this function will return the new ID of the key, which will be retrievable at:

https://api.github.com/user/keys/:id

func (*GitHub) DeleteEmails

func (g *GitHub) DeleteEmails(emails []string) (err error)

Disassociate a list of emails from the currently-authenticated user's account.

func (*GitHub) Do

func (g *GitHub) Do(v interface{}, method string, uriParts ...string) (err error)

Calls the specified GitHub endpoint, with the provided HTTP method, and unmarshals the JSON response (if there is one) into the provided interface{} v.

You can use this function to interact with a majority of the GitHub v3 endpoints.

func (*GitHub) Emails

func (g *GitHub) Emails() (emails []string, err error)

Returns a list of the email accounts associated with the currently- authenticated user.

func (GitHub) Follow

func (g GitHub) Follow(user string) (err error)

Follow a user.

func (*GitHub) GetCurrentUser

func (g *GitHub) GetCurrentUser() (*User, error)

Returns the currently-authenticated user, as a pointer to a User struct.

func (*GitHub) GetOrganization

func (g *GitHub) GetOrganization(name string) (org *Organization, err error)

Returns a complete Organization struct.

func (GitHub) GetPublicKey

func (g GitHub) GetPublicKey(id int) (key PublicKey, err error)

Fetch a singular public SSH key.

func (*GitHub) GetUser

func (g *GitHub) GetUser(login string) (*User, error)

Returns the details of a single user, as specified by their "login".

The term "login" is synonymous with "username":

https://github.com/<login>

func (GitHub) IsFollowing

func (g GitHub) IsFollowing(anotherUser string) (following bool, err error)

Check to see whether or not the current user `u` is following another user.

func (*GitHub) Organizations

func (g *GitHub) Organizations() (orgs []Organization, err error)

List all of the organizations the currently-authenticated user is a member of.

Please be aware that this method does not return a complete Organization struct; for that, please refer to the (*GitHub).GetOrganization() method.

func (GitHub) PublicKeys

func (g GitHub) PublicKeys() (keys []PublicKey, err error)

Fetch a listing of the currently-authenticated user's public SSH keys.

func (GitHub) RemovePublicKey

func (g GitHub) RemovePublicKey(id int) (err error)

Removes a public key from your account.

func (GitHub) Repositories

func (g GitHub) Repositories(options ...int) (repositories []Repository, err error)

Get the currently-authenticated user's repositories.

func (*GitHub) SearchEmail

func (g *GitHub) SearchEmail(p *EmailSearchParam) (*EmailSearchResult, error)

Find user by email address. This API call is added for compatibility reasons only. There’s no guarantee that full email searches will always be available.

func (*GitHub) SearchIssues

func (g *GitHub) SearchIssues(p *IssuesSearchParam) ([]*IssuesSearchResult, error)

Find issues by state and keyword.

func (*GitHub) SearchRepositories

func (g *GitHub) SearchRepositories(p *RepositoriesSearchParam) ([]*RepositoriesSearchResult, error)

Find repositories by keyword. This method returns up to 100 results per page and pages can be fetched using the start_page parameter.

func (*GitHub) SearchUsers

func (g *GitHub) SearchUsers(p *UsersSearchParam) ([]*UsersSearchResult, error)

Find users by state and keyword.

func (GitHub) Unfollow

func (g GitHub) Unfollow(user string) (err error)

Unfollow a user.

type IssuesSearchParam

type IssuesSearchParam struct {
	Owner      string
	Repository string
	State      string // open or close
	Keyword    string
	// contains filtered or unexported fields
}

Types which represents params and result for search issues http://developer.github.com/v3/search/#search-issues

type IssuesSearchResult

type IssuesSearchResult struct {
	GravatarId string    `json:"gravatar_id"`
	Position   int       `json:"position"`
	Number     int       `json:"number"`
	Votes      int       `json:"votes"`
	CreatedAt  time.Time `json:"created_at"`
	Comments   int       `json:"comments"`
	Body       string    `json:"body"`
	Title      string    `json:"title"`
	UpdatedAt  time.Time `json:"updated_at"`
	HtmlUrl    string    `json:"html_url"`
	User       string    `json:"user"`
	Labels     []string  `json:"labels"`
	State      string    `json:"state"`
}

type Organization

type Organization struct {
	AvatarUrl         string           `json:"avatar_url"`
	BillingEmail      string           `json:"billing_email"`
	Blog              string           `json:"blog"`
	Collaborators     int              `json:"collaborators"`
	Company           string           `json:"company"`
	CreatedAt         time.Time        `json:"created_at"`
	DiskUsage         int              `json:"disk_usage"`
	Email             string           `json:"email"`
	EventsUrl         string           `json:"events_url"`
	Followers         int              `json:"followers"`
	Following         int              `json:"following"`
	HtmlUrl           string           `json:"html_url"`
	Id                int              `json:"id"`
	Location          string           `json:"location"`
	Login             string           `json:"login"`
	MembersUrl        string           `json:"members_url"`
	Name              string           `json:"name"`
	OwnedPrivateRepos int              `json:"owned_private_repos"`
	Plan              OrganizationPlan `json:"plan"`
	PrivateGists      int              `json:"private_gists"`
	PublicGists       int              `json:"public_gists"`
	PublicMembersUrl  string           `json:"public_members_url"`
	PublicRepos       int              `json:"public_repos"`
	ReposUrl          string           `json:"repos_url"`
	TotalPrivateRepos int              `json:"total_private_repos"`
	Type              string           `json:"type"`
	UpdatedAt         time.Time        `json:"updated_at"`
	Url               string           `json:"url"`
	// contains filtered or unexported fields
}

type OrganizationPlan

type OrganizationPlan struct {
	Name         string `json:"name"`
	PrivateRepos int    `json:"private_repos"`
	Space        int    `json:"space"`
}

type PublicKey

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

Holds information about user's public SSH keys that they have provided to GitHub.

type RepositoriesSearchParam

type RepositoriesSearchParam struct {
	Keyword   string
	Language  string // optional:
	StartPage uint   // optional:
	Sort      string // optional: stars, forks or update
	Order     string // optional: asc or desc
	// contains filtered or unexported fields
}

Types which represents params and result for search repositories http://developer.github.com/v3/search/#search-repositories

type RepositoriesSearchResult

type RepositoriesSearchResult struct {
	Type         string    `json:"type"`
	Created      time.Time `json:"created"`
	Watchers     int       `json:"watchers"`
	HasDownloads bool      `json:"has_downloads"`
	Username     string    `json:"username"`
	Homepage     string    `json:"homepage"`
	Url          string    `json:"url"`
	Fork         bool      `json:"fork"`
	HasIssues    bool      `json:"has_issues"`
	HasWiki      bool      `json:"has_wiki"`
	Forks        int       `json:"forks"`
	Size         int       `json:"size"`
	Private      bool      `json:"private"`
	Followers    int       `json:"followers"`
	Name         string    `json:"name"`
	Owner        string    `json:"owner"`
	OpenIssues   int       `json:"open_issues"`
	PushedAt     time.Time `json:"pushed_at"`
	Score        float32   `json:"score"`
	Pushed       time.Time `json:"pushed"`
	Description  string    `json:"description"`
	Language     string    `json:"language"`
	CreatedAt    time.Time `json:"created_at"`
}

type Repository

type Repository struct {
	ArchiveUrl       string                `json:"archive_url"`
	AssigneesUrl     string                `json:"assignees_url"`
	BlobsUrl         string                `json:"blobs_url"`
	CloneUrl         string                `json:"clone_url"`
	CollaboratorsUrl string                `json:"collaborators_url"`
	CommentsUrl      string                `json:"comments_url"`
	CommitsUrl       string                `json:"comments_url"`
	CompareUrl       string                `json:"compare_url"`
	ContentsUrl      string                `json:"contentsUrl"`
	ContributorsUrl  string                `json:"contributors_url"`
	CreatedAt        time.Time             `json:"created_at"`
	DefaultBranch    string                `json:"default_branch"`
	Description      string                `json:"description"`
	DownloadsUrl     string                `json:"downloads_url"`
	EventsUrl        string                `json:"events_url"`
	Fork             bool                  `json:"fork"`
	Forks            int                   `json:"forks"`
	ForksCount       int                   `json:"forks_count"`
	ForksUrl         string                `json:"forks_url"`
	FullName         string                `json:"full_name"`
	GitCommitsUrl    string                `json:"git_commits_url"`
	GitRefsUrl       string                `json:"git_refs_url"`
	GitTagsUrl       string                `json:"git_tags_url"`
	GitUrl           string                `json:"git_url"`
	HasDownloads     bool                  `json:"has_downloads"`
	HasIssues        bool                  `json:"has_issues"`
	HasWiki          bool                  `json:"has_wiki"`
	Homepage         string                `json:"homepage"`
	HooksUrl         string                `json:"hooks_url"`
	HtmlUrl          string                `json:"html_url"`
	Id               int                   `json:"id"`
	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"`
	Language         string                `json:"language"`
	LanguagesUrl     string                `json:"languages_url"`
	MasterBranch     string                `json:"master_branch"`
	MergesUrl        string                `json:"merges_url"`
	MilestonesUrl    string                `json:"milestones_url"`
	MirrorUrl        string                `json:"mirror_url"`
	Name             string                `json:"name"`
	NotificationsUrl string                `json:"notifications_url"`
	OpenIssues       int                   `json:"open_issues"`
	OpenIssuesCount  int                   `json:"open_issues_count"`
	Owner            RepositoryOwner       `json:"owner"`
	Permissions      RepositoryPermissions `json:"permissions"`
	Private          bool                  `json:"private"`
	PullsUrl         string                `json:"pulls_url"`
	PushedAt         time.Time             `json:"pushed_at"`
	Size             int                   `json:"size"`
	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"`
	SvnUrl           string                `json:"svn_url"`
	TagsUrl          string                `json:"tags_url"`
	TeamsUrl         string                `json:"teams_url"`
	TreesUrl         string                `json:"trees_url"`
	UpdatedAt        time.Time             `json:"updated_at"`
	Url              string                `json:"url"`
	Watchers         int                   `json:"watchers"`
	WatchersCount    int                   `json:"watchers_count"`
}

type RepositoryOwner

type RepositoryOwner struct {
	AvatarUrl        string `json:"avatar_url"`
	EventsUrl        string `json:"events_url"`
	FollowersUrl     string `json:"followers_url"`
	FollowingUrl     string `json:"following_url"`
	GistsUrl         string `json:"gists_url"`
	GravatarId       string `json:"gravatar_id"`
	HtmlUrl          string `json:"html_url"`
	Id               int    `json:"id"`
	Login            string `json:"login"`
	OrganizationsUrl string `json:"organizations_url"`
	ReposUrl         string `json:"repos_url"`
	StarredUrl       string `json:"starred_url"`
	SubscriptionsUrl string `json:"subscriptions_url"`
	Type             string `json:"type"`
	Url              string `json:"url"`
}

type RepositoryPermissions

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

type User

type User struct {
	Login       string    `json:"login"`
	Id          int       `json:"id"`
	AvatarUrl   string    `json:"avatar_url"`
	GravatarId  string    `json:"gravatar_id"`
	Url         string    `json:"url"`
	Name        string    `json:"name"`
	Company     string    `json:"company"`
	Blog        string    `json:"blog"`
	Location    string    `json:"location"`
	Email       string    `json:"email"`
	Hireable    bool      `json:"hireable"`
	Bio         string    `json:"bio"`
	PublicRepos int       `json:"public_repos"`
	PublicGists int       `json:"public_gists"`
	Followers   int       `json:"followers"`
	Following   int       `json:"following"`
	HtmlUrl     string    `json:"html_url"`
	CreatedAt   time.Time `json:"created_at"`
	Type        string    `json:"type"`
	// contains filtered or unexported fields
}

Represents information about a user's account as defined here: http://developer.github.com/v3/users/#get-a-single-user

Please take note that you cannot use the User struct to modify the details of a user's account. To do this, please look at the CurrentUser struct.

func (User) GetFollowers

func (u User) GetFollowers() (followers []Follower, err error)

Gets a detailed list of a user's followers.

func (User) GetFollowing

func (u User) GetFollowing() (following []Follower, err error)

Gets a list of users the user is following.

func (User) GetPublicKeys

func (u User) GetPublicKeys() (keys []PublicKey, err error)

Gets the verified public SSH keys for a user.

func (*User) Organizations

func (u *User) Organizations() (orgs []Organization, err error)

List all of the organizations the user is a member of.

Please be aware that this method does not return a complete Organization struct; for that, please refer to the (*GitHub).GetOrganization() method.

func (User) Repositories

func (u User) Repositories(options ...int) (repositories []Repository, err error)

Get the user's repositories.

type UsersSearchParam

type UsersSearchParam struct {
	Keyword   string
	StartPage uint   // optional:
	Sort      string // optional: start, forks or update
	Order     string // optional: asc or desc
	// contains filtered or unexported fields
}

Types which represents params and result for search users http://developer.github.com/v3/search/#search-users

type UsersSearchResult

type UsersSearchResult struct {
	GravatarId      string    `json:"gravatar_id"`
	Name            string    `json:"name"`
	CreatedAt       time.Time `json:"created_at"`
	Location        string    `json:"location"`
	PublicRepoCount int       `json:"public_repo_count"`
	Followers       int       `json:"followers"`
	Language        string    `json:"language"`
	Fullname        string    `json:"fullname"`
	Username        string    `json:"username"`
	Id              string    `json:"id"`
	Repos           int       `json:"repos"`
	Type            string    `json:"type"`
	FollowersCount  int       `json:"followers_count"`
	Login           string    `json:"login"`
	Score           float32   `json:"score"`
	Created         time.Time `json:"created"`
}

Jump to

Keyboard shortcuts

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