fabric8-wit: github.com/fabric8-services/fabric8-wit/remoteworkitem Index | Files

package remoteworkitem

import "github.com/fabric8-services/fabric8-wit/remoteworkitem"

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

Index

Package Files

doc.go errors.go flatten.go github.go jira.go remoteworkitem.go scheduler.go tracker.go tracker_repository.go trackeritem.go trackeritem_repository.go trackerquery.go trackerquery_repository.go

Constants

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

const (
    RemoteAssigneeLogins      = "system.assignees.login"
    RemoteAssigneeProfileURLs = "system.assignees.profile_url"
)
const APIStringTypeTrackers = "trackers"

APIStringTypeTracker helps to avoid string literal

Variables

var RemoteWorkItemImplRegistry = map[string]func(TrackerItem) (AttributeAccessor, error){
    ProviderGithub: NewGitHubRemoteWorkItem,
    ProviderJira:   NewJiraRemoteWorkItem,
}

RemoteWorkItemImplRegistry contains all possible providers

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

func ConvertToWorkItemModel Uses

func ConvertToWorkItemModel(ctx context.Context, db *gorm.DB, tID uuid.UUID, item TrackerItemContent, providerType string, spaceID uuid.UUID) (*workitem.WorkItem, error)

Map a remote work item into an WIT work item and persist it into the database.

func Flatten Uses

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

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

type AttributeAccessor Uses

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 Uses

func NewGitHubRemoteWorkItem(item TrackerItem) (AttributeAccessor, error)

NewGitHubRemoteWorkItem creates a new Decoded AttributeAccessor for a GitHub Issue

func NewJiraRemoteWorkItem Uses

func NewJiraRemoteWorkItem(item TrackerItem) (AttributeAccessor, error)

NewJiraRemoteWorkItem creates a new Decoded AttributeAccessor for a GitHub Issue

type AttributeConverter Uses

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

type AttributeExpression Uses

type AttributeExpression string

AttributeExpression represents a commonly understood String format for a target path

type AttributeMapper Uses

type AttributeMapper struct {
    Expression         AttributeExpression
    AttributeConverter AttributeConverter
}

type BadParameterError Uses

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

BadParameterError means that a parameter was not as required

func (BadParameterError) Error Uses

func (err BadParameterError) Error() string

Error implements the error interface

type ConversionError Uses

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

ConversionError error means something went wrong converting between different representations

func (ConversionError) Error Uses

func (err ConversionError) Error() string

type GitHubRemoteWorkItem Uses

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 Uses

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

Get attribute from issue map

type GithubStateConverter Uses

type GithubStateConverter struct{}

func (GithubStateConverter) Convert Uses

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

type GithubTracker Uses

type GithubTracker struct {
    URL   string
    Query string
}

GithubTracker represents the Github tracker provider

func (*GithubTracker) Fetch Uses

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

Fetch tracker items from Github

type GormTrackerQueryRepository Uses

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

GormTrackerQueryRepository implements TrackerRepository using gorm

func NewTrackerQueryRepository Uses

func NewTrackerQueryRepository(db *gorm.DB) *GormTrackerQueryRepository

NewTrackerQueryRepository constructs a TrackerQueryRepository

func (*GormTrackerQueryRepository) CheckExists Uses

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 Uses

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

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

func (*GormTrackerQueryRepository) Delete Uses

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

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

func (*GormTrackerQueryRepository) List Uses

func (r *GormTrackerQueryRepository) List(ctx context.Context) ([]*app.TrackerQuery, error)

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

func (*GormTrackerQueryRepository) Load Uses

func (r *GormTrackerQueryRepository) Load(ctx context.Context, ID string) (*app.TrackerQuery, error)

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

func (*GormTrackerQueryRepository) Save Uses

func (r *GormTrackerQueryRepository) Save(ctx context.Context, tq app.TrackerQuery) (*app.TrackerQuery, error)

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

type GormTrackerRepository Uses

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

GormTrackerRepository implements TrackerRepository using gorm

func NewTrackerRepository Uses

func NewTrackerRepository(db *gorm.DB) *GormTrackerRepository

NewTrackerRepository constructs a TrackerRepository

func (*GormTrackerRepository) CheckExists Uses

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

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

func (*GormTrackerRepository) Create Uses

func (r *GormTrackerRepository) Create(ctx context.Context, t *Tracker) error

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

func (*GormTrackerRepository) Delete Uses

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

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

func (*GormTrackerRepository) List Uses

