github

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: ISC Imports: 15 Imported by: 0

README

Go Doc Build Status Go Report Card Test Coverage Maintainability

go-github

A simple REST client for GitHub API v3.

Quick Start

package main

import (
  "context"
  "fmt"

  "github.com/moorara/go-github"
)

func main() {
  c := github.NewClient("")

  commits, resp, err := c.Repo("octocat", "Hello-World").Commits(context.Background(), 50, 1)
  if err != nil {
    panic(err)
  }

  fmt.Printf("Pages: %+v\n", resp.Pages)
  fmt.Printf("Rate: %+v\n\n", resp.Rate)
  for _, c := range commits {
    fmt.Printf("%s\n", c.SHA)
  }
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthError

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

AuthError occurs when there is an authentication problem.

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

type Branch

type Branch struct {
	Name      string `json:"name"`
	Protected bool   `json:"protected"`
	Commit    Commit `json:"commit"`
}

Branch is a GitHub branch object.

type Client

type Client struct {

	// Services
	Users *UsersService
	// contains filtered or unexported fields
}

Client is used for making API calls to GitHub API v3.

func NewClient

func NewClient(accessToken string) *Client

NewClient creates a new client for calling public GitHub API v3.

func NewEnterpriseClient

func NewEnterpriseClient(apiURL, uploadURL, downloadURL, accessToken string) (*Client, error)

NewEnterpriseClient creates a new client for calling an enterprise GitHub API v3.

func (*Client) Do

func (c *Client) Do(req *http.Request, body interface{}) (*Response, error)

Do makes an HTTP request and returns the API response. If body implements the io.Writer interface, the raw response body will be copied to. Otherwise, the response body will be JOSN-decoded into it.

func (*Client) EnsureScopes

func (c *Client) EnsureScopes(ctx context.Context, scopes ...Scope) error

EnsureScopes makes sure the client and the access token have the given scopes. See https://docs.github.com/developers/apps/scopes-for-oauth-apps

Example
c := github.NewClient("")

err := c.EnsureScopes(context.Background(), github.ScopeRepo)
if err != nil {
	panic(err)
}
Output:

func (*Client) NewDownloadRequest

func (c *Client) NewDownloadRequest(ctx context.Context, url string) (*http.Request, error)

NewDownloadRequest creates a new HTTP request for downloading a file from a GitHub release.

func (*Client) NewPageRequest

func (c *Client) NewPageRequest(ctx context.Context, method, url string, pageSize, pageNo int, body interface{}) (*http.Request, error)

NewPageRequest creates a new HTTP request for a GitHub API v3 with page parameters. If body implements the io.Reader interface, the raw request body will be read. Otherwise, the request body will be JOSN-encoded.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, url string, body interface{}) (*http.Request, error)

NewRequest creates a new HTTP request for a GitHub API v3. If body implements the io.Reader interface, the raw request body will be read. Otherwise, the request body will be JOSN-encoded.

func (*Client) NewUploadRequest

func (c *Client) NewUploadRequest(ctx context.Context, url, filepath string) (*http.Request, io.Closer, error)

NewUploadRequest creates a new HTTP request for uploading a file to a GitHub release. When successful, it returns a closer for the given file that should be closed after making the request.

func (*Client) Repo

func (c *Client) Repo(owner, repo string) *RepoService

Repo returns a service providing GitHub APIs for a specific repository.

type Commit

type Commit struct {
	SHA       string    `json:"sha"`
	Commit    RawCommit `json:"commit"`
	Author    User      `json:"author"`
	Committer User      `json:"committer"`
	Parents   []Hash    `json:"parents"`
	URL       string    `json:"url"`
	HTMLURL   string    `json:"html_url"`
}

Commit is a GitHub repository commit object.

type Epoch

type Epoch int64

Epoch is a Unix timestamp.

func (Epoch) String

func (e Epoch) String() string

String returns string representation of an epoch timestamp.

func (Epoch) Time

func (e Epoch) Time() time.Time

Time returns the Time representation of an epoch timestamp.

type Event

type Event struct {
	ID        int       `json:"id"`
	Event     string    `json:"event"`
	CommitID  string    `json:"commit_id"`
	Actor     User      `json:"actor"`
	URL       string    `json:"url"`
	CommitURL string    `json:"commit_url"`
	CreatedAt time.Time `json:"created_at"`
}

