bug

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: 20 Imported by: 0

Documentation

Overview

Package bug contains the bug data model and low-level related functions

Index

Constants

View Source
const (
	CreateOp dag.OperationType
	SetTitleOp
	AddCommentOp
	SetStatusOp
	LabelChangeOp
	EditCommentOp
	NoOpOp
	SetMetadataOp
)

Variables

View Source
var ClockLoader = dag.ClockLoader(def)
View Source
var ErrBugNotExist = errors.New("bug doesn't exist")

Functions

func ChangeLabels

func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) ([]LabelChangeResult, *LabelChangeOperation, error)

ChangeLabels is a convenience function to change labels on a bug

func Create

func Create(author identity.Interface, unixTime int64, title, message string, files []repository.Hash, metadata map[string]string) (*Bug, *CreateOperation, error)

Create is a convenience function to create a bug

func Fetch

func Fetch(repo repository.Repo, remote string) (string, error)

Fetch retrieve updates from a remote This does not change the local bugs state

func ListLocalIds

func ListLocalIds(repo repository.Repo) ([]entity.Id, error)

ListLocalIds list all the available local bug ids

func MergeAll

func MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) <-chan entity.MergeResult

MergeAll will merge all the available remote bug Note: an author is necessary for the case where a merge commit is created, as this commit will have an author and may be signed if a signing key is available.

func NewErrMultipleMatchBug

func NewErrMultipleMatchBug(matching []entity.Id) *entity.ErrMultipleMatch

func NewErrMultipleMatchOp

func NewErrMultipleMatchOp(matching []entity.Id) *entity.ErrMultipleMatch

func NewSetMetadataOp

func NewSetMetadataOp(author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) *dag.SetMetadataOperation[*Snapshot]

func Pull

func Pull(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) error

Pull will do a Fetch + MergeAll This function will return an error if a merge fail Note: an author is necessary for the case where a merge commit is created, as this commit will have an author and may be signed if a signing key is available.

func Push

func Push(repo repository.Repo, remote string) (string, error)

Push update a remote with the local changes

func ReadAll

func ReadAll(repo repository.ClockedRepo) <-chan StreamedBug

ReadAll read and parse all local bugs

func ReadAllWithResolver

func ReadAllWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers) <-chan StreamedBug

ReadAllWithResolver read and parse all local bugs

func Remove

func Remove(repo repository.ClockedRepo, id entity.Id) error

Remove will remove a local bug from its entity.Id

func SetMetadata

func SetMetadata(b Interface, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*Snapshot], error)

SetMetadata is a convenience function to add metadata on another operation

Types

type AddCommentOperation

type AddCommentOperation struct {
	dag.OpBase
	Message string `json:"message"`
	// TODO: change for a map[string]util.hash to store the filename ?
	Files []repository.Hash `json:"files"`
}

AddCommentOperation will add a new comment in the bug

func AddComment

func AddComment(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *AddCommentOperation, error)

AddComment is a convenience function to add a comment to a bug

func NewAddCommentOp

func NewAddCommentOp(author identity.Interface, unixTime int64, message string, files []repository.Hash) *AddCommentOperation

func (*AddCommentOperation) Apply

func (op *AddCommentOperation) Apply(snapshot *Snapshot)

func (*AddCommentOperation) GetFiles

func (op *AddCommentOperation) GetFiles() []repository.Hash

func (*AddCommentOperation) Id

func (op *AddCommentOperation) Id() entity.Id

func (*AddCommentOperation) Validate

func (op *AddCommentOperation) Validate() error

type AddCommentTimelineItem

type AddCommentTimelineItem struct {
	CommentTimelineItem
}

AddCommentTimelineItem replace a AddComment operation in the Timeline and hold its edition history

func (*AddCommentTimelineItem) IsAuthored

func (a *AddCommentTimelineItem) IsAuthored()

IsAuthored is a sign post method for gqlgen

type Bug

type Bug struct {
	*dag.Entity
}

Bug holds the data of a bug thread, organized in a way close to how it will be persisted inside Git. This is the data structure used to merge two different version of the same Bug.

func NewBug

func NewBug() *Bug

NewBug create a new Bug

func Read

func Read(repo repository.ClockedRepo, id entity.Id) (*Bug, error)

Read will read a bug from a repository

func ReadWithResolver

func ReadWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers, id entity.Id) (*Bug, error)

ReadWithResolver will read a bug from its Id, with custom resolvers

func (*Bug) Append

func (bug *Bug) Append(op Operation)

Append add a new Operation to the Bug

func (*Bug) Compile

func (bug *Bug) Compile() *Snapshot

Compile a bug in an easily usable snapshot

func (*Bug) FirstOp

func (bug *Bug) FirstOp() Operation

FirstOp lookup for the very first operation of the bug. For a valid Bug, this operation should be a CreateOp

