github

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: BSD-3-Clause Imports: 12 Imported by: 1

README

This repo holds Go code for interacting with GitHub. See in particular the issue command, https://godoc.org/rsc.io/github/issue

Documentation

Overview

Package github provides idiomatic Go APIs for accessing basic GitHub issue operations.

The entire GitHub API can be accessed by using the Client with GraphQL schema from rsc.io/github/schema.

Package github provides idiomatic Go APIs for accessing basic GitHub issue operations.

The entire GitHub API can be accessed by using the Client with GraphQL schema from rsc.io/github/schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

A Client is an authenticated client for accessing the GitHub GraphQL API. Client provides convenient methods for common operations. To build others, see the [GraphQLQuery] and [GraphQLMutation] methods.

func Dial

func Dial(user string) (*Client, error)

Dial returns a Client authenticating as user. Authentication credentials are loaded from $HOME/.netrc using the 'api.github.com' entry, which should contain a GitHub personal access token. If user is the empty string, Dial uses the first line in .netrc listed for api.github.com.

For example, $HOME/.netrc might contain:

machine api.github.com login ken password ghp_123456789abcdef123456789abcdef12345

func NewClient added in v0.4.0

func NewClient(token string) *Client

NewClient returns a new client using the given GitHub personal access token (of the form "ghp_....").

func (*Client) AddIssueComment

func (c *Client) AddIssueComment(issue *Issue, text string) error

func (*Client) AddIssueLabels

func (c *Client) AddIssueLabels(issue *Issue, labels ...*Label) error

func (*Client) CloseIssue

func (c *Client) CloseIssue(issue *Issue) error

func (*Client) CreateIssue

func (c *Client) CreateIssue(repo *Repo, title, body string, extra ...any) (*Issue, error)

func (*Client) DeleteIssue added in v0.4.0

func (c *Client) DeleteIssue(issue *Issue) error

func (*Client) DeleteProjectItem

func (c *Client) DeleteProjectItem(project *Project, item *ProjectItem) error

func (*Client) Discussions added in v0.4.0

func (c *Client) Discussions(org, repo string) ([]*Discussion, error)

func (*Client) EditIssueComment

func (c *Client) EditIssueComment(comment *IssueComment, body string) error

func (*Client) GraphQLMutation

func (c *Client) GraphQLMutation(query string, vars Vars) (*schema.Mutation, error)

GraphQLMutation runs a single mutation with the bound variables. For example, to edit an issue comment:

func editComment(commentID, body string) error {
	graphql := `
	  mutation($Comment: ID!, $Body: String!) {
	    updateIssueComment(input: {id: $Comment, body: $Body}) {
	      clientMutationId
	    }
	  }
	`
	_, err := c.GraphQLMutation(graphql, Vars{"Comment": commentID, "Body": body})
	return err
}

(This is roughly the implementation of the Client.EditIssueComment method.)

func (*Client) GraphQLQuery

func (c *Client) GraphQLQuery(query string, vars Vars) (*schema.Query, error)

GraphQLQuery runs a single query with the bound variables. For example, to look up a repository ID:

func repoID(org, name string) (string, error) {
	graphql := `
	  query($Org: String!, $Repo: String!) {
	    repository(owner: $Org, name: $Repo) {
	      id
	    }
	  }
	`
	vars := Vars{"Org": org, "Repo": repo}
	q, err := c.GraphQLQuery(graphql, vars)
	if err != nil {
		return "", err
	}
	return string(q.Repository.Id), nil
}

(This is roughly the implementation of the Client.Repo method.)

func (*Client) Issue added in v0.4.0

func (c *Client) Issue(org, repo string, n int) (*Issue, error)

func (*Client) IssueComments

func (c *Client) IssueComments(issue *Issue) ([]*IssueComment, error)

func (*Client) ProjectItems

func (c *Client) ProjectItems(p *Project) ([]*ProjectItem, error)

func (*Client) Projects

func (c *Client) Projects(org, query string) ([]*Project, error)

func (*Client) RemilestoneIssue

func (c *Client) RemilestoneIssue(issue *Issue, milestone *Milestone) error

func (*Client) RemoveIssueLabels

func (c *Client) RemoveIssueLabels(issue *Issue, labels ...*Label) error

func (*Client) ReopenIssue

func (c *Client) ReopenIssue(issue *Issue) error

func (*Client) Repo

