bug

package
v0.0.0-...-8ec1dd0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

Functions

func ChangeLabels

func ChangeLabels(b Interface, author Person, unixTime int64, add, remove []string) ([]LabelChangeResult, *LabelChangeOperation, error)

ChangeLabels is a convenience function to apply the operation

func Create

func Create(author Person, unixTime int64, title, message string) (*Bug, *CreateOperation, error)

Convenience function to apply the operation

func CreateWithFiles

func CreateWithFiles(author Person, unixTime int64, title, message string, files []git.Hash) (*Bug, *CreateOperation, error)

func Fetch

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

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

func FormatHumanID

func FormatHumanID(id string) string

func ListLocalIds

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

ListLocalIds list all the available local bug ids

func MergeAll

func MergeAll(repo repository.ClockedRepo, remote string) <-chan MergeResult

MergeAll will merge all the available remote bug

func Pull

func Pull(repo repository.ClockedRepo, remote string) error

Pull will do a Fetch + MergeAll This function won't give details on the underlying process. If you need more use Fetch and MergeAll separately.

func Push

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

Push update a remote with the local changes

func ReadAllLocalBugs

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

ReadAllLocalBugs read and parse all local bugs

func ReadAllRemoteBugs

func ReadAllRemoteBugs(repo repository.ClockedRepo, remote string) <-chan StreamedBug

ReadAllRemoteBugs read and parse all remote bugs for a given remote

func Witnesser

func Witnesser(repo *repository.GitRepo) error

Witnesser will read all the available Bug to recreate the different logical clocks

Types

type AddCommentOperation

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

AddCommentOperation will add a new comment in the bug

func AddComment

func AddComment(b Interface, author Person, unixTime int64, message string) (*AddCommentOperation, error)

Convenience function to apply the operation

func AddCommentWithFiles

func AddCommentWithFiles(b Interface, author Person, unixTime int64, message string, files []git.Hash) (*AddCommentOperation, error)

func NewAddCommentOp

func NewAddCommentOp(author Person, unixTime int64, message string, files []git.Hash) *AddCommentOperation

func (*AddCommentOperation) Apply

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

func (*AddCommentOperation) GetFiles

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

func (*AddCommentOperation) Hash

func (op *AddCommentOperation) Hash() (git.Hash, error)

func (*AddCommentOperation) Validate

func (op *AddCommentOperation) Validate() error

type AddCommentTimelineItem

type AddCommentTimelineItem struct {
	CommentTimelineItem
}

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

type Bug

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

Bug hold 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 FindLocalBug

func FindLocalBug(repo repository.ClockedRepo, prefix string) (*Bug, error)

FindLocalBug find an existing Bug matching a prefix

func NewBug

func NewBug() *Bug

NewBug create a new Bug

func ReadLocalBug

func ReadLocalBug(repo repository.ClockedRepo, id string) (*Bug, error)

ReadLocalBug will read a local bug from its hash

func ReadRemoteBug

func ReadRemoteBug(repo repository.ClockedRepo, remote string, id string) (*Bug, error)

ReadRemoteBug will read a remote bug from its hash

func (*Bug) Append

func (bug *Bug) Append(op Operation)

Append an operation into the staging area, to be committed later

func (*Bug) Commit

func (bug *Bug) Commit(repo repository.ClockedRepo) error

Commit write the staging area in Git and move the operations to the packs

func (*Bug) Compile

func (bug *Bug) Compile() Snapshot

Compile a bug in a easily usable snapshot

func (*Bug) CreateLamportTime

func (bug *Bug) CreateLamportTime() lamport.Time

CreateLamportTime return the Lamport time of creation

func (*Bug) EditLamportTime

func (bug *Bug) EditLamportTime() lamport.Time

EditLamportTime return the Lamport time of the last edit

func (*Bug) FirstOp

func (bug *Bug) FirstOp() Operation

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

func (*Bug) HasPendingOp

func (bug *Bug) HasPendingOp() bool

HasPendingOp tell if the bug need to be committed

func (*Bug) HumanId

func (bug *Bug) HumanId() string

HumanId return the Bug identifier truncated for human consumption

func (*Bug) Id

func (bug *Bug) Id() string

Id return the Bug identifier

func (*Bug) LastOp

func (bug *Bug) LastOp() Operation

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

func (*Bug) Merge

func (bug *Bug) Merge(repo repository.Repo, other Interface) (bool, error)

