githubinfocard

package module
v0.0.0-...-aa5e5c2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2019 License: Unlicense Imports: 7 Imported by: 0

README

github-infocard

Experimental Go library which fetches summaries of GitHub repositories

Godoc Build Status Go Report Card

CLI example

Idea

I wanted to create an element on my blog, which displays a summary for a given GitHub repository. It could show visitors information like:

  • the repository owners name
  • amount of stars, forks and open issues
  • date of last commit
  • maybe even the language details (the narrow colored bar above the branch button)

Searching for ways to fetch this kind of data I found the GitHub API and specificaly it's GraphQL API. As I never messed with GraphQL, I thought that this is the perfect opportunity to learn some new things.

My current idea is to develop a library that helps fetching the data.
As an example and testing application, I want to add a CLI client, which just shows the desired data in an extraordinarily unspectacular manner.

GitHub API

You need a Personal access token for the API, which you can generate here (you need to be signed in first).

Usage

go get github.com/tsdtsdtsd/githubinfocard 

There is an example CLI client in example/cli/. It needs two things from you:

  • Environment variable named GITHUB_TOKEN, containing your personal access token
  • Parameter --url to indicate a repository

The following commands assume that you are in $GO_PATH/github.com/tsdtsdtsd/githubinfocard:

Windows
cmd /V /C "set GITHUB_TOKEN=##TOKEN## && go run example\cli\cli.go --url https://github.com/torvalds/linux"
Linux
GITHUB_TOKEN=##TOKEN## bash -c 'go run example/cli/cli.go --url https://github.com/torvalds/linux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Forks       int
	LastRelease string
	Languages   []Language
	Name        string
	OpenIssues  int
	Owner       string
	URL         string
	Stars       int
}

Card defines a repository info card

func Load

func Load(url, token string) (*Card, int, error)

Load tries to load a Card for given repository URL

type Graph

type Graph struct {
	Repository struct {
		DatabaseID  githubv4.Int
		Name        githubv4.String
		Description githubv4.String
		URL         githubv4.URI
		Owner       struct {
			Name githubv4.String `graphql:"login"`
		}

		Issues struct {
			TotalCount githubv4.Int
		} `graphql:"issues(states:OPEN)"`

		Forks struct {
			TotalCount githubv4.Int
		}

		Stargazers struct {
			TotalCount githubv4.Int
		}

		CommitComments struct {
			Nodes []struct {
				PublishedAt githubv4.DateTime
			}
		} `graphql:"commitComments(last:1)"`

		Releases struct {
			Nodes []struct {
				Name        githubv4.String
				PublishedAt githubv4.DateTime
			}
		} `graphql:"releases(last:1)"`

		Languages struct {
			Nodes []struct {
				Name  githubv4.String
				Color githubv4.String
			}
		} `graphql:"languages(first:10)"`
	} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`

	RateLimit struct {
		Cost      githubv4.Int
		Limit     githubv4.Int
		Remaining githubv4.Int
		ResetAt   githubv4.DateTime
	}
}

Graph explains the GraphQL request & response

type Language

type Language struct {
	Name  string
	Color string
}

Language defines a single programming language

Directories

Path Synopsis
example
cli

Jump to

Keyboard shortcuts

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