remoteworkitem

package
v42.0.0-...-56f38d9 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2017 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package remoteworkitem contains all the code that tracks the work items created in remote systems such as jira, github.

Index

Constants

View Source
const (
	ProviderGithub = "github"
	ProviderJira   = "jira"

	// The keys in the flattened response JSON of a typical Github issue.
	GithubTitle                      = "title"
	GithubDescription                = "body"
	GithubState                      = "state"
	GithubID                         = "url"
	GithubCreatorLogin               = "user.login"
	GithubCreatorProfileURL          = "user.url"
	GithubAssigneesLogin             = "assignees.0.login"
	GithubAssigneesLoginPattern      = "assignees.?.login"
	GithubAssigneesProfileURL        = "assignees.0.url"
	GithubAssigneesProfileURLPattern = "assignees.?.url"

	// The keys in the flattened response JSON of a typical Jira issue.
	JiraTitle              = "fields.summary"
	JiraBody               = "fields.description"
	JiraState              = "fields.status.name"
	JiraID                 = "self"
	JiraCreatorLogin       = "fields.creator.key"
	JiraCreatorProfileURL  = "fields.creator.self"
	JiraAssigneeLogin      = "fields.assignee.key"
	JiraAssigneeProfileURL = "fields.assignee.self"
)

List of supported attributes

Variables

RemoteWorkItemImplRegistry contains all possible providers

View Source
var RemoteWorkItemKeyMaps = map[string]RemoteWorkItemMap{
	ProviderGithub: {
		AttributeMapper{AttributeExpression(GithubTitle), StringConverter{}}:                                                               remoteTitle,
		AttributeMapper{AttributeExpression(GithubDescription), MarkupConverter{markup: rendering.SystemMarkupMarkdown}}:                   remoteDescription,
		AttributeMapper{AttributeExpression(GithubState), GithubStateConverter{}}:                                                          remoteState,
		AttributeMapper{AttributeExpression(GithubID), StringConverter{}}:                                                                  remoteItemID,
		AttributeMapper{AttributeExpression(GithubCreatorLogin), StringConverter{}}:                                                        remoteCreatorLogin,
		AttributeMapper{AttributeExpression(GithubCreatorProfileURL), StringConverter{}}:                                                   remoteCreatorProfileURL,
		AttributeMapper{AttributeExpression(GithubAssigneesLogin), PatternToListConverter{pattern: GithubAssigneesLoginPattern}}:           remoteAssigneeLogins,
		AttributeMapper{AttributeExpression(GithubAssigneesProfileURL), PatternToListConverter{pattern: GithubAssigneesProfileURLPattern}}: remoteAssigneeProfileURLs,
	},
	ProviderJira: {
		AttributeMapper{AttributeExpression(JiraTitle), StringConverter{}}:                                      remoteTitle,
		AttributeMapper{AttributeExpression(JiraBody), MarkupConverter{markup: rendering.SystemMarkupJiraWiki}}: remoteDescription,
		AttributeMapper{AttributeExpression(JiraState), JiraStateConverter{}}:                                   remoteState,
		AttributeMapper{AttributeExpression(JiraID), StringConverter{}}:                                         remoteItemID,
		AttributeMapper{AttributeExpression(JiraCreatorLogin), StringConverter{}}:                               remoteCreatorLogin,
		AttributeMapper{AttributeExpression(JiraCreatorProfileURL), StringConverter{}}:                          remoteCreatorProfileURL,
		AttributeMapper{AttributeExpression(JiraAssigneeLogin), ListConverter{}}:                                remoteAssigneeLogins,
		AttributeMapper{AttributeExpression(JiraAssigneeProfileURL), ListConverter{}}:                           remoteAssigneeProfileURLs,
	},
}

RemoteWorkItemKeyMaps relate remote attribute keys to internal representation

Functions

func Flatten

func Flatten(source map[string]interface{}) map[string]interface{}

Flatten Takes the nested map and returns a non nested one with dot delimited keys

Types

type AttributeAccessor

type AttributeAccessor interface {
	// Get returns the value based on a commonly understood attribute expression
	Get(field AttributeExpression) interface{}
}

AttributeAccessor defines the interface between a RemoteWorkItem and the Mapper

func NewGitHubRemoteWorkItem

func NewGitHubRemoteWorkItem(item TrackerItem) (AttributeAccessor, error)

NewGitHubRemoteWorkItem creates a new Decoded AttributeAccessor for a GitHub Issue

func NewJiraRemoteWorkItem

func NewJiraRemoteWorkItem(item TrackerItem) (AttributeAccessor, error)

NewJiraRemoteWorkItem creates a new Decoded AttributeAccessor for a GitHub Issue