Merge a different version of the same bug by rebasing operations of this bug that are not present in the other on top of the chain of operations of the other version.

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  Person
	Message string
	Files   []git.Hash

	// Creation time of the comment.
	// Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
	UnixTime Timestamp
}

Comment represent a comment in a Bug

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

type CommentHistoryStep

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

type CommentTimelineItem

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

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

func NewCommentTimelineItem

func NewCommentTimelineItem(hash git.Hash, 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) Edited

func (c *CommentTimelineItem) Edited() bool

Edited say if the comment was edited

func (*CommentTimelineItem) Hash

func (c *CommentTimelineItem) Hash() git.Hash

type CreateOperation

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

CreateOperation define the initial creation of a bug

func NewCreateOp

func NewCreateOp(author Person, unixTime int64, title, message string, files []git.Hash) *CreateOperation

func (*CreateOperation) Apply

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

func (*CreateOperation) GetFiles

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

func (*CreateOperation) Hash

func (op *CreateOperation) Hash() (git.Hash, error)

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

type EditCommentOperation

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

EditCommentOperation will change a comment in the bug

func EditComment

func EditComment(b Interface, author Person, unixTime int64, target git.Hash, message string) (*EditCommentOperation, error)

Convenience function to apply the operation

func EditCommentWithFiles

func EditCommentWithFiles(b Interface, author Person, unixTime int64, target git.Hash, message string, files []git.Hash) (*EditCommentOperation, error)

func NewEditCommentOp

func NewEditCommentOp(author Person, unixTime int64, target git.Hash, message string, files []git.Hash) *EditCommentOperation

func (*EditCommentOperation) Apply

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

func (*EditCommentOperation) GetFiles

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

func (*EditCommentOperation) Hash

func (op *EditCommentOperation) Hash() (git.Hash, error)

func (*EditCommentOperation) Validate

func (op *EditCommentOperation) Validate() error

type ErrMultipleMatch

type ErrMultipleMatch struct {
	Matching []string
}

func (ErrMultipleMatch) Error

func (e ErrMultipleMatch) Error() string

type Interface

type Interface interface {
	// Id return the Bug identifier
	Id() string

	// HumanId return the Bug identifier truncated for human consumption
	HumanId() string

	// Validate check if the Bug data is valid
	Validate() error

	// Append an operation into the staging area, to be committed later
	Append(op Operation)

	// Append an operation into the staging area, to be committed later
	HasPendingOp() bool

	// Commit write the staging area in Git and move the operations to the packs
	Commit(repo repository.ClockedRepo) error

	// Merge a different version of the same bug by rebasing operations of this bug
	// that are not present in the other on top of the chain of operations of the
	// other version.
	Merge(repo repository.Repo, other Interface) (bool, error)

	// Lookup for the very first operation of the bug.
	// For a valid Bug, this operation should be a CreateOp
	FirstOp() Operation

	// Lookup for the very last operation of the bug.
	// For a valid Bug, should never be nil
	LastOp() Operation

	// Compile a bug in a easily usable snapshot
	Compile() Snapshot

	// CreateLamportTime return the Lamport time of creation
	CreateLamportTime() lamport.Time

	// EditLamportTime return the Lamport time of the last edit
	EditLamportTime() lamport.Time
}

type Label

type Label string

func (Label) MarshalGQL

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

MarshalGQL implements the graphql.Marshaler interface

func (Label) String

func (l Label) String() string

func (*Label) UnmarshalGQL

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

UnmarshalGQL implements the graphql.Unmarshaler interface

func (Label) Validate

func (l Label) Validate() error

type LabelChangeOperation

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

LabelChangeOperation define a Bug operation to add or remove labels

func NewLabelChangeOperation

func NewLabelChangeOperation(author Person, unixTime int64, added, removed []Label) *LabelChangeOperation

func (*LabelChangeOperation) Apply

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

Apply apply the operation

func (*LabelChangeOperation) Hash

func (op *LabelChangeOperation) Hash() (git.Hash, error)

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
)

type LabelChangeTimelineItem

type LabelChangeTimelineItem struct {
	Author   Person
	UnixTime Timestamp
	Added    []Label
	Removed  []Label
	// contains filtered or unexported fields
}

func (LabelChangeTimelineItem) Hash

func (l LabelChangeTimelineItem) Hash() git.Hash

type MergeResult

type MergeResult struct {
	// Err is set when a terminal error occur in the process
	Err error

	Id     string
	Status MergeStatus

	// Only set for invalid status
	Reason string

	// Not set for invalid status
	Bug *Bug
}

