core

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: GPL-3.0 Imports: 13 Imported by: 3

Documentation

Overview

Package core contains the target-agnostic code to define and run a bridge

Index

Constants

View Source
const (
	ConfigKeyTarget = "target"

	MetaKeyOrigin = "origin"
)

Variables

View Source
var ErrExportNotSupported = errors.New("export is not supported")
View Source
var ErrImportNotSupported = errors.New("import is not supported")

Functions

func BridgeExist

func BridgeExist(repo repository.RepoConfig, name string) bool

Check if a bridge exist

func ConfiguredBridges

func ConfiguredBridges(repo repository.RepoConfig) ([]string, error)

ConfiguredBridges return the list of bridge that are configured for the given repo

func FinishConfig

func FinishConfig(repo *cache.RepoCache, metaKey string, login string) error

func LoginMetaKey

func LoginMetaKey(target string) (string, error)

LoginMetaKey return the metadata key used to store the remote bug-tracker login on the user identity. The corresponding value is used to match identities and credentials.

func Register

func Register(impl BridgeImpl)

Register will register a new BridgeImpl

func RemoveBridge

func RemoveBridge(repo repository.RepoConfig, name string) error

Remove a configured bridge

func TargetExist

func TargetExist(target string) bool

TargetExist return true if the given target has a bridge implementation

func Targets

func Targets() []string

Targets return all known bridge implementation target

Types

type Bridge

type Bridge struct {
	Name string
	// contains filtered or unexported fields
}

Bridge is a wrapper around a BridgeImpl that will bind low-level implementation with utility code to provide high-level functions.

func DefaultBridge

func DefaultBridge(repo *cache.RepoCache) (*Bridge, error)

Attempt to retrieve a default bridge for the given repo. If zero or multiple bridge exist, it fails.

func LoadBridge

func LoadBridge(repo *cache.RepoCache, name string) (*Bridge, error)

LoadBridge instantiate a new bridge from a repo configuration

func NewBridge

func NewBridge(repo *cache.RepoCache, target string, name string) (*Bridge, error)

Instantiate a new Bridge for a repo, from the given target and name

func (*Bridge) Configure

func (b *Bridge) Configure(params BridgeParams, interactive bool) error

Configure run the target specific configuration process

func (*Bridge) ExportAll

func (b *Bridge) ExportAll(ctx context.Context, since time.Time) (<-chan ExportResult, error)

func (*Bridge) ImportAll

func (b *Bridge) ImportAll(ctx context.Context) (<-chan ImportResult, error)

func (*Bridge) ImportAllSince

func (b *Bridge) ImportAllSince(ctx context.Context, since time.Time) (<-chan ImportResult, error)

type BridgeImpl

type BridgeImpl interface {
	// Target return the target of the bridge (e.g.: "github")
	Target() string

	// NewImporter return an Importer implementation if the import is supported
	NewImporter() Importer

	// NewExporter return an Exporter implementation if the export is supported
	NewExporter() Exporter

	// Configure handle the user interaction and return a key/value configuration
	// for future use.
	Configure(repo *cache.RepoCache, params BridgeParams, interactive bool) (Configuration, error)

	// The set of the BridgeParams fields supported
	ValidParams() map[string]interface{}

	// ValidateConfig check the configuration for error
	ValidateConfig(conf Configuration) error

	// LoginMetaKey return the metadata key used to store the remote bug-tracker login
	// on the user identity. The corresponding value is used to match identities and
	// credentials.
	LoginMetaKey() string
}

type BridgeParams

type BridgeParams struct {
	URL        string // complete URL of a repo               (Github, Gitlab,     , Launchpad)
	BaseURL    string // base URL for self-hosted instance    (        Gitlab, Jira,          )
	Login      string // username for the passed credential   (Github, Gitlab, Jira,          )
	CredPrefix string // ID prefix of the credential to use   (Github, Gitlab, Jira,          )
	TokenRaw   string // pre-existing token to use            (Github, Gitlab,     ,          )
	Owner      string // owner of the repo                    (Github,       ,     ,          )
	Project    string // name of the repo or project key      (Github,       , Jira, Launchpad)
}

BridgeParams holds parameters to simplify the bridge configuration without having to make terminal prompts.

type Configuration

type Configuration map[string]string

type ExportEvent