type AttributeConverter

type AttributeConverter interface {
	Convert(interface{}, AttributeAccessor) (interface{}, error)
}

type AttributeExpression

type AttributeExpression string

AttributeExpression represents a commonly understood String format for a target path

type AttributeMapper

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

type BadParameterError

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

BadParameterError means that a parameter was not as required

func (BadParameterError) Error

func (err BadParameterError) Error() string

Error implements the error interface

type ConversionError

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

ConversionError error means something went wrong converting between different representations

func (ConversionError) Error

func (err ConversionError) Error() string

type GitHubRemoteWorkItem

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

GitHubRemoteWorkItem knows how to implement a FieldAccessor on a GitHub Issue JSON struct and it should also know how to convert a value in remote work item for use in local WI

func (GitHubRemoteWorkItem) Get

func (gh GitHubRemoteWorkItem) Get(field AttributeExpression) interface{}

Get attribute from issue map

type GithubStateConverter

type GithubStateConverter struct{}

func (GithubStateConverter) Convert

func (ghc GithubStateConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error)

type GithubTracker

type GithubTracker struct {
	URL   string
	Query string
}

GithubTracker represents the Github tracker provider

func (*GithubTracker) Fetch

func (g *GithubTracker) Fetch(githubAuthToken string) chan TrackerItemContent

Fetch tracker items from Github

type GormTrackerQueryRepository

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

GormTrackerQueryRepository implements TrackerRepository using gorm

func NewTrackerQueryRepository

func NewTrackerQueryRepository(db *gorm.DB) *GormTrackerQueryRepository

NewTrackerQueryRepository constructs a TrackerQueryRepository

func (*GormTrackerQueryRepository) CheckExists

func (r *GormTrackerQueryRepository) CheckExists(ctx context.Context, id string) error

CheckExists returns nil if the given ID exists otherwise returns an error

func (*GormTrackerQueryRepository) Create

func (r *GormTrackerQueryRepository) Create(ctx context.Context, query string, schedule string, tracker string, spaceID uuid.UUID) (*app.TrackerQuery, error)

Create creates a new tracker query in the repository returns BadParameterError, ConversionError or InternalError

func (*GormTrackerQueryRepository) Delete

Delete deletes the tracker query with the given id returns NotFoundError or InternalError

func (*GormTrackerQueryRepository) List

List returns tracker query selected by the given criteria.Expression, starting with start (zero-based) and returning at most limit items

func (*GormTrackerQueryRepository) Load

Load returns the tracker query for the given id returns NotFoundError, ConversionError or InternalError

func (*GormTrackerQueryRepository) Save

Save updates the given tracker query in storage. returns NotFoundError, ConversionError or InternalError

type GormTrackerRepository

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

GormTrackerRepository implements TrackerRepository using gorm

func NewTrackerRepository

func NewTrackerRepository(db *gorm.DB) *GormTrackerRepository

NewTrackerRepository constructs a TrackerRepository

func (*GormTrackerRepository) CheckExists

func (r *GormTrackerRepository) CheckExists(ctx context.Context, id string) error

CheckExists returns nil if the given ID exists otherwise returns an error

func (*GormTrackerRepository) Create

func (r *GormTrackerRepository) Create(ctx context.Context, url string, typeID string) (*app.Tracker, error)

Create creates a new tracker configuration in the repository returns BadParameterError, ConversionError or InternalError

func (*GormTrackerRepository) Delete

func (r *GormTrackerRepository) Delete(ctx context.Context, ID string) error

Delete deletes the tracker with the given id returns NotFoundError or InternalError

func (*GormTrackerRepository) List

func (r *GormTrackerRepository) List(ctx context.Context, criteria criteria.Expression, start *int, limit *int) ([]*app.Tracker, error)

List returns tracker selected by the given criteria.Expression, starting with start (zero-based) and returning at most limit items

func (*GormTrackerRepository) Load

Load returns the tracker configuration for the given id returns NotFoundError, ConversionError or InternalError

func (*GormTrackerRepository) Save

Save updates the given tracker in storage. returns NotFoundError, ConversionError or InternalError

type InternalError

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

InternalError means that the operation failed for some internal, unexpected reason

func (InternalError) Error

func (err InternalError) Error() string

type JiraRemoteWorkItem

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

JiraRemoteWorkItem knows how to implement a FieldAccessor on a Jira Issue JSON struct

func (JiraRemoteWorkItem) Get

func (jira JiraRemoteWorkItem) Get(field AttributeExpression) interface{}

Get attribute from issue map

type JiraStateConverter

type JiraStateConverter struct{}

func (JiraStateConverter) Convert