func (MergeResult) String

func (mr MergeResult) String() string

type MergeStatus

type MergeStatus int

MergeStatus represent the result of a merge operation of a bug

const (
	MergeStatusNew MergeStatus
	MergeStatusInvalid
	MergeStatusUpdated
	MergeStatusNothing
)

type NoOpOperation

type NoOpOperation struct {
	OpBase
}

NoOpOperation is an operation that does not change the bug state. It can however be used to store arbitrary metadata in the bug history, for example to support a bridge feature

func NewNoOpOp

func NewNoOpOp(author Person, unixTime int64) *NoOpOperation

func NoOp

func NoOp(b Interface, author Person, unixTime int64, metadata map[string]string) (*NoOpOperation, error)

Convenience function to apply the operation

func (*NoOpOperation) Apply

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

func (*NoOpOperation) Hash

func (op *NoOpOperation) Hash() (git.Hash, error)

func (*NoOpOperation) Validate

func (op *NoOpOperation) Validate() error

type OpBase

type OpBase struct {
	OperationType OperationType `json:"type"`
	Author        Person        `json:"author"`
	UnixTime      int64         `json:"timestamp"`

	Metadata map[string]string `json:"metadata,omitempty"`
	// contains filtered or unexported fields
}

OpBase implement the common code for all operations

func (*OpBase) AllMetadata

func (op *OpBase) AllMetadata() map[string]string

AllMetadata return all metadata for this operation

func (*OpBase) GetFiles

func (op *OpBase) GetFiles() []git.Hash

GetFiles return the files needed by this operation

func (*OpBase) GetMetadata

func (op *OpBase) GetMetadata(key string) (string, bool)

GetMetadata retrieve arbitrary metadata about the operation

func (*OpBase) GetUnixTime

func (op *OpBase) GetUnixTime() int64

GetUnixTime return the unix timestamp when the operation was added

func (*OpBase) SetMetadata

func (op *OpBase) SetMetadata(key string, value string)

SetMetadata store arbitrary metadata about the operation

func (*OpBase) Time

func (op *OpBase) Time() time.Time

Time return the time when the operation was added

type Operation

type Operation interface {

	// Hash return the hash of the operation, to be used for back references
	Hash() (git.Hash, error)
	// Time return the time when the operation was added
	Time() time.Time
	// GetUnixTime return the unix timestamp when the operation was added
	GetUnixTime() int64
	// GetFiles return the files needed by this operation
	GetFiles() []git.Hash
	// Apply the operation to a Snapshot to create the final state
	Apply(snapshot *Snapshot)
	// Validate check if the operation is valid (ex: a title is a single line)
	Validate() error
	// SetMetadata store arbitrary metadata about the operation
	SetMetadata(key string, value string)
	// GetMetadata retrieve arbitrary metadata about the operation
	GetMetadata(key string) (string, bool)
	// AllMetadata return all metadata for this operation
	AllMetadata() map[string]string
	// contains filtered or unexported methods
}

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

type OperationIterator

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

func NewOperationIterator

func NewOperationIterator(bug Interface) *OperationIterator

func (*OperationIterator) Next

func (it *OperationIterator) Next() bool

func (*OperationIterator) Value

func (it *OperationIterator) Value() Operation

type OperationPack

type OperationPack struct {
	Operations []Operation
	// contains filtered or unexported fields
}

OperationPack represent an ordered set of operation to apply to a Bug. These operations are stored in a single Git commit.

These commits will be linked together in a linear chain of commits inside Git to form the complete ordered chain of operation to apply to get the final state of the Bug

func (*OperationPack) Append

func (opp *OperationPack) Append(op Operation)

Append a new operation to the pack

func (*OperationPack) Clone

func (opp *OperationPack) Clone() OperationPack

Make a deep copy

func (*OperationPack) IsEmpty

func (opp *OperationPack) IsEmpty() bool

IsEmpty tell if the OperationPack is empty

func (*OperationPack) MarshalJSON

func (opp *OperationPack) MarshalJSON() ([]byte, error)

func (*OperationPack) UnmarshalJSON

func (opp *OperationPack) UnmarshalJSON(data []byte) error

func (*OperationPack) Validate

func (opp *OperationPack) Validate() error

IsValid tell if the OperationPack is considered valid

func (*OperationPack) Write

func (opp *OperationPack) Write(repo repository.Repo) (git.Hash, error)

Write will serialize and store the OperationPack as a git blob and return its hash