Event is a GitHub event object.

type Hash

type Hash struct {
	SHA string `json:"sha"`
	URL string `json:"url"`
}

Hash is a GitHub hash object.

type Issue

type Issue struct {
	ID        int        `json:"id"`
	Number    int        `json:"number"`
	State     string     `json:"state"`
	Locked    bool       `json:"locked"`
	Title     string     `json:"title"`
	Body      string     `json:"body"`
	User      User       `json:"user"`
	Labels    []Label    `json:"labels"`
	Milestone *Milestone `json:"milestone"`
	URL       string     `json:"url"`
	HTMLURL   string     `json:"html_url"`
	LabelsURL string     `json:"labels_url"`
	PullURLs  *PullURLs  `json:"pull_request"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	ClosedAt  *time.Time `json:"closed_at"`
}

Issue is a GitHub issue object.

type IssuesParams

type IssuesParams struct {
	State string
	Since time.Time
}

IssuesParams are optional parameters for Issues.

type Label

type Label struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Color       string `json:"color"`
	Default     bool   `json:"default"`
	URL         string `json:"url"`
}

Label is a GitHub label object.

type Milestone

type Milestone struct {
	ID           int        `json:"id"`
	Number       int        `json:"number"`
	State        string     `json:"state"`
	Title        string     `json:"title"`
	Description  string     `json:"description"`
	Creator      User       `json:"creator"`
	OpenIssues   int        `json:"open_issues"`
	ClosedIssues int        `json:"closed_issues"`
	DueOn        *time.Time `json:"due_on"`
	URL          string     `json:"url"`
	HTMLURL      string     `json:"html_url"`
	LabelsURL    string     `json:"labels_url"`
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
	ClosedAt     *time.Time `json:"closed_at"`
}

Milestone is a GitHub milestone object.

type NotFoundError

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

NotFoundError occurs when a resource is not found.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) Unwrap

func (e *NotFoundError) Unwrap() error

type Pages

type Pages struct {
	First int
	Prev  int
	Next  int
	Last  int
}

Pages represents the pagination information for GitHub API v3.

type Permission

type Permission string

Permission represents a GitHub repository permission. See https://docs.github.com/en/github/setting-up-and-managing-organizations-and-teams/repository-permission-levels-for-an-organization

const (
	// PermissionNone does not allow anything.
	PermissionNone Permission = "none"
	// PermissionRead allows a contributor to view or discuss a project.
	PermissionRead Permission = "read"
	// PermissionTriage allows a contributor to manage issues and pull requests without write access.
	PermissionTriage Permission = "triage"
	// PermissionWrite allows a contributor to push to a project.
	PermissionWrite Permission = "write"
	// PermissionMaintain allows a contributor to manage a repository without access to sensitive or destructive actions.
	PermissionMaintain Permission = "maintain"
	// PermissionAdmin gives a contributor full access to a project, including sensitive and destructive actions.
	PermissionAdmin Permission = "admin"
)

type Pull

type Pull struct {
	ID             int        `json:"id"`
	Number         int        `json:"number"`
	State          string     `json:"state"`
	Draft          bool       `json:"draft"`
	Locked         bool       `json:"locked"`
	Title          string     `json:"title"`
	Body           string     `json:"body"`
	User           User       `json:"user"`
	Labels         []Label    `json:"labels"`
	Milestone      *Milestone `json:"milestone"`
	Base           PullBranch `json:"base"`
	Head           PullBranch `json:"head"`
	Merged         bool       `json:"merged"`
	Mergeable      *bool      `json:"mergeable"`
	Rebaseable     *bool      `json:"rebaseable"`
	MergedBy       *User      `json:"merged_by"`
	MergeCommitSHA string     `json:"merge_commit_sha"`
	URL            string     `json:"url"`
	HTMLURL        string     `json:"html_url"`
	DiffURL        string     `json:"diff_url"`
	PatchURL       string     `json:"patch_url"`
	IssueURL       string     `json:"issue_url"`
	CommitsURL     string     `json:"commits_url"`
	StatusesURL    string     `json:"statuses_url"`
	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
	ClosedAt       *time.Time `json:"closed_at"`
	MergedAt       *time.Time `json:"merged_at"`
}

Pull is a GitHub pull request object.

type PullBranch

type PullBranch struct {
	Label string     `json:"label"`
	Ref   string     `json:"ref"`
	SHA   string     `json:"sha"`
	User  User       `json:"user"`
	Repo  Repository `json:"repo"`
}

PullBranch represents a base or head object in a Pull object.

type PullURLs

type PullURLs struct {
	URL      string `json:"url"`
	HTMLURL  string `json:"html_url"`
	DiffURL  string `json:"diff_url"`
	PatchURL string `json:"patch_url"`
}

PullURLs is an object added to an issue representing a pull request.

type PullsParams

type PullsParams struct {
	State string
}

PullsParams are optional parameters for Pulls.

type Rate

type Rate struct {
	// The number of requests per hour.
	Limit int `json:"limit"`

	// The number of requests used in the current hour.
	Used int `json:"used,omitempty"`

	// The number of requests remaining in the current hour.
	Remaining int `json:"remaining"`

	// The time at which the current rate will reset.
	Reset Epoch `json:"reset"`
}

Rate represents the rate limit status for the authenticated user.

type RateLimitAbuseError

type RateLimitAbuseError struct {
	Rate       Rate
	RetryAfter time.Duration
	// contains filtered or unexported fields
}

RateLimitAbuseError occurs when best practices for using the legitimate rate limit are not observed. See https://docs.github.com/rest/overview/resources-in-the-rest-api#abuse-rate-limits

func (*RateLimitAbuseError) Error

func (e *RateLimitAbuseError) Error() string

func (*RateLimitAbuseError) Unwrap

func (e *RateLimitAbuseError) Unwrap() error

type RateLimitError

type RateLimitError struct {
	Request *http.Request
	Rate    Rate
	// contains filtered or unexported fields
}

RateLimitError occurs when there is no remaining call in the current hour for the authenticated user. See https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

func (*RateLimitError) Unwrap

func (e *RateLimitError) Unwrap() error

type RawCommit

type RawCommit struct {
	Message   string    `json:"message"`
	Author    Signature `json:"author"`
	Committer Signature `json:"committer"`
	Tree      Hash      `json:"tree"`
	URL       string    `json:"url"`
}

RawCommit is a GitHub raw commit object.

type Release

type Release struct {
	ID          int            `json:"id"`
	Name        string         `json:"name"`
	TagName     string         `json:"tag_name"`
	Target      string         `json:"target_commitish"`
	Draft       bool           `json:"draft"`
	Prerelease  bool           `json:"prerelease"`
	Body        string         `json:"body"`
	URL         string         `json:"url"`
	HTMLURL     string         `json:"html_url"`
	AssetsURL   string         `json:"assets_url"`
	UploadURL   string         `json:"upload_url"`
	TarballURL  string         `json:"tarball_url"`
	ZipballURL  string         `json:"zipball_url"`
	CreatedAt   time.Time      `json:"created_at"`
	PublishedAt time.Time      `json:"published_at"`
	Author      User           `json:"author"`
	Assets      []ReleaseAsset `json:"assets"`
}

Release is a GitHub release object.

type ReleaseAsset

type ReleaseAsset struct {
	ID            int       `json:"id"`
	Name          string    `json:"name"`
	Label         string    `json:"label"`
	State         string    `json:"state"`
	ContentType   string    `json:"content_type"`
	Size          int       `json:"size"`
	DownloadCount int       `json:"download_count"`
	URL           string    `json:"url"`
	DownloadURL   string    `json:"browser_download_url"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
	Uploader      User      `json:"uploader"`
}