func (*Bug) LastOp

func (bug *Bug) LastOp() Operation

LastOp lookup for the very last operation of the bug. For a valid Bug, should never be nil

func (*Bug) Operations

func (bug *Bug) Operations() []Operation

Operations return the ordered operations

func (*Bug) Validate

func (bug *Bug) Validate() error

Validate check if the Bug data is valid

type BugsByCreationTime

type BugsByCreationTime []*Bug

func (BugsByCreationTime) Len

func (b BugsByCreationTime) Len() int

func (BugsByCreationTime) Less

func (b BugsByCreationTime) Less(i, j int) bool

func (BugsByCreationTime) Swap

func (b BugsByCreationTime) Swap(i, j int)

type BugsByEditTime

type BugsByEditTime []*Bug

func (BugsByEditTime) Len

func (b BugsByEditTime) Len() int

func (BugsByEditTime) Less

func (b BugsByEditTime) Less(i, j int) bool

func (BugsByEditTime) Swap

func (b BugsByEditTime) Swap(i, j int)

type Comment

type Comment struct {
	Author  identity.Interface
	Message string
	Files   []repository.Hash
	// contains filtered or unexported fields
}

Comment represent a comment in a Bug

func (Comment) CombinedId

func (c Comment) CombinedId() entity.CombinedId

func (Comment) FormatTime

func (c Comment) FormatTime() string

func (Comment) FormatTimeRel

func (c Comment) FormatTimeRel() string

FormatTimeRel format the unixTime of the comment for human consumption

func (Comment) IsAuthored

func (c Comment) IsAuthored()

IsAuthored is a sign post method for gqlgen

func (Comment) TargetId

func (c Comment) TargetId() entity.Id

type CommentHistoryStep

type CommentHistoryStep struct {
	// The author of the edition, not necessarily the same as the author of the
	// original comment
	Author identity.Interface
	// The new message
	Message  string
	UnixTime timestamp.Timestamp
}

CommentHistoryStep hold one version of a message in the history

type CommentTimelineItem

type CommentTimelineItem struct {
	Author    identity.Interface
	Message   string
	Files     []repository.Hash
	CreatedAt timestamp.Timestamp
	LastEdit  timestamp.Timestamp
	History   []CommentHistoryStep
	// contains filtered or unexported fields
}

CommentTimelineItem is a TimelineItem that holds a Comment and its edition history

func NewCommentTimelineItem

func NewCommentTimelineItem(comment Comment) CommentTimelineItem

func (*CommentTimelineItem) Append

func (c *CommentTimelineItem) Append(comment Comment)

Append will append a new comment in the history and update the other values

func (*CommentTimelineItem) CombinedId

func (c *CommentTimelineItem) CombinedId() entity.CombinedId

func (*CommentTimelineItem) Edited

func (c *CommentTimelineItem) Edited() bool

Edited say if the comment was edited

func (*CommentTimelineItem) MessageIsEmpty

func (c *CommentTimelineItem) MessageIsEmpty() bool

MessageIsEmpty return true is the message is empty or only made of spaces

type CreateOperation

type CreateOperation struct {
	dag.OpBase
	Title   string            `json:"title"`
	Message string            `json:"message"`
	Files   []repository.Hash `json:"files"`
}

CreateOperation define the initial creation of a bug

func NewCreateOp

func NewCreateOp(author identity.Interface, unixTime int64, title, message string, files []repository.Hash) *CreateOperation

func (*CreateOperation) Apply

func (op *CreateOperation) Apply(snapshot *Snapshot)

func (*CreateOperation) GetFiles

func (op *CreateOperation) GetFiles() []repository.Hash

func (*CreateOperation) Id

func (op *CreateOperation) Id() entity.Id

func (*CreateOperation) Validate

func (op *CreateOperation) Validate() error

type CreateTimelineItem

type CreateTimelineItem struct {
	CommentTimelineItem
}

CreateTimelineItem replace a Create operation in the Timeline and hold its edition history

func (*CreateTimelineItem) IsAuthored

func (c *CreateTimelineItem) IsAuthored()

IsAuthored is a sign post method for gqlgen

type EditCommentOperation

type EditCommentOperation struct {
	dag.OpBase
	Target  entity.Id         `json:"target"`
	Message string            `json:"message"`
	Files   []repository.Hash `json:"files"`
}

EditCommentOperation will change a comment in the bug

func EditComment

func EditComment(b Interface, author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *EditCommentOperation, error)

EditComment is a convenience function to apply the operation

func EditCreateComment

func EditCreateComment(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *EditCommentOperation, error)

EditCreateComment is a convenience function to edit the body of a bug (the first comment)

func NewEditCommentOp

func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash) *EditCommentOperation

func (*EditCommentOperation) Apply

func (op *EditCommentOperation) Apply(snapshot *Snapshot)