func (c *Client) Repo(org, repo string) (*Repo, error)

func (*Client) RetitleIssue

func (c *Client) RetitleIssue(issue *Issue, title string) error

func (*Client) SearchLabels

func (c *Client) SearchLabels(org, repo, query string) ([]*Label, error)

func (*Client) SearchMilestones

func (c *Client) SearchMilestones(org, repo, query string) ([]*Milestone, error)

func (*Client) SetProjectItemFieldOption

func (c *Client) SetProjectItemFieldOption(project *Project, item *ProjectItem, field *ProjectField, option *ProjectFieldOption) error

func (*Client) UserComments added in v0.4.0

func (c *Client) UserComments(user string) ([]*IssueComment, error)

type Discussion added in v0.4.0

type Discussion struct {
	Locked bool
	Title  string
	Number int
	Owner  string
	Repo   string
	Body   string
}

type Issue

type Issue struct {
	ID           string
	Title        string
	Number       int
	Closed       bool
	ClosedAt     time.Time
	CreatedAt    time.Time
	LastEditedAt time.Time
	Labels       []*Label
	Milestone    *Milestone
	Author       string
	Owner        string
	Repo         string
	Body         string
	URL          string
}

func (*Issue) LabelByName

func (i *Issue) LabelByName(name string) *Label

type IssueComment

type IssueComment struct {
	ID          string
	Author      string
	Body        string
	CreatedAt   time.Time
	PublishedAt time.Time
	UpdatedAt   time.Time
	Issue       int
	Owner       string
	Repo        string
}

type Label

type Label struct {
	Name        string
	Description string
	ID          string
	Owner       string
	Repo        string
}

type Milestone

type Milestone struct {
	Title string
	ID    string
}

type Project

type Project struct {
	ID        string
	Closed    bool
	ClosedAt  time.Time
	CreatedAt time.Time
	UpdatedAt time.Time
	Fields    []*ProjectField
	Number    int
	Title     string
	URL       string
	Org       string
}

func (*Project) FieldByName

func (p *Project) FieldByName(name string) *ProjectField

type ProjectField

type ProjectField struct {
	Kind       string // "field", "iteration", "select"
	CreatedAt  time.Time
	UpdatedAt  time.Time
	DataType   schema.ProjectV2FieldType // TODO
	DatabaseID int
	ID         schema.ID
	Name       string
	Iterations *ProjectIterations
	Options    []*ProjectFieldOption
}

func (*ProjectField) OptionByName

func (f *ProjectField) OptionByName(name string) *ProjectFieldOption

type ProjectFieldOption

type ProjectFieldOption struct {
	ID       string
	Name     string
	NameHTML string
}

func (*ProjectFieldOption) String

func (o *ProjectFieldOption) String() string

type ProjectFieldValue

type ProjectFieldValue struct {
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Kind       string
	ID         string
	DatabaseID int
	Field      string
	Option     *ProjectFieldOption
	Date       time.Time
	Text       string
}

func (*ProjectFieldValue) String

func (v *ProjectFieldValue) String() string

type ProjectItem

type ProjectItem struct {
	CreatedAt  time.Time
	DatabaseID int
	ID         schema.ID
	IsArchived bool
	Type       schema.ProjectV2ItemType
	UpdatedAt  time.Time
	Fields     []*ProjectFieldValue
	Issue      *Issue
}

func (*ProjectItem) FieldByName

func (it *ProjectItem) FieldByName(name string) *ProjectFieldValue

type ProjectIteration

type ProjectIteration struct {
	Days      int
	ID        string
	Start     time.Time
	Title     string
	TitleHTML string
}

type ProjectIterations

type ProjectIterations struct {
	Completed []*ProjectIteration
	Active    []*ProjectIteration
	Days      int
	StartDay  time.Weekday
}

type Repo

type Repo struct {
	Owner string
	Repo  string
	ID    string
}

type Vars

type Vars map[string]any

A Vars is a binding of GraphQL variables to JSON-able values (usually strings).

Directories

Path Synopsis
internal
minutes Module
minutes2 Module
minutes3 Module
Issue is a client for reading and updating issues in a GitHub project issue tracker.
Issue is a client for reading and updating issues in a GitHub project issue tracker.
Package schema is Go data structures corresponding to the GitHub GraphQL schema.
Package schema is Go data structures corresponding to the GitHub GraphQL schema.

Jump to

Keyboard shortcuts

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