ReleaseAsset is a Github release asset object.

type ReleaseParams

type ReleaseParams struct {
	Name       string `json:"name"`
	TagName    string `json:"tag_name"`
	Target     string `json:"target_commitish"`
	Draft      bool   `json:"draft"`
	Prerelease bool   `json:"prerelease"`
	Body       string `json:"body"`
}

ReleaseParams is used for creating or updating a GitHub release.

type RepoService

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

RepoService provides GitHub APIs for a specific repository. See https://docs.github.com/en/rest/reference/repos

func (*RepoService) Branch

func (s *RepoService) Branch(ctx context.Context, name string) (*Branch, *Response, error)

Branch retrieves a branch for a given repository by its name. See https://docs.github.com/rest/reference/repos#get-a-branch

func (*RepoService) BranchProtection

func (s *RepoService) BranchProtection(ctx context.Context, branch string, enabled bool) (*Response, error)

BranchProtection enables/disables a branch protection for administrator users. See https://docs.github.com/rest/reference/repos#set-admin-branch-protection See https://docs.github.com/rest/reference/repos#delete-admin-branch-protection

func (*RepoService) Commit

func (s *RepoService) Commit(ctx context.Context, ref string) (*Commit, *Response, error)

Commit retrieves a commit for a given repository by its reference. See https://docs.github.com/rest/reference/repos#get-a-commit

