github

package
v0.0.0-...-deb4dbf Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrScope = "github"

	ErrCodeParameter    = 10
	ErrCodeClientOption = 11
	ErrCodeMakeRequest  = 20
	ErrCodeNetwork      = 30
	ErrCodeAccessToken  = 40
)
View Source
const (
	HTMLHost    = "https://github.com/"
	HTMLPathPre = "blob/master"
	APIHost     = "https://api.github.com/"
	APIPathPre  = "graphql"
)
View Source
const QueryRepo = `` /* 256-byte string literal not displayed */
View Source
const QueryUser = `{ "query": "query { viewer { login } rateLimit { limit, remaining, resetAt }}"`

Variables

This section is empty.

Functions

func IsAbuseError

func IsAbuseError(err error) bool

func SetDefaultLogger

func SetDefaultLogger(logger *zap.Logger)

Types

type Client

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

func NewClient

func NewClient(htmlClient HTTPClient, apiClient HTTPClient, option ClientOption) (*Client, error)

func (*Client) GetHTML

func (c *Client) GetHTML(id RepoID, path string) (string, error)

Get file wrapped in html page.

func (Client) GetHTMLReadme

func (c Client) GetHTMLReadme(id RepoID) (string, error)

Get README.md wrapped in html page.

func (Client) GetRepo

func (c Client) GetRepo(ctx context.Context, id RepoID) (*Repo, error)

Get repository information.

func (*Client) GetUser

func (c *Client) GetUser() (*User, error)

Get current user information.

type ClientOption

type ClientOption struct {
	HTMLHost    string // GitHub HTML host
	HTMLPathPre string // GitHub HTML path prefix
	APIHost     string // GitHub API host
	ApiPathPre  string // GitHub API path prefix
	AccessToken string // GitHub personal access token
}

func NewDefaultClientOption

func NewDefaultClientOption() ClientOption

type HTTPClient

type HTTPClient interface {
	Json(req *http.Request, resp interface{}) (err error)
	Text(req *http.Request) (text string, err error)
}

type Repo

type Repo struct {
	Data struct {
		Repository struct {
			Forks struct {
				TotalCount int
			}
			Stargazers struct {
				TotalCount int
			}
			Watchers struct {
				TotalCount int
			}
			DefaultBranchRef struct {
				Target struct {
					History struct {
						Edges []struct {
							Node struct {
								CommittedDate time.Time
							}
						}
					}
				}
			}
			Description string
		}
	}
	Errors []struct {
		Message string
	}
}

type RepoID

type RepoID struct {
	Owner string `json:"owner"`
	Name  string `json:"name"`
}

func (RepoID) String

func (r RepoID) String() string

type User

type User struct {
	Data struct {
		Viewer struct {
			Login string
		}
		Ratelimit struct {
			Limit     int
			Remaining int
			ResetAt   time.Time
		}
	}
	Errors []struct {
		Message string
	}
}

Jump to

Keyboard shortcuts

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