github

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasURLPrefix

func HasURLPrefix(path, pathPrefix string) bool

HasURLPrefix returns true if pathPrefix tests true as prefix for path, either with tree or blob in its resource type segment The resource type in the URL prefix {tree|blob} changes according to the resource To keep the prefix valid it should alternate this path segment too.

func NewResourceHandler

func NewResourceHandler(client *github.Client, acceptedHosts []string) resourcehandlers.ResourceHandler

NewResourceHandler creates new GitHub ResourceHandler objects

Types

type Cache

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

Cache is indexes GitHub TreeEntries by website resource URLs as keys, mapping ResourceLocator objects to them. TODO: implement me efficiently and for parallel use

func (*Cache) Get

func (c *Cache) Get(path string) *ResourceLocator

Get returns a ResourceLocator object mapped to the path (URL)

func (*Cache) GetSubset

func (c *Cache) GetSubset(pathPrefix string) []*ResourceLocator

GetSubset returns a subset of the ResourceLocator objects mapped to keys with this pathPrefix

func (*Cache) Set

func (c *Cache) Set(path string, entry *ResourceLocator) *ResourceLocator

Set adds a mapping between a path (URL) and a ResourceLocator to the cache

type GitHub

type GitHub struct {
	Client *github.Client
	// contains filtered or unexported fields
}

GitHub implements resourcehandlers/ResourceHandler

func (*GitHub) Accept

func (gh *GitHub) Accept(uri string) bool

Accept implements resourcehandlers/ResourceHandler#Accept

func (gh *GitHub) BuildAbsLink(source, relPath string) (string, error)

BuildAbsLink builds the abs link from the source and the relative path Implements resourcehandlers/ResourceHandler#BuildAbsLink

func (gh *GitHub) GetRawFormatLink(absLink string) (string, error)

GetRawFormatLink implements ResourceHandler#GetRawFormatLink

func (*GitHub) Read

func (gh *GitHub) Read(ctx context.Context, uri string) ([]byte, error)

Read implements resourcehandlers/ResourceHandler#Read

func (*GitHub) ReadGitInfo added in v0.6.0

func (gh *GitHub) ReadGitInfo(ctx context.Context, uri string) ([]byte, error)

ReadGitInfo implements resourcehandlers/ResourceHandler#ReadGitInfo

func (*GitHub) ResolveNodeSelector

func (gh *GitHub) ResolveNodeSelector(ctx context.Context, node *api.Node, excludePaths []string, frontMatter map[string]interface{}, excludeFrontMatter map[string]interface{}, depth int32) error

ResolveNodeSelector recursively adds nodes built from tree entries to node ResolveNodeSelector implements resourcehandlers/ResourceHandler#ResolveNodeSelector

func (*GitHub) ResourceName added in v0.5.0

func (gh *GitHub) ResourceName(uri string) (string, string)

ResourceName implements resourcehandlers/ResourceHandler#ResourceName

func (*GitHub) SetVersion

func (gh *GitHub) SetVersion(absLink, version string) (string, error)

SetVersion replaces the version segment in the path of GitHub URLs if applicable or returns the original URL unchanged if not. Implements resourcehandlers/ResourceHandler#SetVersion

func (*GitHub) URLToGitHubLocator

func (gh *GitHub) URLToGitHubLocator(ctx context.Context, urlString string, resolveAPIUrl bool) (*ResourceLocator, error)

URLToGitHubLocator produces a ResourceLocator from a GitHub website URL. ResourceLocator is the internal format used to dereference GitHub website links from documentation structure specification and documents.

Examples: - https://github.com/gardener/gardener/tree/master/docs - https://github.com/gardener/gardener/blob/master/docs/README.md

If resolveAPIUrl is true, GitHub API will be queried to populate the API URL for that resource (its SHA cannot be inferred from the url). If it's false the APIUrl property will be nil. In this case ctx can be omitted too.

type ResourceLocator

type ResourceLocator struct {
	Scheme string
	Host   string
	Owner  string
	Repo   string
	SHA    string
	Type   ResourceType
	Path   string
	// branch name (master), tag (v1.2.3), commit hash (1j4h4jh...)
	SHAAlias string
	// IsRawAPI is used to determine if the located resource has to be transformed to
	// a url of type https://host/raw/example/example during .String()
	IsRawAPI bool
}

ResourceLocator is an abstraction for GitHub specific Universal Resource Locators (URLs) It is an internal structure breaking down the GitHub URLs into more segment types such as Repo, Owner or SHA. ResourceLocator is a common denominator used to translate between GitHub user-oriented urls and API urls

func TreeEntryToGitHubLocator

func TreeEntryToGitHubLocator(treeEntry *github.TreeEntry, shaAlias string) *ResourceLocator

TreeEntryToGitHubLocator creates a ResourceLocator from a github.TreeEntry and shaAlias. The shaAlias is the name of e.g. a branch or a tag that should resolve to this resource in the git database. It binds the formats of a GitHub website URLs to the GitHub API URLs.

Example tree entries:

{
	"path": "docs",
	"mode": "040000",
	"type": "tree",
	"sha": "5e11bda664b234920d85db5ca10055916c11e35d",
	"url": "https://api.github.com/repos/gardener/gardener/git/trees/5e11bda664b234920d85db5ca10055916c11e35d"
}

Example blob:

{
	"path": "docs/README.md",
	"mode": "100644",
	"type": "blob",
 "size": "6260"
	"sha": "91776959202ec10db883c5cfc05c51e78403f02c",
	"url": "https://api.github.com/repos/gardener/gardener/git/blobs/91776959202ec10db883c5cfc05c51e78403f02c"
}

func (*ResourceLocator) GetName

func (r *ResourceLocator) GetName() string

GetName returns the Name segment of a resource URL path

func (*ResourceLocator) GetRaw added in v0.4.0

func (r *ResourceLocator) GetRaw() string

GetRaw returns the raw content URL for this ResourceLocator if applicable. Only bloband raw resource locators qualify. An empty string is returned for all other resource type

func (*ResourceLocator) String

func (r *ResourceLocator) String() string

String produces a GitHub website link to a resource from a ResourceLocator. That's the format used to link а GitHub resource in the documentation structure and pages. Example: https://github.com/gardener/gardener/blob/master/docs/README.md

type ResourceType

type ResourceType int

ResourceType is an enumeration for GitHub resource types Supported types are "tree", "blob" and "wiki"

const (
	// Tree is GitHub tree objects resource type
	Tree ResourceType = iota
	// Blob is GitHub blob objects resource type
	Blob
	// Raw is GitHub raw resource type aw blob content
	Raw
	// Wiki is GitHub wiki resource type
	Wiki
	// Releases is GitHub releases resource type
	Releases
	// Issues is GitHub issues resource type
	Issues
	// Issue is GitHub issue resource type
	Issue
	// Pulls is GitHub pulls resource type
	Pulls
	// Pull is GitHub pull resource type
	Pull
)

func NewResourceType

func NewResourceType(resourceTypeString string) (ResourceType, error)

NewResourceType creates a ResourceType enum from string

func (ResourceType) String

func (s ResourceType) String() string

Jump to

Keyboard shortcuts

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