func (*RepoService) Commits

func (s *RepoService) Commits(ctx context.Context, pageSize, pageNo int) ([]Commit, *Response, error)

Commits retrieves all commits for a given repository page by page. See https://docs.github.com/rest/reference/repos#list-commits

Example
c := github.NewClient("")

commits, resp, err := c.Repo("octocat", "Hello-World").Commits(context.Background(), 50, 1)
if err != nil {
	panic(err)
}

fmt.Printf("Pages: %+v\n", resp.Pages)
fmt.Printf("Rate: %+v\n\n", resp.Rate)
for _, c := range commits {
	fmt.Printf("%s\n", c.SHA)
}
Output:

func (*RepoService) CreateRelease

func (s *RepoService) CreateRelease(ctx context.Context, params ReleaseParams) (*Release, *Response, error)

CreateRelease creates a new GitHub release. See https://docs.github.com/rest/reference/repos#create-a-release

func (*RepoService) DownloadReleaseAsset

func (s *RepoService) DownloadReleaseAsset(ctx context.Context, releaseTag, assetName string, w io.Writer) (*Response, error)

DownloadReleaseAsset downloads an asset from a GitHub release.

func (*RepoService) DownloadTarArchive added in v0.1.1

func (s *RepoService) DownloadTarArchive(ctx context.Context, ref string, w io.Writer) (*Response, error)

DownloadTarArchive downloads a repository archive in tar format.

func (*RepoService) DownloadZipArchive added in v0.1.1

func (s *RepoService) DownloadZipArchive(ctx context.Context, ref string, w io.Writer) (*Response, error)

DownloadZipArchive downloads a repository archive in zip format.

func (*RepoService) Events

func (s *RepoService) Events(ctx context.Context, number, pageSize, pageNo int) ([]Event, *Response, error)

Events retrieves all events for a given repository and an issue page by page. See https://docs.github.com/rest/reference/issues#list-issue-events

func (*RepoService) Get

func (s *RepoService) Get(ctx context.Context) (*Repository, *Response, error)

Get retrieves a repository by its name. See https://docs.github.com/rest/reference/repos#get-a-repository

func (*RepoService) Issues

func (s *RepoService) Issues(ctx context.Context, pageSize, pageNo int, params IssuesParams) ([]Issue, *Response, error)

Issues retrieves all issues for a given repository page by page. See https://docs.github.com/rest/reference/issues#list-repository-issues

func (*RepoService) LatestRelease

func (s *RepoService) LatestRelease(ctx context.Context) (*Release, *Response, error)

LatestRelease returns the latest GitHub release. The latest release is the most recent non-prerelease and non-draft release. See https://docs.github.com/rest/reference/repos#get-the-latest-release

func (*RepoService) Permission

func (s *RepoService) Permission(ctx context.Context, username string) (Permission, *Response, error)

Permission returns the repository permission for a collaborator (user). See https://docs.github.com/en/rest/reference/repos#get-repository-permissions-for-a-user

func (*RepoService) Pull

func (s *RepoService) Pull(ctx context.Context, number int) (*Pull, *Response, error)

Pull retrieves a pull request for a given repository by its number. See https://docs.github.com/rest/reference/pulls#get-a-pull-request

func (*RepoService) Pulls