type ExportEvent int
const (

	// Bug has been exported on the remote tracker
	ExportEventBug ExportEvent
	// Comment has been exported on the remote tracker
	ExportEventComment
	// Comment has been edited on the remote tracker
	ExportEventCommentEdition
	// Bug's status has been changed on on the remote tracker
	ExportEventStatusChange
	// Bug's title has been changed on the remote tracker
	ExportEventTitleEdition
	// Bug's labels have been changed on the remote tracker
	ExportEventLabelChange

	// Nothing changed on the bug
	ExportEventNothing

	// Something wrong happened during export that is worth notifying to the user
	// but not severe enough to consider the export a failure.
	ExportEventWarning

	// The export system (web API) has reached a rate limit
	ExportEventRateLimiting

	// Error happened during export
	ExportEventError
)

type ExportResult

type ExportResult struct {
	Err      error
	Event    ExportEvent
	EntityId entity.Id // optional for err, warning
	Reason   string
}

ExportResult is an event that is emitted during the export process, to allow calling code to report on what is happening, collect metrics or display meaningful errors if something went wrong.

func NewExportBug

func NewExportBug(entityId entity.Id) ExportResult

func NewExportComment

func NewExportComment(entityId entity.Id) ExportResult

func NewExportCommentEdition

func NewExportCommentEdition(entityId entity.Id) ExportResult

func NewExportError

func NewExportError(err error, entityId entity.Id) ExportResult

func NewExportLabelChange

func NewExportLabelChange(entityId entity.Id) ExportResult

func NewExportNothing

func NewExportNothing(entityId entity.Id, reason string) ExportResult

func NewExportRateLimiting added in v0.8.0

func NewExportRateLimiting(msg string) ExportResult

func NewExportStatusChange

func NewExportStatusChange(entityId entity.Id) ExportResult

func NewExportTitleEdition

func NewExportTitleEdition(entityId entity.Id) ExportResult

func NewExportWarning

func NewExportWarning(err error, entityId entity.Id) ExportResult

func (ExportResult) String

func (er ExportResult) String() string

type Exporter

type Exporter interface {
	Init(ctx context.Context, repo *cache.RepoCache, conf Configuration) error
	ExportAll(ctx context.Context, repo *cache.RepoCache, since time.Time) (<-chan ExportResult, error)
}

type ImportEvent

type ImportEvent int
const (

	// Bug has been created
	ImportEventBug ImportEvent
	// Comment has been created
	ImportEventComment
	// Comment has been edited
	ImportEventCommentEdition
	// Bug's status has changed
	ImportEventStatusChange
	// Bug's title has changed
	ImportEventTitleEdition
	// Bug's labels changed
	ImportEventLabelChange
	// Nothing happened on a Bug
	ImportEventNothing

	// Identity has been created
	ImportEventIdentity

	// Something wrong happened during import that is worth notifying to the user
	// but not severe enough to consider the import a failure.
	ImportEventWarning

	// The import system (web API) has reached the rate limit
	ImportEventRateLimiting

	// Error happened during import
	ImportEventError
)

type ImportResult

type ImportResult struct {
	Err         error
	Event       ImportEvent
	EntityId    entity.Id         // optional for err, warnings
	OperationId entity.Id         // optional
	ComponentId entity.CombinedId // optional
	Reason      string
}

ImportResult is an event that is emitted during the import process, to allow calling code to report on what is happening, collect metrics or display meaningful errors if something went wrong.

func NewImportBug

func NewImportBug(entityId entity.Id) ImportResult

func NewImportComment

func NewImportComment(entityId entity.Id, commentId entity.CombinedId) ImportResult

func NewImportCommentEdition

func NewImportCommentEdition(entityId entity.Id, commentId entity.CombinedId) ImportResult

func NewImportError

func NewImportError(err error, entityId entity.Id) ImportResult

func NewImportIdentity

func NewImportIdentity(entityId entity.Id) ImportResult

func NewImportLabelChange

func NewImportLabelChange(entityId entity.Id, opId entity.Id) ImportResult

func NewImportNothing

func NewImportNothing(entityId entity.Id, reason string) ImportResult

func NewImportRateLimiting added in v0.8.0

func NewImportRateLimiting(msg string) ImportResult

func NewImportStatusChange

func NewImportStatusChange(entityId entity.Id, opId entity.Id) ImportResult

func NewImportTitleEdition

func NewImportTitleEdition(entityId entity.Id, opId entity.Id) ImportResult

func NewImportWarning

func NewImportWarning(err error, entityId entity.Id) ImportResult

func (ImportResult) String

func (er ImportResult) String() string

type Importer

type Importer interface {
	Init(ctx context.Context, repo *cache.RepoCache, conf Configuration) error
	ImportAll(ctx context.Context, repo *cache.RepoCache, since time.Time) (<-chan ImportResult, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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