func (jhc JiraStateConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error)

type JiraTracker

type JiraTracker struct {
	URL   string
	Query string
}

JiraTracker represents the Jira tracker provider

func (*JiraTracker) Fetch

func (j *JiraTracker) Fetch(authToken string) chan TrackerItemContent

Fetch collects data from Jira

type ListConverter

type ListConverter struct{}

ListConverter converts a value into a list containing a single element

func (ListConverter) Convert

func (converter ListConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error)

Convert converts the given value to a list containing this single value as string

type ListStringConverter

type ListStringConverter struct{}

func (ListStringConverter) Convert

func (sc ListStringConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error)

Convert method map the external tracker item to WIT WorkItem

type MarkupConverter

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

MarkupConverter converts to a 'MarkupContent' element with the given 'Markup' value

func (MarkupConverter) Convert

func (converter MarkupConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error)

Convert returns the given `value` if the `item` is not nil`, otherwise returns `nil`

type NotFoundError

type NotFoundError struct {
	ID string
	// contains filtered or unexported fields
}

NotFoundError means the object specified for the operation does not exist

func (NotFoundError) Error

func (err NotFoundError) Error() string

type PatternToListConverter

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

PatternToListConverter joins multiple elements matching a regular expression into a single array

func (PatternToListConverter) Convert

func (converter PatternToListConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error)

Convert converts all fields from the given item that match this RegexpConverter's pattern, and returns an array of matching values as string

type RemoteWorkItem

type RemoteWorkItem struct {
	// The field values, according to the field type
	Fields map[string]interface{}
	// unique id per installation
	ID uuid.UUID
	// Name of the type of this work item
	Type uuid.UUID `sql:"type:uuid"`
}

RemoteWorkItem a temporary structure that holds the relevant field values retrieved from a remote work item

func Map

func Map(remoteItem AttributeAccessor, mapping RemoteWorkItemMap) (RemoteWorkItem, error)

Map maps the remote WorkItem to a local RemoteWorkItem

type RemoteWorkItemMap

type RemoteWorkItemMap map[AttributeMapper]string

RemoteWorkItemMap will define mappings between remote<->internal attribute

type Scheduler

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

Scheduler represents scheduler

func NewScheduler

func NewScheduler(db *gorm.DB) *Scheduler

NewScheduler creates a new Scheduler

func (*Scheduler) ScheduleAllQueries

func (s *Scheduler) ScheduleAllQueries(ctx context.Context, accessTokens map[string]string)

ScheduleAllQueries fetch and import of remote tracker items

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop scheduler This should be called only from main

type StateConverter

type StateConverter interface{}

StateConverter converts a remote work item state

type StringConverter

type StringConverter struct{}

StringConverter converts a value to a string

func (StringConverter) Convert

func (converter StringConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error)

Convert converts the given value to a string

type Tracker

type Tracker struct {
	gormsupport.Lifecycle
	ID uint64 `gorm:"primary_key"`
	// URL of the tracker
	URL string
	// Type of the tracker (jira, github, bugzilla, trello etc.)
	Type string
}

Tracker represents tracker configuration

type TrackerItem

type TrackerItem struct {
	gormsupport.Lifecycle
	ID uint64 `gorm:"primary_key"`
	// Remote item ID - unique across multiple trackers
	RemoteItemID string `gorm:"not null;unique"`
	// the field values
	Item string
	// FK to tracker
	TrackerID uint64 `gorm:"ForeignKey:Tracker"`
}

TrackerItem represents a remote tracker item Staging area before pushing to work item

type TrackerItemContent

type TrackerItemContent struct {
	ID      string
	Content []byte
}

TrackerItemContent represents a remote tracker item with it's content and unique ID

type TrackerProvider

type TrackerProvider interface {
	Fetch(authToken string) chan TrackerItemContent // TODO: Change to an interface to enforce the contract
}

TrackerProvider represents a remote tracker

type TrackerQuery

type TrackerQuery struct {
	gormsupport.Lifecycle
	ID uint64 `gorm:"primary_key"`
	// Search query of the tracker
	Query string
	// Schedule to fetch and import remote tracker items
	Schedule string
	// TrackerID is a foreign key for a tracker
	TrackerID uint64 `gorm:"ForeignKey:Tracker"`
	// SpaceID is a foreign key for a space
	SpaceID uuid.UUID `gorm:"ForeignKey:Space"`
}

TrackerQuery represents tracker query

type VersionConflictError

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

VersionConflictError means that the version was not as expected in an update operation

func (VersionConflictError) Error

func (err VersionConflictError) Error() string

Jump to

Keyboard shortcuts

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