github

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package github contains more usable functions and types for interacting with the Githubv4 API

Index

Constants

View Source
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.

func GetCommitsInRange

func GetCommitsInRange(ctx context.Context, client Client, opts models.ListCommitsOptions, from time.Time, to time.Time) (Commits, error)

GetCommitsInRange lists all commits in a repository within a time range.

func (Commits) Frames

func (c Commits) Frames() data.Frames

Frames converts the list of commits to a Grafana DataFrame

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

func (*Datasource) HandleTagsQuery

func (d *Datasource) HandleTagsQuery(ctx context.Context, query *models.TagsQuery, req backend.DataQuery) (dfutil.Framer, error)

HandleTagsQuery is the query handler for listing GitHub Tags

type GitActor

type GitActor struct {
	Name  string
	Email string
	User  User
}

A GitActor is a user that has performed a git action, like a commit

type GitActors

type GitActors []GitActor

GitActors is a list of GitHub users

func (GitActors) Frames

func (g GitActors) Frames() data.Frames

Frames converts the list of actors to a grafana data frame

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

func GetIssuesInRange

func GetIssuesInRange(ctx context.Context, client Client, opts models.ListIssuesOptions, from time.Time, to time.Time) (Issues, error)

GetIssuesInRange lists issues in a project given a time range.

func (Issues) Frames

func (c Issues) Frames() data.Frames

Frames converts the list of issues to a Grafana DataFrame

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

func (Labels) Frames

func (a Labels) Frames() data.Frames

Frames converts the list of labels to a Grafana DataFrame

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

func (Packages) Frames

func (p Packages) Frames() data.Frames

Frames converts a list of Packages to a Grafana Data Frame

type PageInfo

type PageInfo struct {
	StartCursor githubv4.String
	EndCursor   githubv4.String
	HasNextPage bool
}

PageInfo is a GitHub type used in paginated responses

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

func GetReleasesInRange

func GetReleasesInRange(ctx context.Context, client Client, opts models.ListReleasesOptions, from time.Time, to time.Time) (Releases, error)

GetReleasesInRange retrieves every release from the repository and then returns the ones that fall within the given time range.

func (Releases) Frames

func (c Releases) Frames() data.Frames

Frames converts the list of Releases to a Grafana DataFrame

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

func GetAllTags(ctx context.Context, client Client, opts models.ListTagsOptions) (Tags, error)

GetAllTags retrieves every tag from a repository

func GetTagsInRange

func GetTagsInRange(ctx context.Context, client Client, opts models.ListTagsOptions, from time.Time, to time.Time) (Tags, error)

GetTagsInRange retrieves every tag from the repository and then returns the ones that fall within the given time range.

func (Tags) Frames

func (t Tags) Frames() data.Frames

Frames converts the list of tags to a Grafana DataFrame

type User

type User struct {
	ID      string
	Login   string
	Name    string
	Company string
	Email   string
	URL     string
}

A User is a GitHub user

type Users

type Users []User

Users is a slice of GitHub users

func GetAllContributors

func GetAllContributors(ctx context.Context, client Client, opts models.ListContributorsOptions) (Users, error)

GetAllContributors lists all of the git contributors in a a repository

func (Users) Frames

func (u Users) Frames() data.Frames

Frames converts the list of GitHub users to a Grafana Data Frame

Jump to

Keyboard shortcuts

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