github

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 20 Imported by: 1

README

Github installer for Plugin Registry

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

An installer for plugin-registry

Prerequisites

  • Go >= 1.15

Install

go get github.com/nhatthm/plugin-registry-github

Usage

Import the library while bootstrapping the application (see the examples)

The installer supports this source format: [https?://]github.com/owner/repository[@version]. For examples:

  • https://github.com/owner/repository
  • github.com/owner/repository@latest
  • github.com/owner/repository@v1.4.2

In the root folder of the repository, there must be a .plugin.registry.yaml file that describe the plugin. For example: https://github.com/nhatthm/moneylovercli-plugin-n26/blob/master/.plugin.registry.yaml

Examples

package mypackage

import (
	"context"

	registry "github.com/nhatthm/plugin-registry"
	_ "github.com/nhatthm/plugin-registry-github" // Add file system installer.
)

var defaultRegistry = mustCreateRegistry()

func mustCreateRegistry() registry.Registry {
	r, err := createRegistry()
	if err != nil {
		panic(err)
	}

	return r
}

func createRegistry() (registry.Registry, error) {
	return registry.NewRegistry("~/plugins")
}

func installPlugin(url string) error {
	return defaultRegistry.Install(context.Background(), url)
}

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this

Documentation

Overview

Package github provides Installer plugin installer.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotGithub indicates the url is not github.
	ErrNotGithub = errors.New("not a github url")
	// ErrMissingOwner indicates that there is no owner in the url.
	ErrMissingOwner = errors.New("missing github owner")
	// ErrMissingRepository indicates that there is no repository in the url.
	ErrMissingRepository = errors.New("missing github repository")
)
View Source
var ErrArtifactNotFound = errors.New("artifact not found")

ErrArtifactNotFound indicates that the artifact is not found.

Functions

This section is empty.

Types

type Installer

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

Installer installs plugin from github.

func NewInstaller

func NewInstaller(fs afero.Fs, options ...Option) *Installer

NewInstaller initiates a new github installer.

func (*Installer) Install

func (i *Installer) Install(ctx context.Context, dest, source string) (*plugin.Plugin, error)

Install installs the plugin. The installer will download the archive or binary from github, then uses the filesystem installers to install the plugin.

func (*Installer) WithService

func (i *Installer) WithService(service RepositoryService) *Installer

WithService sets the repository service.

type Option

type Option func(i *Installer)

Option is option to configure Installer.

func WithBaseURL

func WithBaseURL(url *url.URL) Option

WithBaseURL sets the base url for github client.

func WithService

func WithService(service RepositoryService) Option

WithService sets the repository service.

type RepositoryService

type RepositoryService interface {
	DownloadContents(ctx context.Context, owner, repo, filepath string, opts *github.RepositoryContentGetOptions) (io.ReadCloser, *github.Response, error)
	GetLatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, *github.Response, error)
	GetReleaseByTag(ctx context.Context, owner, repo, tag string) (*github.RepositoryRelease, *github.Response, error)
	DownloadReleaseAsset(ctx context.Context, owner, repo string, id int64, followRedirectsClient *http.Client) (rc io.ReadCloser, redirectURL string, err error)
}

RepositoryService is a wrapper around *github.RepositoryService.

Directories

Path Synopsis
mock
service
Package service provides mock functionalities for github service.
Package service provides mock functionalities for github service.

Jump to

Keyboard shortcuts

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