func (*EditCommentOperation) GetFiles

func (op *EditCommentOperation) GetFiles() []repository.Hash

func (*EditCommentOperation) Id

func (op *EditCommentOperation) Id() entity.Id

func (*EditCommentOperation) Validate

func (op *EditCommentOperation) Validate() error

type Interface

type Interface interface {
	dag.Interface[*Snapshot, Operation]
}

type Label

type Label string

func (Label) Color

func (l Label) Color() LabelColor

RGBA from a Label computed in a deterministic way

func (Label) String

func (l Label) String() string

func (Label) Validate

func (l Label) Validate() error

type LabelChangeOperation

type LabelChangeOperation struct {
	dag.OpBase
	Added   []Label `json:"added"`
	Removed []Label `json:"removed"`
}

LabelChangeOperation define a Bug operation to add or remove labels

func ForceChangeLabels

func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) (*LabelChangeOperation, error)

ForceChangeLabels is a convenience function to apply the operation The difference with ChangeLabels is that no checks for deduplication are done. You are entirely responsible for what you are doing. In the general case, you want to use ChangeLabels instead. The intended use of this function is to allow importers to create legal but unexpected label changes, like removing a label with no information of when it was added before.

func NewLabelChangeOperation

func NewLabelChangeOperation(author identity.Interface, unixTime int64, added, removed []Label) *LabelChangeOperation

func (*LabelChangeOperation) Apply

func (op *LabelChangeOperation) Apply(snapshot *Snapshot)

Apply applies the operation

func (*LabelChangeOperation) Id

func (op *LabelChangeOperation) Id() entity.Id

func (*LabelChangeOperation) Validate

func (op *LabelChangeOperation) Validate() error

type LabelChangeResult

type LabelChangeResult struct {
	Label  Label
	Status LabelChangeStatus
}

func (LabelChangeResult) String

func (l LabelChangeResult) String() string

type LabelChangeStatus

type LabelChangeStatus int
const (
	LabelChangeAdded LabelChangeStatus
	LabelChangeRemoved
	LabelChangeDuplicateInOp
	LabelChangeAlreadySet
	LabelChangeDoesntExist
)

func (LabelChangeStatus) MarshalGQL

func (l LabelChangeStatus) MarshalGQL(w io.Writer)

func (*LabelChangeStatus) UnmarshalGQL

func (l *LabelChangeStatus) UnmarshalGQL(v interface{}) error

type LabelChangeTimelineItem

type LabelChangeTimelineItem struct {
	Author   identity.Interface
	UnixTime timestamp.Timestamp
	Added    []Label
	Removed  []Label
	// contains filtered or unexported fields
}

func (LabelChangeTimelineItem) CombinedId

func (l LabelChangeTimelineItem) CombinedId() entity.CombinedId

func (*LabelChangeTimelineItem) IsAuthored

func (l *LabelChangeTimelineItem) IsAuthored()

IsAuthored is a sign post method for gqlgen

type LabelColor

type LabelColor color.RGBA

func (LabelColor) RGBA

func (lc LabelColor) RGBA() color.RGBA

func (LabelColor) Term256

func (lc LabelColor) Term256() Term256

type Operation

type Operation interface {
	dag.Operation

	// Apply the operation to a Snapshot to create the final state
	Apply(snapshot *Snapshot)
}

Operation define the interface to fulfill for an edit operation of a Bug

type SetStatusOperation

type SetStatusOperation struct {
	dag.OpBase
	Status common.Status `json:"status"`
}

SetStatusOperation will change the status of a bug

func Close

func Close(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*SetStatusOperation, error)

Close is a convenience function to change a bugs state to Close

func NewSetStatusOp

func NewSetStatusOp(author identity.Interface, unixTime int64, status common.Status) *SetStatusOperation

func Open

func Open(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*SetStatusOperation, error)

Open is a convenience function to change a bugs state to Open

func (*SetStatusOperation) Apply

func (op *SetStatusOperation) Apply(snapshot *Snapshot)

func (*SetStatusOperation) Id

func (op *SetStatusOperation) Id() entity.Id

func (*SetStatusOperation) Validate

func (op *SetStatusOperation) Validate() error

type SetStatusTimelineItem

type SetStatusTimelineItem struct {
	Author   identity.Interface
	UnixTime timestamp.Timestamp
	Status   common.Status
	// contains filtered or unexported fields
}

func (SetStatusTimelineItem) CombinedId

func (s SetStatusTimelineItem) CombinedId() entity.CombinedId

func (*SetStatusTimelineItem) IsAuthored

func (s *SetStatusTimelineItem) IsAuthored()

IsAuthored is a sign post method for gqlgen

type SetTitleOperation

type SetTitleOperation struct {
	dag.OpBase
	Title string `json:"title"`
	Was   string `json:"was"`
}

