Documentation
¶
Overview ¶
Package gh wraps the GitHub REST and GraphQL APIs for syncing issues, PRs, and project items.
Index ¶
- func ParseGitHubURL(gitHubURL string) (owner, name, typ string, number int, err error)
- type ClosingIssue
- type ItemValueType
- type PRApproval
- type Project
- func (p *Project) AddItem(nodeID string) (*string, error)
- func (p *Project) GetItemFieldValuesByNodeID(contentNodeID string, fieldNames []string) (map[string]ProjectItemFieldValue, error)
- func (p *Project) GetItems() ([]ProjectItem, error)
- func (p *Project) HasItem(nodeID string) (*string, error)
- func (p *Project) LoadDetails() error
- func (p *Project) SetItemStatus(itemID, status string) error
- func (p *Project) UpdateItem(itemID string, fields []ProjectItemField) error
- type ProjectDetails
- type ProjectDetailsResult
- type ProjectItem
- type ProjectItemField
- type ProjectItemFieldValue
- type ProjectItemsResult
- type PullRequest
- type Rate
- type RateLimits
- type Repo
- func (r Repo) GetAllIssueEvents(number int) (*[]github.Timeline, error)
- func (r Repo) GetAllIssues(state string) (*[]github.Issue, error)
- func (r Repo) GetAllPullRequests(state string) (*[]github.PullRequest, error)
- func (r Repo) GetAllPullRequestsGQL(states, reviewers []string, limit int, progress func(int)) (*[]PullRequest, error)
- func (r Repo) GetLabelsFor(number int) (*[]string, error)
- func (r Repo) GetPullRequest(pr int) (*github.PullRequest, error)
- func (r Repo) ListAllIssueEvents(number int, cb func([]*github.Timeline, *github.Response) error) error
- func (r Repo) ListAllIssues(state string, cb func([]*github.Issue, *github.Response) error) error
- func (r Repo) ListAllPullRequests(state string, cb func([]*github.PullRequest, *github.Response) error) error
- func (r Repo) PRReviewDecision(pr int) (*string, error)
- func (r Repo) PrURL(pr int) string
- type Token
- func (t Token) GraphQLQuery(query string, params [][]string) (*string, error)
- func (t Token) GraphQLQueryUnmarshal(query string, params [][]string, data any) error
- func (t Token) NewClient() (*github.Client, context.Context)
- func (t Token) NewGraphQLClient() (*githubv4.Client, context.Context, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClosingIssue ¶
type ItemValueType ¶
type ItemValueType int
ItemValueType is the type of a project item field value (text, number, single select, or date).
const ( ItemValueTypeText ItemValueType = iota ItemValueTypeNumber ItemValueTypeSingleSelect ItemValueTypeDate )
func (ItemValueType) String ¶
func (t ItemValueType) String() string
type PRApproval ¶
type Project ¶
type Project struct {
Owner string
Number int
Token
*ProjectDetails
}
func (*Project) GetItemFieldValuesByNodeID ¶
func (p *Project) GetItemFieldValuesByNodeID(contentNodeID string, fieldNames []string) (map[string]ProjectItemFieldValue, error)
GetItemFieldValuesByNodeID looks up the project item for a given content node ID (e.g. an issue) and returns the field values for the requested field names. The returned map is keyed by field name. If the item is not found in the project, returns nil map with no error.
func (*Project) GetItems ¶
func (p *Project) GetItems() ([]ProjectItem, error)
GetItems returns all items in the project. todo: allow configure the fields we want to get
func (*Project) HasItem ¶
HasItem checks whether a given content node (issue or PR) is already in this project. Returns the project item ID if found, nil if not found.
func (*Project) LoadDetails ¶
func (*Project) SetItemStatus ¶
func (*Project) UpdateItem ¶
func (p *Project) UpdateItem(itemID string, fields []ProjectItemField) error
UpdateItem updates the fields of a project item by building a dynamic GraphQL mutation.
type ProjectDetails ¶
type ProjectDetails struct {
ID string
Fields []struct {
ID string
Name string
Options []struct {
ID string
Name string
}
}
FieldIDs map[string]string
StatusIDs map[string]string
FieldTypes map[string]ItemValueType // field name -> type
SingleSelectOptionIDs map[string]map[string]string // field name -> option name -> option ID
SingleSelectOptionNames map[string]map[string]string // field name -> option ID -> option name
}
type ProjectDetailsResult ¶
type ProjectDetailsResult struct {
Data struct {
Organization struct {
ProjectV2 struct {
ID string `json:"id"`
Fields struct {
Nodes []struct {
ID string `json:"id"`
Name string `json:"name"`
Options []struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"options"`
} `json:"nodes"`
} `json:"fields"`
} `json:"projectV2"`
} `json:"organization"`
} `json:"data"`
}
type ProjectItem ¶
type ProjectItemField ¶
type ProjectItemField struct {
Name string // A short name for this field (used in GraphQL alias, e.g. "set_key")
FieldID string // The GraphQL ID of the field
Type ItemValueType
Value any
}
ProjectItemField represents a single field update for the project item. Type should be either "text" or "number".
type ProjectItemFieldValue ¶
type ProjectItemFieldValue struct {
Type ItemValueType
Value any // string for text/date/singleSelect option ID, float64 for number
}
ProjectItemFieldValue holds a field value read from a project item.
type ProjectItemsResult ¶
type ProjectItemsResult struct {
Data struct {
Organization struct {
ProjectV2 struct {
ID string `json:"id"`
Items struct {
PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
EndCursor string `json:"endCursor"`
} `json:"pageInfo"`
Nodes []struct {
ID string `json:"id"`
Type string `json:"type"`
Status *struct {
SingleSelectOptionID string `json:"singleSelectOptionId"`
}
RequestType *struct {
Text string `json:"text"`
} `json:"requestType"`
DueDate *struct {
Date string `json:"date"`
} `json:"dueDate"`
Content struct {
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
} `json:"content"`
} `json:"nodes"`
} `json:"items"`
} `json:"projectV2"`
} `json:"organization"`
} `json:"data"`
}
ProjectItemsResult is the result of the project items query; for now we hard code the project fields we want (dueDate and type). TODO in the future we can make this configurable / get all of them
type PullRequest ¶
type PullRequest struct {
NodeID string
Author string
Number int
Title string
State string
ReviewDecision string
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt time.Time
Draft bool
Milestone string
TotalCommentCount int
TotalReviewCount int
ReviewCommentCount int
FilteredReviewCount int
FilteredReviewCommentCount int
ClosingIssues []ClosingIssue
Assignees []string
AssociatedLabels map[string]bool
AssociatedProjectNumbers map[int]bool
}
type RateLimits ¶
type RateLimits struct {
Core Rate
GraphQL Rate
Search Rate
SourceImport Rate
IntegrationManifest Rate
CodeScanning Rate // code_scanning_upload
ActionsRunnerRegistration Rate
Scim Rate
// "rate" (alias for core)
Rate Rate
// Any new/unknown buckets GitHub adds in the future
Other map[string]Rate
}
RateLimits is the flat set of rate limit buckets, without the "resources" nesting of the API response.
func GetRateLimit ¶
func GetRateLimit(ctx context.Context, token string) (*RateLimits, error)
type Repo ¶
func NewRepoOwnerName ¶
func (Repo) GetAllIssueEvents ¶
func (Repo) GetAllPullRequests ¶
func (r Repo) GetAllPullRequests(state string) (*[]github.PullRequest, error)
func (Repo) GetAllPullRequestsGQL ¶
func (Repo) GetPullRequest ¶
func (r Repo) GetPullRequest(pr int) (*github.PullRequest, error)
func (Repo) ListAllIssueEvents ¶
func (Repo) ListAllIssues ¶
func (Repo) ListAllPullRequests ¶
type Token ¶
type Token struct {
Token *string
}