github

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: ISC Imports: 14 Imported by: 0

README

Go Doc Build Status Build Status Go Report Card Test Coverage

go-github

A simple Go client for GitHub API v3.

Quick Start

You can find more examples here.

package main

import (
  "context"
  "fmt"

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

func main() {
  client := github.NewClient("")
  commits, resp, err := client.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 _, commit := range commits {
    fmt.Printf("%s\n", commit.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  *UserService
	Search *SearchService
	// 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
client := github.NewClient("")
if err := client.EnsureScopes(context.Background(), github.ScopeRepo); 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 CreatePullParams

type CreatePullParams struct {
	Draft bool   `json:"draft"`
	Title string `json:"title"`
	Body  string `json:"body"`
	Head  string `json:"head"`
	Base  string `json:"base"`
}

CreatePullParams is used for creating a pull request. See https://docs.github.com/en/rest/reference/pulls#create-a-pull-request

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 IssueService

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

IssueService provides GitHub APIs for issues in a repository. See https://docs.github.com/en/rest/reference/issues

func (*IssueService) Events

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

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

func (*IssueService) List

func (s *IssueService) List(ctx context.Context, pageSize, pageNo int, filter IssuesFilter) ([]Issue, *Response, error)

List retrieves all issues in the repository page by page. See https://docs.github.com/rest/reference/issues#list-repository-issues

Example
client := github.NewClient("")
issues, resp, err := client.Repo("octocat", "Hello-World").Issues.List(context.Background(), 50, 1, github.IssuesFilter{})
if err != nil {
	panic(err)
}

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

type IssuesFilter

type IssuesFilter struct {
	State string
	Since time.Time
}

IssuesFilter are used for fetching 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 PullService

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

PullService provides GitHub APIs for pull requests in a repository. See https://docs.github.com/en/rest/reference/pulls

func (*PullService) Create

func (s *PullService) Create(ctx context.Context, params CreatePullParams) (*Pull, *Response, error)

Create creates a new pull request in the repository. See https://docs.github.com/en/rest/reference/pulls#create-a-pull-request

func (*PullService) Get

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

Get retrieves a pull request in the repository by its number. See https://docs.github.com/rest/reference/pulls#get-a-pull-request

func (*PullService) List

func (s *PullService) List(ctx context.Context, pageSize, pageNo int, filter PullsFilter) ([]Pull, *Response, error)

List retrieves all pull requests in the repository page by page. See https://docs.github.com/rest/reference/pulls#list-pull-requests

Example
client := github.NewClient("")
pulls, resp, err := client.Repo("octocat", "Hello-World").Pulls.List(context.Background(), 50, 1, github.PullsFilter{})
if err != nil {
	panic(err)
}

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

func (*PullService) Update

func (s *PullService) Update(ctx context.Context, number int, params UpdatePullParams) (*Pull, *Response, error)

Update updates a pull request in the repository. See https://docs.github.com/en/rest/reference/pulls#update-a-pull-request

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 PullsFilter

type PullsFilter struct {
	State string
}

PullsFilter are used for fetching Pulls.

type Qualifier

type Qualifier string

Qualifier is a GitHub search qualifier. See https://docs.github.com/en/search-github/searching-on-github

const (
	// QualifierTypeUser matches users.
	QualifierTypeUser Qualifier = "type:user"
	// QualifierTypeOrg matches organizations.
	QualifierTypeOrg Qualifier = "type:org"
	// QualifierTypePR matches pull requests.
	QualifierTypePR Qualifier = "type:pr"
	// QualifierTypeIssue matches issues.
	QualifierTypeIssue Qualifier = "type:issue"
	// QualifierIsPR matches pull requests.
	QualifierIsPR Qualifier = "is:pr"
	// QualifierIsIssue matches issues.
	QualifierIsIssue Qualifier = "is:issue"
	// QualifierInLogin matches a user username.
	QualifierInLogin Qualifier = "in:login"
	// QualifierInName matches a user email.
	QualifierInEmail Qualifier = "in:email"
	// QualifierInName matches a user/repository name.
	QualifierInName Qualifier = "in:name"
	// QualifierInDescription matches a repository description.
	QualifierInDescription Qualifier = "in:description"
	// QualifierInREADME matches a repository README file content.
	QualifierInREADME Qualifier = "in:readme"
	// QualifierInTitle matches issues or pull requests titles.
	QualifierInTitle Qualifier = "in:title"
	// QualifierInBody matches issues or pull requests titles or bodies.
	QualifierInBody Qualifier = "in:body"
	// QualifierInComments matches issues or pull requests comments.
	QualifierInComments Qualifier = "in:comments"
	// QualifierStateOpen matches open issues or pull requests.
	QualifierStateOpen Qualifier = "state:open"
	// QualifierStateClosed matches closed issues or pull requests.
	QualifierStateClosed Qualifier = "state:closed"
	// QualifierIsOpen matches open issues or pull requests.
	QualifierIsOpen Qualifier = "is:open"
	// QualifierIsClosed matches closed issues or pull requests.
	QualifierIsClosed Qualifier = "is:closed"
	// QualifierIsPublic matches public repositories.
	QualifierIsPublic Qualifier = "is:public"
	// QualifierIsInternal matches internal repositories.
	QualifierIsInternal Qualifier = "is:internal"
	// QualifierIsPrivate matches private repositories that the user can access.
	QualifierIsPrivate Qualifier = "is:private"
	// QualifierStatusPending matches open pull requests with a pending status.
	QualifierStatusPending Qualifier = "status:pending"
	// QualifierStatusSuccess matches open pull requests with a successful status.
	QualifierStatusSuccess Qualifier = "status:success"
	// QualifierStatusFailure matches open pull requests with a failed status.
	QualifierStatusFailure Qualifier = "status:failure"
	// QualifierArchivedTrue matches archived repositories.
	QualifierArchivedTrue Qualifier = "archived:true"
	// QualifierArchivedFalse matches unarchived repositories.
	QualifierArchivedFalse Qualifier = "archived:false"
	// QualifierDraftTrue matches draft pull requests.
	QualifierDraftTrue Qualifier = "draft:true"
	// QualifierDraftFalse matches pull requests that are ready for review.
	QualifierDraftFalse Qualifier = "draft:false"
	// QualifierIsMerged matches merged pull requests.
	QualifierIsMerged Qualifier = "is:merged"
	// QualifierIsUnmerged matches closed issues or pull requests.
	QualifierIsUnmerged Qualifier = "is:unmerged"
	// QualifierIsLocked matches issues or pull requests that have a locked conversation.
	QualifierIsLocked Qualifier = "is:locked"
	// QualifierIsUnlocked matches issues or pull requests that have an unlocked conversation.
	QualifierIsUnlocked Qualifier = "is:unlocked"
	// QualifierNoAssignee matches issues or pull requests without any assignees.
	QualifierNoAssignee Qualifier = "no:assignee"
	// QualifierNoLabel matches issues or pull requests without any labels.
	QualifierNoLabel Qualifier = "no:label"
	// QualifierNoProject matches issues or pull requests without any projects.
	QualifierNoProject Qualifier = "no:project"
	// QualifierNoMilestone matches issues or pull requests without a milestone.
	QualifierNoMilestone Qualifier = "no:milestone"
)

func QualifierAssignee

func QualifierAssignee(username string) Qualifier

QualifierAssignee creates a qualifier for matching an assignee.

func QualifierAuthor

func QualifierAuthor(username string) Qualifier

QualifierAuthor creates a qualifier for matching an author.

func QualifierAuthorApp

func QualifierAuthorApp(username string) Qualifier

QualifierAuthorApp creates a qualifier for matching an author app.

func QualifierBase

func QualifierBase(branch string) Qualifier

QualifierBase creates a qualifier for matching a base branch.

func QualifierClosedAfter

func QualifierClosedAfter(t time.Time) Qualifier

QualifierClosedAfter creates a qualifier for matching issues and pull requests closed after a date.

func QualifierClosedBefore

func QualifierClosedBefore(t time.Time) Qualifier

QualifierClosedBefore creates a qualifier for matching issues and pull requests closed before a date.

func QualifierClosedBetween

func QualifierClosedBetween(from, to time.Time) Qualifier

QualifierClosedBetween creates a qualifier for matching issues and pull requests closed between two dates.

func QualifierClosedOn

func QualifierClosedOn(t time.Time) Qualifier

QualifierClosedOn creates a qualifier for matching issues and pull requests closed on a date.

func QualifierClosedOnOrAfter

func QualifierClosedOnOrAfter(t time.Time) Qualifier

QualifierClosedOnOrAfter creates a qualifier for matching issues and pull requests closed on or after a date.

func QualifierClosedOnOrBefore

func QualifierClosedOnOrBefore(t time.Time) Qualifier

QualifierClosedOnOrBefore creates a qualifier for matching issues and pull requests closed on or before a date.

func QualifierCreatedAfter

func QualifierCreatedAfter(t time.Time) Qualifier

QualifierCreatedAfter creates a qualifier for matching issues and pull requests created after a date.

func QualifierCreatedBefore

func QualifierCreatedBefore(t time.Time) Qualifier

QualifierCreatedBefore creates a qualifier for matching issues and pull requests created before a date.

func QualifierCreatedBetween

func QualifierCreatedBetween(from, to time.Time) Qualifier

QualifierCreatedBetween creates a qualifier for matching issues and pull requests created between two dates.

func QualifierCreatedOn

func QualifierCreatedOn(t time.Time) Qualifier

QualifierCreatedOn creates a qualifier for matching issues and pull requests created on a date.

func QualifierCreatedOnOrAfter

func QualifierCreatedOnOrAfter(t time.Time) Qualifier

QualifierCreatedOnOrAfter creates a qualifier for matching issues and pull requests created on or after a date.

func QualifierCreatedOnOrBefore

func QualifierCreatedOnOrBefore(t time.Time) Qualifier

QualifierCreatedOnOrBefore creates a qualifier for matching issues and pull requests created on or before a date.

func QualifierHead

func QualifierHead(branch string) Qualifier

QualifierHead creates a qualifier for matching a head branch.

func QualifierLabel

func QualifierLabel(label string) Qualifier

QualifierLabel creates a qualifier for matching a label.

func QualifierLanguage

func QualifierLanguage(language string) Qualifier

QualifierLanguage creates a qualifier for matching a language.

func QualifierMergedAfter

func QualifierMergedAfter(t time.Time) Qualifier

QualifierMergedAfter creates a qualifier for matching pull requests merged after a date.

func QualifierMergedBefore

func QualifierMergedBefore(t time.Time) Qualifier

QualifierMergedBefore creates a qualifier for matching pull requests merged before a date.

func QualifierMergedBetween

func QualifierMergedBetween(from, to time.Time) Qualifier

QualifierMergedBetween creates a qualifier for matching pull requests merged between two dates.

func QualifierMergedOn

func QualifierMergedOn(t time.Time) Qualifier

QualifierMergedOn creates a qualifier for matching pull requests merged on a date.

func QualifierMergedOnOrAfter

func QualifierMergedOnOrAfter(t time.Time) Qualifier

QualifierMergedOnOrAfter creates a qualifier for matching pull requests merged on or after a date.

func QualifierMergedOnOrBefore

func QualifierMergedOnOrBefore(t time.Time) Qualifier

QualifierMergedOnOrBefore creates a qualifier for matching pull requests merged on or before a date.

func QualifierMilestone

func QualifierMilestone(milestone string) Qualifier

QualifierMilestone creates a qualifier for matching a milestone.

func QualifierOrg

func QualifierOrg(orgname string) Qualifier

QualifierOrg creates a qualifier for matching an organization.

func QualifierProject

func QualifierProject(projectBoard string) Qualifier

QualifierProject creates a qualifier for matching a project board.

func QualifierRepo

func QualifierRepo(repoOwner, repoName string) Qualifier

QualifierRepo creates a qualifier for matching a repository.

func QualifierRepoProject

func QualifierRepoProject(repoOwner, repoName, projectBoard string) Qualifier

QualifierRepoProject creates a qualifier for matching a repository project board.

func QualifierTopic

func QualifierTopic(topic string) Qualifier

QualifierTopic creates a qualifier for matching a topic.

func QualifierUpdatedAfter

func QualifierUpdatedAfter(t time.Time) Qualifier

QualifierUpdatedAfter creates a qualifier for matching issues and pull requests updated after a date.

func QualifierUpdatedBefore

func QualifierUpdatedBefore(t time.Time) Qualifier

QualifierUpdatedBefore creates a qualifier for matching issues and pull requests updated before a date.

func QualifierUpdatedBetween

func QualifierUpdatedBetween(from, to time.Time) Qualifier

QualifierUpdatedBetween creates a qualifier for matching issues and pull requests updated between two dates.

func QualifierUpdatedOn

func QualifierUpdatedOn(t time.Time) Qualifier

QualifierUpdatedOn creates a qualifier for matching issues and pull requests updated on a date.

func QualifierUpdatedOnOrAfter

func QualifierUpdatedOnOrAfter(t time.Time) Qualifier

QualifierUpdatedOnOrAfter creates a qualifier for matching issues and pull requests updated on or after a date.

func QualifierUpdatedOnOrBefore

func QualifierUpdatedOnOrBefore(t time.Time) Qualifier

QualifierUpdatedOnOrBefore creates a qualifier for matching issues and pull requests updated on or before a date.

func QualifierUser

func QualifierUser(username string) Qualifier

QualifierUser creates a qualifier for matching a user.

type Rate

type Rate struct {
	// The resource being rate limited.
	Resource string `json:"resource"`
	// The number of requests per hour.
	Limit int `json:"limit"`
	// The number of requests used in the current hour.
	Used int `json:"used"`
	// 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 ReleaseService

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

ReleaseService provides GitHub APIs for releases in a repository. See https://docs.github.com/en/rest/reference/repos#releases

func (*ReleaseService) Create

func (s *ReleaseService) Create(ctx context.Context, params ReleaseParams) (*Release, *Response, error)

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

func (*ReleaseService) Delete

func (s *ReleaseService) Delete(ctx context.Context, id int) (*Response, error)

Delete deletes a release by release id. See https://docs.github.com/en/rest/reference/repos#delete-a-release

func (*ReleaseService) DownloadAsset

func (s *ReleaseService) DownloadAsset(ctx context.Context, tag, assetName string, w io.Writer) (*Response, error)

DownloadAsset downloads an asset from a GitHub release.

func (*ReleaseService) Get

func (s *ReleaseService) Get(ctx context.Context, id int) (*Release, *Response, error)

Get retrieves a release by release id. See https://docs.github.com/en/rest/reference/repos#get-a-release

func (*ReleaseService) GetByTag

func (s *ReleaseService) GetByTag(ctx context.Context, tag string) (*Release, *Response, error)

GetByTag retrieves a release by tag name. See https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name

func (*ReleaseService) Latest

func (s *ReleaseService) Latest(ctx context.Context) (*Release, *Response, error)

Latest returns the latest 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 (*ReleaseService) List

func (s *ReleaseService) List(ctx context.Context, pageSize, pageNo int) ([]Release, *Response, error)

List retrieves all releases. If the user has push access, draft releases will also be returned. See https://docs.github.com/en/rest/reference/repos#list-releases

Example
client := github.NewClient("")
releases, resp, err := client.Repo("octocat", "Hello-World").Releases.List(context.Background(), 20, 1)
if err != nil {
	panic(err)
}

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

func (*ReleaseService) Update

func (s *ReleaseService) Update(ctx context.Context, id int, params ReleaseParams) (*Release, *Response, error)

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

func (*ReleaseService) UploadAsset

func (s *ReleaseService) UploadAsset(ctx context.Context, id int, assetFile, assetLabel string) (*ReleaseAsset, *Response, error)

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

type RepoService

type RepoService struct {

	// Services
	Pulls    *PullService
	Issues   *IssueService
	Releases *ReleaseService
	// contains filtered or unexported fields
}

RepoService provides GitHub APIs for a 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 in the 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 in the 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 in the repository page by page. See https://docs.github.com/rest/reference/repos#list-commits

Example
client := github.NewClient("")
commits, resp, err := client.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("SHA: %s\n", c.SHA)
}
Output:

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) 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) 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) Tags

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

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

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 SearchIssuesResult

type SearchIssuesResult struct {
	TotalCount        int     `json:"total_count"`
	IncompleteResults bool    `json:"incomplete_results"`
	Items             []Issue `json:"items"`
}

SearchIssuesResult is the result of searching issues and pull requests.

type SearchQuery

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

SearchQuery is used for searching GitHub. See https://docs.github.com/en/rest/reference/search#constructing-a-search-query See https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax

func (*SearchQuery) ExcludeKeywords

func (q *SearchQuery) ExcludeKeywords(keywords ...string)

func (*SearchQuery) ExcludeQualifiers

func (q *SearchQuery) ExcludeQualifiers(qualifiers ...Qualifier)

func (*SearchQuery) IncludeKeywords

func (q *SearchQuery) IncludeKeywords(keywords ...string)

func (*SearchQuery) IncludeQualifiers

func (q *SearchQuery) IncludeQualifiers(qualifiers ...Qualifier)

func (*SearchQuery) String

func (q *SearchQuery) String() string

String returns the GitHub search query parameter.

type SearchReposResult

type SearchReposResult struct {
	TotalCount        int          `json:"total_count"`
	IncompleteResults bool         `json:"incomplete_results"`
	Items             []Repository `json:"items"`
}

SearchReposResult is the result of searching repositories.

type SearchResultOrder

type SearchResultOrder string

SearchResultOrder determines the order of search results.

const (
	// DefaultOrder uses the default ordering.
	DefaultOrder SearchResultOrder = ""
	// AscOrder returns the search results in ascending order.
	AscOrder SearchResultOrder = "asc"
	// DescOrder returns the search results in descending order.
	DescOrder SearchResultOrder = "desc"
)

type SearchResultSort

type SearchResultSort string

SearchResultSort determines how to sort search results.

const (
	// SortByDefault uses the default sorting criteria (best match).
	SortByDefault SearchResultSort = ""
	// SortByFollowers sorts users by the number of followers.
	SortByFollowers SearchResultSort = "followers"
	// SortByRepositories sorts users by the number of repositories.
	SortByRepositories SearchResultSort = "repositories"
	// SortByJoined sorts users by when the joined GitHub.
	SortByJoined SearchResultSort = "joined"
	// SortStars sorts repositories by the number of stars.
	SortByStars SearchResultSort = "stars"
	// SortForks sorts repositories by the number of forks.
	SortByForks SearchResultSort = "forks"
	// SortUpdated sorts repositories, issues, and pull requests by the time they are updated.
	SortByUpdated SearchResultSort = "updated"
	// SortByCreated sorts issues and pull requests by the time they are created.
	SortByCreated SearchResultSort = "created"
	// SortByComments issues and pull requests by the number of comments.
	SortByComments SearchResultSort = "comments"
	// SortByReactions issues and pull requests by the number of reactions.
	SortByReactions SearchResultSort = "reactions"
	// SortByInteractions issues and pull requests by the number of interactions.
	SortByInteractions SearchResultSort = "interactions"
)

type SearchService

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

SearchService provides GitHub APIs for searching users, repositories, issues, pull requests, etc. See https://docs.github.com/en/rest/reference/search

func (*SearchService) SearchIssues

func (s *SearchService) SearchIssues(ctx context.Context, pageSize, pageNo int, sort SearchResultSort, order SearchResultOrder, query SearchQuery) (*SearchIssuesResult, *Response, error)

SearchIssues searches issues and pull requests. See https://docs.github.com/en/rest/reference/search#search-issues-and-pull-requests See https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests

Example
client := github.NewClient("")

query := github.SearchQuery{}
query.IncludeKeywords("Fix")
query.ExcludeKeywords("WIP")
query.IncludeQualifiers(
	github.QualifierTypePR,
	github.QualifierInTitle,
	github.QualifierLabel("bug"),
)

result, resp, err := client.Search.SearchIssues(context.Background(), 20, 1, "", "", query)
if err != nil {
	panic(err)
}

fmt.Printf("Pages: %+v\n", resp.Pages)
fmt.Printf("Rate: %+v\n\n", resp.Rate)
for _, issue := range result.Items {
	fmt.Printf("%s\n", issue.HTMLURL)
}
Output:

type SearchUsersResult

type SearchUsersResult struct {
	TotalCount        int    `json:"total_count"`
	IncompleteResults bool   `json:"incomplete_results"`
	Items             []User `json:"items"`
}

SearchUsersResult is the result of searching users.

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 UpdatePullParams

type UpdatePullParams struct {
	Title string `json:"title"`
	Body  string `json:"body"`
	Base  string `json:"base"`
	State string `json:"state"` // Either open or closed
}

UpdatePullParams is used for updating a pull request. See https://docs.github.com/en/rest/reference/pulls#update-a-pull-request

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 UserService

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

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

func (*UserService) Get

func (s *UserService) 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
client := github.NewClient("")
user, resp, err := client.Users.Get(context.Background(), "octocat")
if err != nil {
	panic(err)
}

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

func (*UserService) User

func (s *UserService) 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
example

Jump to

Keyboard shortcuts

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