SetTitleOperation will change the title of a bug

func NewSetTitleOp

func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was string) *SetTitleOperation

func SetTitle

func SetTitle(b Interface, author identity.Interface, unixTime int64, title string, metadata map[string]string) (*SetTitleOperation, error)

SetTitle is a convenience function to change a bugs title

func (*SetTitleOperation) Apply

func (op *SetTitleOperation) Apply(snapshot *Snapshot)

func (*SetTitleOperation) Id

func (op *SetTitleOperation) Id() entity.Id

func (*SetTitleOperation) Validate

func (op *SetTitleOperation) Validate() error

type SetTitleTimelineItem

type SetTitleTimelineItem struct {
	Author   identity.Interface
	UnixTime timestamp.Timestamp
	Title    string
	Was      string
	// contains filtered or unexported fields
}

func (SetTitleTimelineItem) CombinedId

func (s SetTitleTimelineItem) CombinedId() entity.CombinedId

func (*SetTitleTimelineItem) IsAuthored

func (s *SetTitleTimelineItem) IsAuthored()

IsAuthored is a sign post method for gqlgen

type SimpleResolver

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

SimpleResolver is a Resolver loading Bugs directly from a Repo

func NewSimpleResolver

func NewSimpleResolver(repo repository.ClockedRepo) *SimpleResolver

func (*SimpleResolver) Resolve

func (r *SimpleResolver) Resolve(id entity.Id) (entity.Interface, error)

type Snapshot

type Snapshot struct {
	Status       common.Status
	Title        string
	Comments     []Comment
	Labels       []Label
	Author       identity.Interface
	Actors       []identity.Interface
	Participants []identity.Interface
	CreateTime   time.Time

	Timeline []TimelineItem

	Operations []dag.Operation
	// contains filtered or unexported fields
}

Snapshot is a compiled form of the Bug data structure used for storage and merge

func (*Snapshot) AllOperations

func (snap *Snapshot) AllOperations() []dag.Operation

func (*Snapshot) EditTime

func (snap *Snapshot) EditTime() time.Time

EditTime returns the last time a bug was modified

func (*Snapshot) GetCreateMetadata

func (snap *Snapshot) GetCreateMetadata(key string) (string, bool)

GetCreateMetadata return the creation metadata

func (*Snapshot) HasActor

func (snap *Snapshot) HasActor(id entity.Id) bool

HasActor return true if the id is a actor

func (*Snapshot) HasAnyActor

func (snap *Snapshot) HasAnyActor(ids ...entity.Id) bool

HasAnyActor return true if one of the ids is a actor

func (*Snapshot) HasAnyParticipant

func (snap *Snapshot) HasAnyParticipant(ids ...entity.Id) bool

HasAnyParticipant return true if one of the ids is a participant

func (*Snapshot) HasParticipant

func (snap *Snapshot) HasParticipant(id entity.Id) bool

HasParticipant return true if the id is a participant

func (*Snapshot) Id

func (snap *Snapshot) Id() entity.Id

Id returns the Bug identifier

func (*Snapshot) IsAuthored

func (snap *Snapshot) IsAuthored()

IsAuthored is a sign post method for gqlgen

func (*Snapshot) SearchComment

func (snap *Snapshot) SearchComment(id entity.CombinedId) (*Comment, error)

SearchComment will search for a comment matching the given id

func (*Snapshot) SearchCommentByOpId

func (snap *Snapshot) SearchCommentByOpId(id entity.Id) (*Comment, error)

SearchCommentByOpId will search for a comment generated by the given operation Id

func (*Snapshot) SearchTimelineItem

func (snap *Snapshot) SearchTimelineItem(id entity.CombinedId) (TimelineItem, error)

SearchTimelineItem will search in the timeline for an item matching the given hash

type StreamedBug

type StreamedBug struct {
	Bug *Bug
	Err error
}

type Term256

type Term256 int

func (Term256) Escape

func (t Term256) Escape() string

func (Term256) Unescape

func (t Term256) Unescape() string

type TimelineItem

type TimelineItem interface {
	// CombinedId returns the global identifier of the item
	CombinedId() entity.CombinedId
}

type WithSnapshot

type WithSnapshot struct {
	*Bug
	// contains filtered or unexported fields
}

WithSnapshot encapsulate a Bug and maintain the corresponding Snapshot efficiently

func (*WithSnapshot) Append

func (b *WithSnapshot) Append(op Operation)

Append intercept Bug.Append() to update the snapshot efficiently

func (*WithSnapshot) Commit

func (b *WithSnapshot) Commit(repo repository.ClockedRepo) error

Commit intercept Bug.Commit() to update the snapshot efficiently

func (*WithSnapshot) Compile

func (b *WithSnapshot) Compile() *Snapshot

Jump to

Keyboard shortcuts

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