type OperationType

type OperationType int

OperationType is an operation type identifier

const (
	CreateOp OperationType
	SetTitleOp
	AddCommentOp
	SetStatusOp
	LabelChangeOp
	EditCommentOp
	NoOpOp
)

type Person

type Person struct {
	Name      string `json:"name"`
	Email     string `json:"email"`
	AvatarUrl string `json:"avatar_url"`
}

func GetUser

func GetUser(repo repository.Repo) (Person, error)

GetUser will query the repository for user detail and build the corresponding Person

func (Person) Match

func (p Person) Match(query string) bool

Match tell is the Person match the given query string

func (Person) String

func (p Person) String() string

func (Person) Validate

func (p Person) Validate() error

type SetStatusOperation

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

SetStatusOperation will change the status of a bug

func Close

func Close(b Interface, author Person, unixTime int64) (*SetStatusOperation, error)

Convenience function to apply the operation

func NewSetStatusOp

func NewSetStatusOp(author Person, unixTime int64, status Status) *SetStatusOperation

func Open

func Open(b Interface, author Person, unixTime int64) (*SetStatusOperation, error)

Convenience function to apply the operation

func (*SetStatusOperation) Apply

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

func (*SetStatusOperation) Hash

func (op *SetStatusOperation) Hash() (git.Hash, error)

func (*SetStatusOperation) Validate

func (op *SetStatusOperation) Validate() error

type SetStatusTimelineItem

type SetStatusTimelineItem struct {
	Author   Person
	UnixTime Timestamp
	Status   Status
	// contains filtered or unexported fields
}

func (SetStatusTimelineItem) Hash

func (s SetStatusTimelineItem) Hash() git.Hash

type SetTitleOperation

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

SetTitleOperation will change the title of a bug

func NewSetTitleOp

func NewSetTitleOp(author Person, unixTime int64, title string, was string) *SetTitleOperation

func SetTitle

func SetTitle(b Interface, author Person, unixTime int64, title string) (*SetTitleOperation, error)

Convenience function to apply the operation

func (*SetTitleOperation) Apply

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

func (*SetTitleOperation) Hash

func (op *SetTitleOperation) Hash() (git.Hash, error)

func (*SetTitleOperation) Validate

func (op *SetTitleOperation) Validate() error

type SetTitleTimelineItem

type SetTitleTimelineItem struct {
	Author   Person
	UnixTime Timestamp
	Title    string
	Was      string
	// contains filtered or unexported fields
}

func (SetTitleTimelineItem) Hash

func (s SetTitleTimelineItem) Hash() git.Hash

type Snapshot

type Snapshot struct {
	Status    Status
	Title     string
	Comments  []Comment
	Labels    []Label
	Author    Person
	CreatedAt time.Time

	Timeline []TimelineItem

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

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

func (*Snapshot) HumanId

func (snap *Snapshot) HumanId() string

Return the Bug identifier truncated for human consumption

func (*Snapshot) Id

func (snap *Snapshot) Id() string

Return the Bug identifier

func (*Snapshot) LastEditTime

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

Return the last time a bug was modified

func (*Snapshot) LastEditUnix

func (snap *Snapshot) LastEditUnix() int64

Return the last timestamp a bug was modified

func (*Snapshot) SearchTimelineItem

func (snap *Snapshot) SearchTimelineItem(hash git.Hash) (TimelineItem, error)

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

func (*Snapshot) Summary deprecated

func (snap *Snapshot) Summary() string

Deprecated:should be moved in UI code

type Status

type Status int
const (
	OpenStatus Status
	ClosedStatus
)

func StatusFromString

func StatusFromString(str string) (Status, error)

func (Status) Action

func (s Status) Action() string

func (Status) String

func (s Status) String() string

func (Status) Validate

func (s Status) Validate() error

type StreamedBug

type StreamedBug struct {
	Bug *Bug
	Err error
}

type TimelineItem

type TimelineItem interface {
	// Hash return the hash of the item
	Hash() git.Hash
}

type Timestamp

type Timestamp int64

func (Timestamp) Time

func (t Timestamp) Time() time.Time

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) Merge

func (b *WithSnapshot) Merge(repo repository.Repo, other Interface) (bool, error)

Merge intercept Bug.Merge() and clear the snapshot

func (*WithSnapshot) Snapshot

func (b *WithSnapshot) Snapshot() *Snapshot

Snapshot return the current snapshot

Jump to

Keyboard shortcuts

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