Documentation
¶
Index ¶
- func HasURLPrefix(path, pathPrefix string) bool
- func NewResourceHandler(client *github.Client, acceptedHosts []string) resourcehandlers.ResourceHandler
- type Cache
- type GitHub
- func (gh *GitHub) Accept(uri string) bool
- func (gh *GitHub) BuildAbsLink(source, relPath string) (string, error)
- func (gh *GitHub) GetLocalityDomainCandidate(source string) (key, path, version string, err error)
- func (gh *GitHub) Name(uri string) string
- func (gh *GitHub) Read(ctx context.Context, uri string) ([]byte, error)
- func (gh *GitHub) ResolveNodeSelector(ctx context.Context, node *api.Node) error
- func (gh *GitHub) SetVersion(absLink, version string) (string, error)
- func (gh *GitHub) URLToGitHubLocator(ctx context.Context, urlString string, resolveAPIUrl bool) (*ResourceLocator, error)
- type ResourceLocator
- type ResourceType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasURLPrefix ¶
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 efficently 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 ¶
GitHub implements resourcehanlders#ResourceHandler
func (*GitHub) BuildAbsLink ¶
BuildAbsLink builds the abs link from the source and the relative path
func (*GitHub) GetLocalityDomainCandidate ¶
GetLocalityDomainCandidate returns the provided source as locality domain candidate parameters suitable for quering reactor/LocalityDomain#PathInLocality
func (*GitHub) ResolveNodeSelector ¶
ResolveNodeSelector recursively adds nodes built from tree entries to node
func (*GitHub) SetVersion ¶
SetVersion replaces the version segment in the path of GitHub URLs if applicable or returns the original URL unchanged if not.
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 omited too.
type ResourceLocator ¶
type ResourceLocator struct {
Host string
Owner string
Repo string
SHA string
Type ResourceType
Path string
// branch name (master), tag (v1.2.3), commit hash (1j4h4jh...)
SHAAlias string
}
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) 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 rеsource in the documentatiоn 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" and "blob"
const ( // Tree is GitHub tree objects resource type Tree ResourceType = iota // Blob is GitHub blob objects resource type Blob )
func NewResourceType ¶
func NewResourceType(resourceTypeString string) (ResourceType, error)
NewResourceType creates a ResourceType enum from string
func (ResourceType) String ¶
func (s ResourceType) String() string