func (s *RepoService) Pulls(ctx context.Context, pageSize, pageNo int, params PullsParams) ([]Pull, *Response, error)

Pulls retrieves all pull requests for a given repository page by page. See https://docs.github.com/rest/reference/pulls#list-pull-requests

func (*RepoService) Tags

func (s *RepoService) Tags(ctx context.Context, pageSize, pageNo int) ([]Tag, *Response, error)

Tags retrieves all tags for a given repository page by page. See https://docs.github.com/rest/reference/repos#list-repository-tags

func (*RepoService) UpdateRelease

func (s *RepoService) UpdateRelease(ctx context.Context, releaseID int, params ReleaseParams) (*Release, *Response, error)

UpdateRelease updates an existing GitHub release. See https://docs.github.com/rest/reference/repos#update-a-release

func (*RepoService) UploadReleaseAsset

func (s *RepoService) UploadReleaseAsset(ctx context.Context, releaseID int, assetFile, assetLabel string) (*ReleaseAsset, *Response, error)

UploadReleaseAsset uploads a file to a GitHub release. See https://docs.github.com/rest/reference/repos#upload-a-release-asset

type Repository

type Repository struct {
	ID            int       `json:"id"`
	Name          string    `json:"name"`
	FullName      string    `json:"full_name"`
	Description   string    `json:"description"`
	Topics        []string  `json:"topics"`
	Private       bool      `json:"private"`
	Fork          bool      `json:"fork"`
	Archived      bool      `json:"archived"`
	Disabled      bool      `json:"disabled"`
	DefaultBranch string    `json:"default_branch"`
	Owner         User      `json:"owner"`
	URL           string    `json:"url"`
	HTMLURL       string    `json:"html_url"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
	PushedAt      time.Time `json:"pushed_at"`
}

Repository is a GitHub repository object.

type Response

type Response struct {
	*http.Response

	Pages Pages
	Rate  Rate
}

Response represents an HTTP response for GitHub API v3.

type ResponseError

type ResponseError struct {
	Response         *http.Response
	Message          string `json:"message"`
	DocumentationURL string `json:"documentation_url,omitempty"`
}

ResponseError is a generic error for HTTP calls to GitHub API v3. See https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#client-errors

func (*ResponseError) Error

func (e *ResponseError) Error() string

type Scope

type Scope string

Scope represents a GitHub authorization scope. See https://docs.github.com/developers/apps/scopes-for-oauth-apps

const (
	// ScopeRepo grants full access to private and public repositories. It also grants ability to manage user projects.
	ScopeRepo Scope = "repo"
	// ScopeRepoStatus grants read/write access to public and private repository commit statuses.
	ScopeRepoStatus Scope = "repo:status"
	// ScopeRepoDeployment grants access to deployment statuses for public and private repositories.
	ScopeRepoDeployment Scope = "repo_deployment"
	// ScopePublicRepo grants access only to public repositories.
	ScopePublicRepo Scope = "public_repo"
	// ScopeRepoInvite grants accept/decline abilities for invitations to collaborate on a repository.
	ScopeRepoInvite Scope = "repo:invite"
	// ScopeSecurityEvents grants read and write access to security events in the code scanning API.
	ScopeSecurityEvents Scope = "security_events"

	// ScopeWritePackages grants access to upload or publish a package in GitHub Packages.
	ScopeWritePackages Scope = "write:packages"
	// ScopeReadPackages grants access to download or install packages from GitHub Packages.
	ScopeReadPackages Scope = "read:packages"
	// ScopeDeletePackages grants access to delete packages from GitHub Packages.
	ScopeDeletePackages Scope = "delete:packages"

	// ScopeAdminOrg grants access to fully manage the organization and its teams, projects, and memberships.
	ScopeAdminOrg Scope = "admin:org"
	// ScopeWriteOrg grants read and write access to organization membership, organization projects, and team membership.
	ScopeWriteOrg Scope = "write:org"
	// ScopeReadOrg grants read-only access to organization membership, organization projects, and team membership.
	ScopeReadOrg Scope = "read:org"

	// ScopeAdminPublicKey grants access to fully manage public keys.
	ScopeAdminPublicKey Scope = "admin:public_key"
	// ScopeWritePublicKey grants access to create, list, and view details for public keys.
	ScopeWritePublicKey Scope = "write:public_key"
	// ScopeReadPublicKey grants access to list and view details for public keys.
	ScopeReadPublicKey Scope = "read:public_key"

	// ScopeAdminRepoHook grants read, write, ping, and delete access to repository hooks in public and private repositories.
	ScopeAdminRepoHook Scope = "admin:repo_hook"
	// ScopeWriteRepoHook grants read, write, and ping access to hooks in public or private repositories.
	ScopeWriteRepoHook Scope = "write:repo_hook"
	// ScopeReadRepoHook grants read and ping access to hooks in public or private repositories.
	ScopeReadRepoHook Scope = "read:repo_hook"

	// ScopeAdminOrgHook grants read, write, ping, and delete access to organization hooks.
	ScopeAdminOrgHook Scope = "admin:org_hook"
	// ScopeGist grants write access to gists.
	ScopeGist Scope = "gist"
	// ScopeNotifications grants read access to a user's notifications and misc.
	ScopeNotifications Scope = "notifications"

	// ScopeUser grants read/write access to profile info only.
	ScopeUser Scope = "user"
	// ScopeReadUser grants access to read a user's profile data.
	ScopeReadUser Scope = "read:user"
	// ScopeUserEmail grants read access to a user's email addresses.
	ScopeUserEmail Scope = "user:email"
	// ScopeUserFollow grants access to follow or unfollow other users.
	ScopeUserFollow Scope = "user:follow"

	// ScopeDeleteRepo grants access to delete adminable repositories.
	ScopeDeleteRepo Scope = "delete_repo"

	// ScopeWriteDiscussion allows read and write access for team discussions.
	ScopeWriteDiscussion Scope = "write:discussion"
	// ScopeReadDiscussion allows read access for team discussions.
	ScopeReadDiscussion Scope = "read:discussion"

	// ScopeAdminGPGKey grants access to fully manage GPG keys.
	ScopeAdminGPGKey Scope = "admin:gpg_key"
	// ScopeWriteGPGKey grants access to create, list, and view details for GPG keys.
	ScopeWriteGPGKey Scope = "write:gpg_key"
	// ScopeReadGPGKey grants access to list and view details for GPG keys.
	ScopeReadGPGKey Scope = "read:gpg_key"

	// ScopeWorkflow grants the ability to add and update GitHub Actions workflow files.
	ScopeWorkflow Scope = "workflow"
)

type Signature

type Signature struct {
	Name  string    `json:"name"`
	Email string    `json:"email"`
	Time  time.Time `json:"date"`
}

Signature is a GitHub signature object.

type Tag

type Tag struct {
	Name   string `json:"name"`
	Commit Hash   `json:"commit"`
}

Tag is a GitHib tag object.

type User

type User struct {
	ID         int       `json:"id"`
	Login      string    `json:"login"`
	Type       string    `json:"type"`
	Email      string    `json:"email"`
	Name       string    `json:"name"`
	URL        string    `json:"url"`
	HTMLURL    string    `json:"html_url"`
	OrgsURL    string    `json:"organizations_url"`
	AvatarURL  string    `json:"avatar_url"`
	GravatarID string    `json:"gravatar_id"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

User is a GitHub user object.

type UsersService

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

UsersService provides GitHub APIs for users. See https://docs.github.com/en/rest/reference/users

func (*UsersService) Get

func (s *UsersService) Get(ctx context.Context, username string) (*User, *Response, error)

Get retrieves a user by its username (login). See https://docs.github.com/rest/reference/users#get-a-user

Example
c := github.NewClient("")

user, resp, err := c.Users.Get(context.Background(), "octocat")
if err != nil {
	panic(err)
}

fmt.Printf("Pages: %+v\n", resp.Pages)
fmt.Printf("Rate: %+v\n\n", resp.Rate)
fmt.Printf("Name: %s\n", user.Name)
Output:

func (*UsersService) User

func (s *UsersService) User(ctx context.Context) (*User, *Response, error)

User returns the authenticated user. If the access token does not have the user scope, then the response includes only the public information. If the access token has the user scope, then the response includes the public and private information. See https://docs.github.com/rest/reference/users#get-the-authenticated-user

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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