func (r *GormTrackerRepository) List(ctx context.Context) ([]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 Uses

func (r *GormTrackerRepository) Load(ctx context.Context, ID uuid.UUID) (*Tracker, error)

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

func (*GormTrackerRepository) Save Uses

func (r *GormTrackerRepository) Save(ctx context.Context, t *Tracker) (*Tracker, error)

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

type InternalError Uses

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

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

func (InternalError) Error Uses

func (err InternalError) Error() string

type JiraRemoteWorkItem Uses

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

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

func (JiraRemoteWorkItem) Get Uses

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

Get attribute from issue map

type JiraStateConverter Uses

type JiraStateConverter struct{}

func (JiraStateConverter) Convert Uses

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

type JiraTracker Uses

type JiraTracker struct {
    URL   string
    Query string
}

JiraTracker represents the Jira tracker provider

func (*JiraTracker) Fetch Uses

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

Fetch collects data from Jira

type ListConverter Uses

type ListConverter struct{}

ListConverter converts a value into a list containing a single element

func (ListConverter) Convert Uses

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 Uses

type ListStringConverter struct{}

func (ListStringConverter) Convert Uses

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

Convert method map the external tracker item to WIT WorkItem

type MarkupConverter Uses

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

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

func (MarkupConverter) Convert Uses

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 Uses

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

NotFoundError means the object specified for the operation does not exist

func (NotFoundError) Error Uses

func (err NotFoundError) Error() string

type PatternToListConverter Uses

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

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

func (PatternToListConverter) Convert Uses

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 Uses

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 Uses

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

Map maps the remote WorkItem to a local RemoteWorkItem

type RemoteWorkItemMap Uses

type RemoteWorkItemMap map[AttributeMapper]string

RemoteWorkItemMap will define mappings between remote<->internal attribute

type Scheduler Uses

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

Scheduler represents scheduler

func NewScheduler Uses

func NewScheduler(db *gorm.DB) *Scheduler

NewScheduler creates a new Scheduler

func (*Scheduler) ScheduleAllQueries Uses

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

ScheduleAllQueries fetch and import of remote tracker items

func (*Scheduler) Stop Uses

func (s *Scheduler) Stop()

Stop scheduler This should be called only from main

type StateConverter Uses

type StateConverter interface{}

StateConverter converts a remote work item state

type StringConverter Uses

type StringConverter struct{}

StringConverter converts a value to a string

func (StringConverter) Convert Uses

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

Convert converts the given value to a string

type Tracker Uses

type Tracker struct {
    gormsupport.Lifecycle
    ID  uuid.UUID `sql:"type:uuid default uuid_generate_v4()" 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 Uses

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 uuid.UUID `gorm:"ForeignKey:Tracker"`
}

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

type TrackerItemContent Uses

type TrackerItemContent struct {
    ID      string
    Content []byte
}

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

type TrackerProvider Uses

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

TrackerProvider represents a remote tracker

type TrackerQuery Uses

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 uuid.UUID `gorm:"ForeignKey:Tracker"`
    // SpaceID is a foreign key for a space
    SpaceID uuid.UUID `gorm:"ForeignKey:Space"`
}

TrackerQuery represents tracker query

type TrackerQueryRepository Uses

type TrackerQueryRepository interface {
    CheckExists(ctx context.Context, id string) error
    Create(ctx context.Context, query string, schedule string, tracker uuid.UUID, spaceID uuid.UUID) (*app.TrackerQuery, error)
    Save(ctx context.Context, tq app.TrackerQuery) (*app.TrackerQuery, error)
    Load(ctx context.Context, ID string) (*app.TrackerQuery, error)
    Delete(ctx context.Context, ID string) error
    List(ctx context.Context) ([]*app.TrackerQuery, error)
}

TrackerQueryRepository encapsulate storage & retrieval of tracker queries

type TrackerRepository Uses

type TrackerRepository interface {
    repository.Exister
    Load(ctx context.Context, ID uuid.UUID) (*Tracker, error)
    Save(ctx context.Context, t *Tracker) (*Tracker, error)
    Delete(ctx context.Context, ID uuid.UUID) error
    Create(ctx context.Context, t *Tracker) error
    List(ctx context.Context) ([]Tracker, error)
}

TrackerRepository encapsulate storage & retrieval of tracker configuration

type VersionConflictError Uses

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

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

func (VersionConflictError) Error Uses

func (err VersionConflictError) Error() string

Package remoteworkitem imports 27 packages (graph) and is imported by 32 packages. Updated 2018-05-22. Refresh now. Tools for package owners.