Documentation
¶
Overview ¶
Package github contains more usable functions and types for interacting with the Githubv4 API
Index ¶
- Constants
- type Client
- type Commit
- type Commits
- type Datasource
- func (d *Datasource) CheckHealth(ctx context.Context) error
- func (d *Datasource) HandleCommitsQuery(ctx context.Context, query *models.CommitsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandleContributorsQuery(ctx context.Context, query *models.ContributorsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandleGetLabels(w http.ResponseWriter, r *http.Request)
- func (d *Datasource) HandleGetMilestones(w http.ResponseWriter, r *http.Request)
- func (d *Datasource) HandleIssuesQuery(ctx context.Context, query *models.IssuesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandleLabelsQuery(ctx context.Context, query *models.LabelsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandleMilestonesQuery(ctx context.Context, query *models.MilestonesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandlePackagesQuery(ctx context.Context, query *models.PackagesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandlePullRequestsQuery(ctx context.Context, query *models.PullRequestsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandleReleasesQuery(ctx context.Context, query *models.ReleasesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandleRepositoriesQuery(ctx context.Context, query *models.RepositoriesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (d *Datasource) HandleTagsQuery(ctx context.Context, query *models.TagsQuery, req backend.DataQuery) (dfutil.Framer, error)
- type GitActor
- type GitActors
- type Issue
- type Issues
- type Label
- type Labels
- type Milestone
- type Milestones
- type Organization
- type Organizations
- type Package
- type PackageStatistics
- type PackageVersion
- type Packages
- type PageInfo
- type PullRequest
- type PullRequestAuthor
- type PullRequests
- type QueryListCommits
- type QueryListCommitsInRange
- type QueryListContributors
- type QueryListLabels
- type QueryListMilestones
- type QueryListOrganizations
- type QueryListPackages
- type QueryListPullRequests
- type QueryListReleases
- type QueryListRepositories
- type QueryListTags
- type QuerySearchIssues
- type Release
- type Releases
- type Repositories
- type Repository
- type Tag
- type Tags
- type User
- type Users
Constants ¶
const PageNumberLimit = 2
PageNumberLimit is the limit on the number of pages that will be traversed
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Query(ctx context.Context, q interface{}, variables map[string]interface{}) error
}
The Client interface is satisfied by the githubv4.Client type. Rather than accept the githubv4.Client type everywhere, we will follow the Go idiom of accepting interfaces / returning structs and accept this interface.
type Commit ¶
type Commit struct {
OID string
PushedDate githubv4.DateTime
AuthoredDate githubv4.DateTime
CommittedDate githubv4.DateTime
Message githubv4.String
Author GitActor
}
Commit represents a git commit from GitHub's API
type Commits ¶
type Commits []Commit
Commits is a slice of git commits
func GetAllCommits ¶
func GetAllCommits(ctx context.Context, client Client, opts models.ListCommitsOptions) (Commits, error)
GetAllCommits lists every commit in a project. This function is slow and very prone to rate limiting.
type Datasource ¶
type Datasource struct {
// contains filtered or unexported fields
}
Datasource handles requests to GitHub
func NewDatasource ¶
func NewDatasource(ctx context.Context, settings models.Settings) *Datasource
NewDatasource creates a new datasource for handling queries
func (*Datasource) CheckHealth ¶
func (d *Datasource) CheckHealth(ctx context.Context) error
CheckHealth calls frequently used endpoints to determine if the client has sufficient privileges
func (*Datasource) HandleCommitsQuery ¶
func (d *Datasource) HandleCommitsQuery(ctx context.Context, query *models.CommitsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleCommitsQuery is the query handler for listing GitHub Commits
func (*Datasource) HandleContributorsQuery ¶
func (d *Datasource) HandleContributorsQuery(ctx context.Context, query *models.ContributorsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleContributorsQuery is the query handler for listing GitHub Contributors
func (*Datasource) HandleGetLabels ¶
func (d *Datasource) HandleGetLabels(w http.ResponseWriter, r *http.Request)
HandleGetLabels is the HTTP handler for the resource call for getting GitHub labels
func (*Datasource) HandleGetMilestones ¶
func (d *Datasource) HandleGetMilestones(w http.ResponseWriter, r *http.Request)
HandleGetMilestones is the HTTP handler for the resource call for getting GitHub milestones
func (*Datasource) HandleIssuesQuery ¶
func (d *Datasource) HandleIssuesQuery(ctx context.Context, query *models.IssuesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleIssuesQuery is the query handler for listing GitHub Issues
func (*Datasource) HandleLabelsQuery ¶
func (d *Datasource) HandleLabelsQuery(ctx context.Context, query *models.LabelsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleLabelsQuery is the query handler for listing GitHub Labels
func (*Datasource) HandleMilestonesQuery ¶
func (d *Datasource) HandleMilestonesQuery(ctx context.Context, query *models.MilestonesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleMilestonesQuery is the query handler for listing GitHub Milestones
func (*Datasource) HandlePackagesQuery ¶
func (d *Datasource) HandlePackagesQuery(ctx context.Context, query *models.PackagesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandlePackagesQuery is the query handler for listing GitHub Packages
func (*Datasource) HandlePullRequestsQuery ¶
func (d *Datasource) HandlePullRequestsQuery(ctx context.Context, query *models.PullRequestsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandlePullRequestsQuery is the query handler for listing GitHub PullRequests
func (*Datasource) HandleReleasesQuery ¶
func (d *Datasource) HandleReleasesQuery(ctx context.Context, query *models.ReleasesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleReleasesQuery is the query handler for listing GitHub Releases
func (*Datasource) HandleRepositoriesQuery ¶ added in v1.0.1
func (d *Datasource) HandleRepositoriesQuery(ctx context.Context, query *models.RepositoriesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleRepositoriesQuery is the query handler for listing GitHub Repositories
type Issue ¶
type Issue struct {
Title string
ClosedAt githubv4.DateTime
CreatedAt githubv4.DateTime
Closed bool
Author struct {
User `graphql:"... on User"`
}
}
Issue represents a GitHub issue in a repository
type Issues ¶
type Issues []Issue
Issues is a slice of GitHub issues
type Label ¶
type Label struct {
Color string `json:"color"`
Name string `json:"name"`
Description string `json:"description"`
}
Label is a GitHub label used in Issues / Pull Requests
type Labels ¶
type Labels []Label
Labels is a list of GitHub labels
func GetAllLabels ¶
func GetAllLabels(ctx context.Context, client Client, opts models.ListLabelsOptions) (Labels, error)
GetAllLabels gets all labels from a GitHub repository
type Milestone ¶
type Milestone struct {
Closed bool
Creator struct {
User User `graphql:"... on User"`
}
DueOn githubv4.DateTime
ClosedAt githubv4.DateTime
CreatedAt githubv4.DateTime
State githubv4.MilestoneState
Title string
}
Milestone is a GitHub Milestone
type Milestones ¶
type Milestones []Milestone
Milestones is a list of GitHub milestones
func GetAllMilestones ¶
func GetAllMilestones(ctx context.Context, client Client, opts models.ListMilestonesOptions) (Milestones, error)
GetAllMilestones lists milestones in a repository
func (Milestones) Frames ¶
func (m Milestones) Frames() data.Frames
Frames converts the list of GitHub Milestones to a Grafana data frame
type Organization ¶
type Organization struct {
Name string
}
An Organization is a single GitHub organization
func GetAllOrganizations ¶
func GetAllOrganizations(ctx context.Context, client Client) ([]Organization, error)
GetAllOrganizations lists the available organizations for the client
type Organizations ¶
type Organizations []Organization
Organizations is a slice of GitHub Organizations
func (Organizations) Frames ¶
func (c Organizations) Frames() data.Frames
Frames converts the list of Organizations to a Grafana DataFrame
type Package ¶
type Package struct {
Name string
PackageType githubv4.PackageType
Statistics PackageStatistics
Versions []PackageVersion
}
Package represents a GitHub Package
type PackageStatistics ¶
type PackageStatistics struct {
DownloadsTotalCount int64
}
PackageStatistics is a common object used in package versions and packages themselves
type PackageVersion ¶
type PackageVersion struct {
PreRelease bool
Platform string
Version string
Statistics PackageStatistics
}
PackageVersion is the version of a package. A package can have several versions.
type Packages ¶
type Packages []Package
Packages is a list of GitHub packages
func GetAllPackages ¶
func GetAllPackages(ctx context.Context, client Client, opts models.ListPackagesOptions) (Packages, error)
GetAllPackages lists packages in a repository
type PullRequest ¶
type PullRequest struct {
Number int64
Title string
URL string
State githubv4.PullRequestState
Author PullRequestAuthor
Closed bool
IsDraft bool
Locked bool
Merged bool
ClosedAt githubv4.DateTime
CreatedAt githubv4.DateTime
UpdatedAt githubv4.DateTime
MergedAt githubv4.DateTime
Mergeable githubv4.MergeableState
MergedBy *PullRequestAuthor
Repository Repository
}
PullRequest is a GitHub pull request
type PullRequestAuthor ¶
type PullRequestAuthor struct {
User User `graphql:"... on User"`
}
PullRequestAuthor is the structure of the Author object in a Pull Request (which requires a grapql object expansion on `User`)
type PullRequests ¶
type PullRequests []PullRequest
PullRequests is a list of GitHub Pull Requests
func GetAllPullRequests ¶
func GetAllPullRequests(ctx context.Context, client Client, opts models.ListPullRequestsOptions) (PullRequests, error)
GetAllPullRequests uses the graphql search endpoint API to search all pull requests in the repository
func GetPullRequestsInRange ¶
func GetPullRequestsInRange(ctx context.Context, client Client, opts models.ListPullRequestsOptions, from time.Time, to time.Time) (PullRequests, error)
GetPullRequestsInRange uses the graphql search endpoint API to find pull requests in the given time range.
func (PullRequests) Frames ¶
func (p PullRequests) Frames() data.Frames
Frames converts the list of Pull Requests to a Grafana DataFrame
type QueryListCommits ¶
type QueryListCommits struct {
Repository struct {
Object struct {
Commit struct {
History struct {
Nodes []Commit
PageInfo PageInfo
} `graphql:"history(first: 100, after: $cursor)"`
} `graphql:"... on Commit"`
} `graphql:"object(expression: $ref)"`
} `graphql:"repository(name: $name, owner: $owner)"`
}
QueryListCommits is the object representation of the graphql query for retrieving a paginated list of commits for a project
query {
repository(name:"$name", owner:"$owner") {
object(expression: "master") {
... on Commit {
history {
nodes {
committedDate
}
pageInfo{
hasNextPage
hasPreviousPage
}
}
}
}
}
}
type QueryListCommitsInRange ¶
type QueryListCommitsInRange struct {
Repository struct {
Object struct {
Commit struct {
History struct {
Nodes []Commit
PageInfo PageInfo
} `graphql:"history(first: 100, after: $cursor, since: $since, until: $until)"`
} `graphql:"... on Commit"`
} `graphql:"object(expression: $ref)"`
} `graphql:"repository(name: $name, owner: $owner)"`
}
QueryListCommitsInRange is the graphql query for retrieving a paginated list of commits within a time range
type QueryListContributors ¶
type QueryListContributors struct {
Repository struct {
Users struct {
Nodes Users
PageInfo PageInfo
} `graphql:"mentionableUsers(query: $query, first: 100, after: $cursor)"`
} `graphql:"repository(name: $name, owner: $owner)"`
}
QueryListContributors is the GraphQL query for lising contributors (or rather, mentionable users in a repository)
type QueryListLabels ¶
type QueryListLabels struct {
Repository struct {
Labels struct {
Nodes Labels
PageInfo PageInfo
} `graphql:"labels(first: 100, after: $cursor, query: $query)"`
} `graphql:"repository(name: $name, owner: $owner)"`
}
QueryListLabels lists all labels in a repository
{
repository(name: "grafana", owner: "grafana") {
labels(first: 100) {
nodes {
color
description
name
}
}
}
}
type QueryListMilestones ¶
type QueryListMilestones struct {
Repository struct {
Milestones struct {
Nodes Milestones
PageInfo PageInfo
} `graphql:"milestones(first: 100, after: $cursor, query: $query)"`
} `graphql:"repository(name: $name, owner: $owner)"`
}
QueryListMilestones lists all milestones in a repository
{
repository(name: "grafana", owner: "grafana") {
milestones(first: 100) {
nodes {
color
description
name
}
}
}
}
type QueryListOrganizations ¶
type QueryListOrganizations struct {
Viewer struct {
Organizations struct {
Nodes []Organization
PageInfo PageInfo
} `graphql:"organizations(first: 100, after: $cursor)"`
}
}
QueryListOrganizations is the GraphQL query for listing organizations
type QueryListPackages ¶
type QueryListPackages struct {
Repository struct {
Packages struct {
Nodes []struct {
Name string
PackageType githubv4.PackageType
Statistics PackageStatistics
Versions struct {
Nodes []PackageVersion
PageInfo PageInfo
} `graphql:"versions(first: 100, after: $versionsCursor)"`
}
PageInfo PageInfo
} `graphql:"packages(names: $names, packageType: $packageType, first: 100, after: $cursor)"`
} `graphql:"repository(name: $name, owner: $owner)"`
}
QueryListPackages is the GraphQL query for listing GitHub packages
{
repository(name: "grafana", owner: "grafana") {
packages(names: "", packageType: "", first: 10) {
nodes {
id
name
packageType
statistics {
downloadsTotalCount
}
versions(first: 10) {
nodes {
preRelease
platform
version
statistics {
downloadsTotalCount
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
totalCount
pageInfo {
endCursor
hasNextPage
}
}
}
}
type QueryListPullRequests ¶
type QueryListPullRequests struct {
Search struct {
Nodes []struct {
PullRequest PullRequest `graphql:"... on PullRequest"`
}
PageInfo PageInfo
} `graphql:"search(query: $query, type: ISSUE, first: 100, after: $cursor)"`
}
QueryListPullRequests lists all pull requests in a repository
{
search(query: "is:pr repo:grafana/grafana merged:2020-08-19..*", type: ISSUE, first: 100) {
nodes {
... on PullRequest {
id
title
}
}
}
type QueryListReleases ¶
type QueryListReleases struct {
Repository struct {
Releases struct {
Nodes []Release
PageInfo PageInfo
} `graphql:"releases(first: 100, after: $cursor)"`
} `graphql:"repository(owner: $owner, name: $name)"`
}
QueryListReleases is the GraphQL query for listing GitHub releases in a repository
type QueryListRepositories ¶
type QueryListRepositories struct {
Search struct {
Nodes []struct {
Repository Repository `graphql:"... on Repository"`
}
PageInfo PageInfo
} `graphql:"search(query: $query, type: REPOSITORY, first: 100, after: $cursor)"`
}
QueryListRepositories is the GraphQL query for retrieving a list of repositories for an organization
{
search(query: "is:pr repo:grafana/grafana merged:2020-08-19..*", type: ISSUE, first: 100) {
nodes {
... on PullRequest {
id
title
}
}
}
type QueryListTags ¶
type QueryListTags struct {
Repository struct {
Refs struct {
Nodes []struct {
Target struct {
Tag Tag `graphql:"... on Tag"`
}
}
PageInfo PageInfo
} `graphql:"refs(refPrefix: \"refs/tags/\", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, first: 100, after: $cursor)"`
} `graphql:"repository(name: $name, owner: $owner)"`
}
QueryListTags is the GraphQL query for listing GitHub tags in a repository
repository(name: "grafana", owner: "grafana") {
refs(refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, first: 10, query: "") {
nodes {
target {
oid
... on Tag {
name
tagger {
date
}
target {
oid
... on Commit {
committedDate
pushedDate
}
}
}
}
}
}
}
}
type QuerySearchIssues ¶
type QuerySearchIssues struct {
Search struct {
Nodes []struct {
Issue Issue `graphql:"... on Issue"`
}
PageInfo PageInfo
} `graphql:"search(query: $query, type: ISSUE, first: 100, after: $cursor)"`
}
QuerySearchIssues is the object representation of the graphql query for retrieving a paginated list of issues using the search query
{
search(query: "is:issue repo:grafana/grafana opened:2020-08-19..*", type: ISSUE, first: 100) {
nodes {
... on PullRequest {
id
title
}
}
}
type Release ¶
type Release struct {
ID string
Name string
Author User
IsDraft bool
IsPrerelease bool
CreatedAt githubv4.DateTime
PublishedAt githubv4.DateTime
TagName string
URL string
}
Release is a GitHub release. Every release has an associated tag.
type Releases ¶
type Releases []Release
Releases is a slice of GitHub releases
func GetAllReleases ¶
func GetAllReleases(ctx context.Context, client Client, opts models.ListReleasesOptions) (Releases, error)
GetAllReleases retrieves every release from a repository
type Repositories ¶ added in v1.0.1
type Repositories []Repository
Repositories is a list of GitHub repositories
func GetAllRepositories ¶
func GetAllRepositories(ctx context.Context, client Client, opts models.ListRepositoriesOptions) (Repositories, error)
GetAllRepositories retrieves all available repositories for an organization
func (Repositories) Frames ¶ added in v1.0.1
func (r Repositories) Frames() data.Frames
Frames converts the list of GitHub repositories to a Grafana Dataframe
type Repository ¶
type Repository struct {
Name string
Owner struct {
Login string
}
NameWithOwner string
URL string
ForkCount int64
IsFork bool
IsMirror bool
IsPrivate bool
CreatedAt githubv4.DateTime
}
Repository is a code repository
type Tag ¶
type Tag struct {
Name string
Tagger struct {
Date githubv4.DateTime
User User
}
Target struct {
OID string
Commit Commit `graphql:"... on Commit"`
}
}
Tag is a GitHub tag. Every tag has an associated commit
type Tags ¶
type Tags []Tag
Tags is a list of GitHub tags
func GetAllTags ¶
GetAllTags retrieves every tag from a repository