mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-15 10:12:06 +03:00
bug: fix an issue where Id would be used, then changed due to metadata
This commit is contained in:
parent
3d454d9dc8
commit
d179b8b7ec
@ -140,14 +140,14 @@ func (bug *Bug) Operations() []Operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compile a bug in a easily usable snapshot
|
// Compile a bug in a easily usable snapshot
|
||||||
func (bug *Bug) Compile() Snapshot {
|
func (bug *Bug) Compile() *Snapshot {
|
||||||
snap := Snapshot{
|
snap := &Snapshot{
|
||||||
id: bug.Id(),
|
id: bug.Id(),
|
||||||
Status: OpenStatus,
|
Status: OpenStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, op := range bug.Operations() {
|
for _, op := range bug.Operations() {
|
||||||
op.Apply(&snap)
|
op.Apply(snap)
|
||||||
snap.Operations = append(snap.Operations, op)
|
snap.Operations = append(snap.Operations, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,22 +7,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
// Id return the Bug identifier
|
// Id returns the Bug identifier
|
||||||
Id() entity.Id
|
Id() entity.Id
|
||||||
|
|
||||||
// Validate check if the Bug data is valid
|
// Validate checks if the Bug data is valid
|
||||||
Validate() error
|
Validate() error
|
||||||
|
|
||||||
// Append an operation into the staging area, to be committed later
|
// Append an operation into the staging area, to be committed later
|
||||||
Append(op Operation)
|
Append(op Operation)
|
||||||
|
|
||||||
// Operations return the ordered operations
|
// Operations returns the ordered operations
|
||||||
Operations() []Operation
|
Operations() []Operation
|
||||||
|
|
||||||
// NeedCommit indicate that the in-memory state changed and need to be commit in the repository
|
// NeedCommit indicates that the in-memory state changed and need to be commit in the repository
|
||||||
NeedCommit() bool
|
NeedCommit() bool
|
||||||
|
|
||||||
// Commit write the staging area in Git and move the operations to the packs
|
// Commit writes the staging area in Git and move the operations to the packs
|
||||||
Commit(repo repository.ClockedRepo) error
|
Commit(repo repository.ClockedRepo) error
|
||||||
|
|
||||||
// FirstOp lookup for the very first operation of the bug.
|
// FirstOp lookup for the very first operation of the bug.
|
||||||
@ -33,8 +33,8 @@ type Interface interface {
|
|||||||
// For a valid Bug, should never be nil
|
// For a valid Bug, should never be nil
|
||||||
LastOp() Operation
|
LastOp() Operation
|
||||||
|
|
||||||
// Compile a bug in a easily usable snapshot
|
// Compile a bug in an easily usable snapshot
|
||||||
Compile() Snapshot
|
Compile() *Snapshot
|
||||||
|
|
||||||
// CreateLamportTime return the Lamport time of creation
|
// CreateLamportTime return the Lamport time of creation
|
||||||
CreateLamportTime() lamport.Time
|
CreateLamportTime() lamport.Time
|
||||||
|
@ -79,16 +79,15 @@ type AddCommentTimelineItem struct {
|
|||||||
// IsAuthored is a sign post method for gqlgen
|
// IsAuthored is a sign post method for gqlgen
|
||||||
func (a *AddCommentTimelineItem) IsAuthored() {}
|
func (a *AddCommentTimelineItem) IsAuthored() {}
|
||||||
|
|
||||||
// Convenience function to apply the operation
|
// AddComment is a convenience function to add a comment to a bug
|
||||||
func AddComment(b Interface, author identity.Interface, unixTime int64, message string) (*AddCommentOperation, error) {
|
func AddComment(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (*AddCommentOperation, error) {
|
||||||
return AddCommentWithFiles(b, author, unixTime, message, nil)
|
op := NewAddCommentOp(author, unixTime, message, files)
|
||||||
}
|
for key, val := range metadata {
|
||||||
|
op.SetMetadata(key, val)
|
||||||
func AddCommentWithFiles(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash) (*AddCommentOperation, error) {
|
}
|
||||||
addCommentOp := NewAddCommentOp(author, unixTime, message, files)
|
if err := op.Validate(); err != nil {
|
||||||
if err := addCommentOp.Validate(); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b.Append(addCommentOp)
|
b.Append(op)
|
||||||
return addCommentOp, nil
|
return op, nil
|
||||||
}
|
}
|
||||||
|
@ -97,20 +97,16 @@ type CreateTimelineItem struct {
|
|||||||
// IsAuthored is a sign post method for gqlgen
|
// IsAuthored is a sign post method for gqlgen
|
||||||
func (c *CreateTimelineItem) IsAuthored() {}
|
func (c *CreateTimelineItem) IsAuthored() {}
|
||||||
|
|
||||||
// Convenience function to apply the operation
|
// Create is a convenience function to create a bug
|
||||||
func Create(author identity.Interface, unixTime int64, title, message string) (*Bug, *CreateOperation, error) {
|
func Create(author identity.Interface, unixTime int64, title, message string, files []repository.Hash, metadata map[string]string) (*Bug, *CreateOperation, error) {
|
||||||
return CreateWithFiles(author, unixTime, title, message, nil)
|
b := NewBug()
|
||||||
}
|
op := NewCreateOp(author, unixTime, title, message, files)
|
||||||
|
for key, val := range metadata {
|
||||||
func CreateWithFiles(author identity.Interface, unixTime int64, title, message string, files []repository.Hash) (*Bug, *CreateOperation, error) {
|
op.SetMetadata(key, val)
|
||||||
newBug := NewBug()
|
|
||||||
createOp := NewCreateOp(author, unixTime, title, message, files)
|
|
||||||
|
|
||||||
if err := createOp.Validate(); err != nil {
|
|
||||||
return nil, createOp, err
|
|
||||||
}
|
}
|
||||||
|
if err := op.Validate(); err != nil {
|
||||||
newBug.Append(createOp)
|
return nil, op, err
|
||||||
|
}
|
||||||
return newBug, createOp, nil
|
b.Append(op)
|
||||||
|
return b, op, nil
|
||||||
}
|
}
|
||||||
|
@ -110,27 +110,20 @@ func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.I
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EditComment is a convenience function to apply the operation
|
// EditComment is a convenience function to apply the operation
|
||||||
func EditComment(b Interface, author identity.Interface, unixTime int64, target entity.Id, message string) (*EditCommentOperation, error) {
|
func EditComment(b Interface, author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash, metadata map[string]string) (*EditCommentOperation, error) {
|
||||||
return EditCommentWithFiles(b, author, unixTime, target, message, nil)
|
op := NewEditCommentOp(author, unixTime, target, message, files)
|
||||||
}
|
for key, val := range metadata {
|
||||||
|
op.SetMetadata(key, val)
|
||||||
func EditCommentWithFiles(b Interface, author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash) (*EditCommentOperation, error) {
|
}
|
||||||
editCommentOp := NewEditCommentOp(author, unixTime, target, message, files)
|
if err := op.Validate(); err != nil {
|
||||||
if err := editCommentOp.Validate(); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b.Append(editCommentOp)
|
b.Append(op)
|
||||||
return editCommentOp, nil
|
return op, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditCreateComment is a convenience function to edit the body of a bug (the first comment)
|
// EditCreateComment is a convenience function to edit the body of a bug (the first comment)
|
||||||
func EditCreateComment(b Interface, author identity.Interface, unixTime int64, message string) (*EditCommentOperation, error) {
|
func EditCreateComment(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (*EditCommentOperation, error) {
|
||||||
createOp := b.FirstOp().(*CreateOperation)
|
createOp := b.FirstOp().(*CreateOperation)
|
||||||
return EditComment(b, author, unixTime, createOp.Id(), message)
|
return EditComment(b, author, unixTime, createOp.Id(), message, files, metadata)
|
||||||
}
|
|
||||||
|
|
||||||
// EditCreateCommentWithFiles is a convenience function to edit the body of a bug (the first comment)
|
|
||||||
func EditCreateCommentWithFiles(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash) (*EditCommentOperation, error) {
|
|
||||||
createOp := b.FirstOp().(*CreateOperation)
|
|
||||||
return EditCommentWithFiles(b, author, unixTime, createOp.Id(), message, files)
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func (op *LabelChangeOperation) Id() entity.Id {
|
|||||||
return dag.IdOperation(op, &op.OpBase)
|
return dag.IdOperation(op, &op.OpBase)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply apply the operation
|
// Apply applies the operation
|
||||||
func (op *LabelChangeOperation) Apply(snapshot *Snapshot) {
|
func (op *LabelChangeOperation) Apply(snapshot *Snapshot) {
|
||||||
snapshot.addActor(op.Author())
|
snapshot.addActor(op.Author())
|
||||||
|
|
||||||
@ -113,10 +113,10 @@ func (l LabelChangeTimelineItem) Id() entity.Id {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsAuthored is a sign post method for gqlgen
|
// IsAuthored is a sign post method for gqlgen
|
||||||
func (l *LabelChangeTimelineItem) IsAuthored() {}
|
func (l LabelChangeTimelineItem) IsAuthored() {}
|
||||||
|
|
||||||
// ChangeLabels is a convenience function to apply the operation
|
// ChangeLabels is a convenience function to change labels on a bug
|
||||||
func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string) ([]LabelChangeResult, *LabelChangeOperation, error) {
|
func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) ([]LabelChangeResult, *LabelChangeOperation, error) {
|
||||||
var added, removed []Label
|
var added, removed []Label
|
||||||
var results []LabelChangeResult
|
var results []LabelChangeResult
|
||||||
|
|
||||||
@ -164,23 +164,25 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r
|
|||||||
return results, nil, fmt.Errorf("no label added or removed")
|
return results, nil, fmt.Errorf("no label added or removed")
|
||||||
}
|
}
|
||||||
|
|
||||||
labelOp := NewLabelChangeOperation(author, unixTime, added, removed)
|
op := NewLabelChangeOperation(author, unixTime, added, removed)
|
||||||
|
for key, val := range metadata {
|
||||||
if err := labelOp.Validate(); err != nil {
|
op.SetMetadata(key, val)
|
||||||
|
}
|
||||||
|
if err := op.Validate(); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Append(labelOp)
|
b.Append(op)
|
||||||
|
|
||||||
return results, labelOp, nil
|
return results, op, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForceChangeLabels is a convenience function to apply the operation
|
// ForceChangeLabels is a convenience function to apply the operation
|
||||||
// The difference with ChangeLabels is that no checks of deduplications are done. You are entirely
|
// The difference with ChangeLabels is that no checks of deduplications are done. You are entirely
|
||||||
// responsible of what you are doing. In the general case, you want to use ChangeLabels instead.
|
// 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,
|
// 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.
|
// like removing a label with no information of when it was added before.
|
||||||
func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string) (*LabelChangeOperation, error) {
|
func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) (*LabelChangeOperation, error) {
|
||||||
added := make([]Label, len(add))
|
added := make([]Label, len(add))
|
||||||
for i, str := range add {
|
for i, str := range add {
|
||||||
added[i] = Label(str)
|
added[i] = Label(str)
|
||||||
@ -191,15 +193,18 @@ func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, a
|
|||||||
removed[i] = Label(str)
|
removed[i] = Label(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
labelOp := NewLabelChangeOperation(author, unixTime, added, removed)
|
op := NewLabelChangeOperation(author, unixTime, added, removed)
|
||||||
|
|
||||||
if err := labelOp.Validate(); err != nil {
|
for key, val := range metadata {
|
||||||
|
op.SetMetadata(key, val)
|
||||||
|
}
|
||||||
|
if err := op.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Append(labelOp)
|
b.Append(op)
|
||||||
|
|
||||||
return labelOp, nil
|
return op, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func labelExist(labels []Label, label Label) bool {
|
func labelExist(labels []Label, label Label) bool {
|
||||||
|
@ -10,7 +10,7 @@ func NewSetMetadataOp(author identity.Interface, unixTime int64, target entity.I
|
|||||||
return dag.NewSetMetadataOp[*Snapshot](SetMetadataOp, author, unixTime, target, newMetadata)
|
return dag.NewSetMetadataOp[*Snapshot](SetMetadataOp, author, unixTime, target, newMetadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience function to apply the operation
|
// SetMetadata is a convenience function to add metadata on another operation
|
||||||
func SetMetadata(b Interface, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*Snapshot], error) {
|
func SetMetadata(b Interface, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*Snapshot], error) {
|
||||||
op := NewSetMetadataOp(author, unixTime, target, newMetadata)
|
op := NewSetMetadataOp(author, unixTime, target, newMetadata)
|
||||||
if err := op.Validate(); err != nil {
|
if err := op.Validate(); err != nil {
|
||||||
|
@ -66,11 +66,14 @@ func (s SetStatusTimelineItem) Id() entity.Id {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsAuthored is a sign post method for gqlgen
|
// IsAuthored is a sign post method for gqlgen
|
||||||
func (s *SetStatusTimelineItem) IsAuthored() {}
|
func (s SetStatusTimelineItem) IsAuthored() {}
|
||||||
|
|
||||||
// Convenience function to apply the operation
|
// Open is a convenience function to change a bugs state to Open
|
||||||
func Open(b Interface, author identity.Interface, unixTime int64) (*SetStatusOperation, error) {
|
func Open(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*SetStatusOperation, error) {
|
||||||
op := NewSetStatusOp(author, unixTime, OpenStatus)
|
op := NewSetStatusOp(author, unixTime, OpenStatus)
|
||||||
|
for key, value := range metadata {
|
||||||
|
op.SetMetadata(key, value)
|
||||||
|
}
|
||||||
if err := op.Validate(); err != nil {
|
if err := op.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -78,9 +81,12 @@ func Open(b Interface, author identity.Interface, unixTime int64) (*SetStatusOpe
|
|||||||
return op, nil
|
return op, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience function to apply the operation
|
// Close is a convenience function to change a bugs state to Close
|
||||||
func Close(b Interface, author identity.Interface, unixTime int64) (*SetStatusOperation, error) {
|
func Close(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*SetStatusOperation, error) {
|
||||||
op := NewSetStatusOp(author, unixTime, ClosedStatus)
|
op := NewSetStatusOp(author, unixTime, ClosedStatus)
|
||||||
|
for key, value := range metadata {
|
||||||
|
op.SetMetadata(key, value)
|
||||||
|
}
|
||||||
if err := op.Validate(); err != nil {
|
if err := op.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -80,10 +80,10 @@ func (s SetTitleTimelineItem) Id() entity.Id {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsAuthored is a sign post method for gqlgen
|
// IsAuthored is a sign post method for gqlgen
|
||||||
func (s *SetTitleTimelineItem) IsAuthored() {}
|
func (s SetTitleTimelineItem) IsAuthored() {}
|
||||||
|
|
||||||
// Convenience function to apply the operation
|
// SetTitle is a convenience function to change a bugs title
|
||||||
func SetTitle(b Interface, author identity.Interface, unixTime int64, title string) (*SetTitleOperation, error) {
|
func SetTitle(b Interface, author identity.Interface, unixTime int64, title string, metadata map[string]string) (*SetTitleOperation, error) {
|
||||||
var lastTitleOp *SetTitleOperation
|
var lastTitleOp *SetTitleOperation
|
||||||
for _, op := range b.Operations() {
|
for _, op := range b.Operations() {
|
||||||
switch op := op.(type) {
|
switch op := op.(type) {
|
||||||
@ -99,12 +99,14 @@ func SetTitle(b Interface, author identity.Interface, unixTime int64, title stri
|
|||||||
was = b.FirstOp().(*CreateOperation).Title
|
was = b.FirstOp().(*CreateOperation).Title
|
||||||
}
|
}
|
||||||
|
|
||||||
setTitleOp := NewSetTitleOp(author, unixTime, title, was)
|
op := NewSetTitleOp(author, unixTime, title, was)
|
||||||
|
for key, value := range metadata {
|
||||||
if err := setTitleOp.Validate(); err != nil {
|
op.SetMetadata(key, value)
|
||||||
|
}
|
||||||
|
if err := op.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Append(setTitleOp)
|
b.Append(op)
|
||||||
return setTitleOp, nil
|
return op, nil
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ func TestID(t *testing.T) {
|
|||||||
err = rene.Commit(repo)
|
err = rene.Commit(repo)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
b, op, err := Create(rene, time.Now().Unix(), "title", "message")
|
b, op, err := Create(rene, time.Now().Unix(), "title", "message", nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
id1 := op.Id()
|
id1 := op.Id()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package bug
|
package bug
|
||||||
|
|
||||||
import "github.com/MichaelMure/git-bug/repository"
|
import (
|
||||||
|
"github.com/MichaelMure/git-bug/repository"
|
||||||
|
)
|
||||||
|
|
||||||
var _ Interface = &WithSnapshot{}
|
var _ Interface = &WithSnapshot{}
|
||||||
|
|
||||||
@ -10,11 +12,10 @@ type WithSnapshot struct {
|
|||||||
snap *Snapshot
|
snap *Snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snapshot return the current snapshot
|
func (b *WithSnapshot) Compile() *Snapshot {
|
||||||
func (b *WithSnapshot) Snapshot() *Snapshot {
|
|
||||||
if b.snap == nil {
|
if b.snap == nil {
|
||||||
snap := b.Bug.Compile()
|
snap := b.Bug.Compile()
|
||||||
b.snap = &snap
|
b.snap = snap
|
||||||
}
|
}
|
||||||
return b.snap
|
return b.snap
|
||||||
}
|
}
|
||||||
|
100
cache/bug_cache.go
vendored
100
cache/bug_cache.go
vendored
@ -34,7 +34,7 @@ func NewBugCache(repoCache *RepoCache, b *bug.Bug) *BugCache {
|
|||||||
func (c *BugCache) Snapshot() *bug.Snapshot {
|
func (c *BugCache) Snapshot() *bug.Snapshot {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
defer c.mu.RUnlock()
|
defer c.mu.RUnlock()
|
||||||
return c.bug.Snapshot()
|
return c.bug.Compile()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BugCache) Id() entity.Id {
|
func (c *BugCache) Id() entity.Id {
|
||||||
@ -85,18 +85,11 @@ func (c *BugCache) AddCommentWithFiles(message string, files []repository.Hash)
|
|||||||
|
|
||||||
func (c *BugCache) AddCommentRaw(author *IdentityCache, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (*bug.AddCommentOperation, error) {
|
func (c *BugCache) AddCommentRaw(author *IdentityCache, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (*bug.AddCommentOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.AddCommentWithFiles(c.bug, author.Identity, unixTime, message, files)
|
op, err := bug.AddComment(c.bug, author, unixTime, message, files, metadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
|
|
||||||
return op, c.notifyUpdated()
|
return op, c.notifyUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,24 +104,12 @@ func (c *BugCache) ChangeLabels(added []string, removed []string) ([]bug.LabelCh
|
|||||||
|
|
||||||
func (c *BugCache) ChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) ([]bug.LabelChangeResult, *bug.LabelChangeOperation, error) {
|
func (c *BugCache) ChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) ([]bug.LabelChangeResult, *bug.LabelChangeOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
changes, op, err := bug.ChangeLabels(c.bug, author.Identity, unixTime, added, removed)
|
changes, op, err := bug.ChangeLabels(c.bug, author.Identity, unixTime, added, removed, metadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return changes, nil, err
|
return changes, nil, err
|
||||||
}
|
}
|
||||||
|
return changes, op, c.notifyUpdated()
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
|
|
||||||
err = c.notifyUpdated()
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return changes, op, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.LabelChangeOperation, error) {
|
func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.LabelChangeOperation, error) {
|
||||||
@ -142,23 +123,12 @@ func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.Lab
|
|||||||
|
|
||||||
func (c *BugCache) ForceChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) (*bug.LabelChangeOperation, error) {
|
func (c *BugCache) ForceChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) (*bug.LabelChangeOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.ForceChangeLabels(c.bug, author.Identity, unixTime, added, removed)
|
op, err := bug.ForceChangeLabels(c.bug, author.Identity, unixTime, added, removed, metadata)
|
||||||
if err != nil {
|
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
err = c.notifyUpdated()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return op, c.notifyUpdated()
|
||||||
return op, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BugCache) Open() (*bug.SetStatusOperation, error) {
|
func (c *BugCache) Open() (*bug.SetStatusOperation, error) {
|
||||||
@ -172,17 +142,11 @@ func (c *BugCache) Open() (*bug.SetStatusOperation, error) {
|
|||||||
|
|
||||||
func (c *BugCache) OpenRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
|
func (c *BugCache) OpenRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.Open(c.bug, author.Identity, unixTime)
|
op, err := bug.Open(c.bug, author.Identity, unixTime, metadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
return op, c.notifyUpdated()
|
return op, c.notifyUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,17 +161,11 @@ func (c *BugCache) Close() (*bug.SetStatusOperation, error) {
|
|||||||
|
|
||||||
func (c *BugCache) CloseRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
|
func (c *BugCache) CloseRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.Close(c.bug, author.Identity, unixTime)
|
op, err := bug.Close(c.bug, author.Identity, unixTime, metadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
return op, c.notifyUpdated()
|
return op, c.notifyUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,17 +180,11 @@ func (c *BugCache) SetTitle(title string) (*bug.SetTitleOperation, error) {
|
|||||||
|
|
||||||
func (c *BugCache) SetTitleRaw(author *IdentityCache, unixTime int64, title string, metadata map[string]string) (*bug.SetTitleOperation, error) {
|
func (c *BugCache) SetTitleRaw(author *IdentityCache, unixTime int64, title string, metadata map[string]string) (*bug.SetTitleOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.SetTitle(c.bug, author.Identity, unixTime, title)
|
op, err := bug.SetTitle(c.bug, author.Identity, unixTime, title, metadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
return op, c.notifyUpdated()
|
return op, c.notifyUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,17 +201,11 @@ func (c *BugCache) EditCreateComment(body string) (*bug.EditCommentOperation, er
|
|||||||
// EditCreateCommentRaw is a convenience function to edit the body of a bug (the first comment)
|
// EditCreateCommentRaw is a convenience function to edit the body of a bug (the first comment)
|
||||||
func (c *BugCache) EditCreateCommentRaw(author *IdentityCache, unixTime int64, body string, metadata map[string]string) (*bug.EditCommentOperation, error) {
|
func (c *BugCache) EditCreateCommentRaw(author *IdentityCache, unixTime int64, body string, metadata map[string]string) (*bug.EditCommentOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.EditCreateComment(c.bug, author.Identity, unixTime, body)
|
op, err := bug.EditCreateComment(c.bug, author.Identity, unixTime, body, nil, metadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
return op, c.notifyUpdated()
|
return op, c.notifyUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,17 +220,11 @@ func (c *BugCache) EditComment(target entity.Id, message string) (*bug.EditComme
|
|||||||
|
|
||||||
func (c *BugCache) EditCommentRaw(author *IdentityCache, unixTime int64, target entity.Id, message string, metadata map[string]string) (*bug.EditCommentOperation, error) {
|
func (c *BugCache) EditCommentRaw(author *IdentityCache, unixTime int64, target entity.Id, message string, metadata map[string]string) (*bug.EditCommentOperation, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.EditComment(c.bug, author.Identity, unixTime, target, message)
|
op, err := bug.EditComment(c.bug, author.Identity, unixTime, target, message, nil, metadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
return op, c.notifyUpdated()
|
return op, c.notifyUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,12 +240,10 @@ func (c *BugCache) SetMetadata(target entity.Id, newMetadata map[string]string)
|
|||||||
func (c *BugCache) SetMetadataRaw(author *IdentityCache, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*bug.Snapshot], error) {
|
func (c *BugCache) SetMetadataRaw(author *IdentityCache, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*bug.Snapshot], error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
op, err := bug.SetMetadata(c.bug, author.Identity, unixTime, target, newMetadata)
|
op, err := bug.SetMetadata(c.bug, author.Identity, unixTime, target, newMetadata)
|
||||||
|
c.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.mu.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.mu.Unlock()
|
|
||||||
return op, c.notifyUpdated()
|
return op, c.notifyUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
cache/repo_cache.go
vendored
6
cache/repo_cache.go
vendored
@ -209,9 +209,9 @@ func (c *RepoCache) buildCache() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
snap := b.Bug.Compile()
|
snap := b.Bug.Compile()
|
||||||
c.bugExcerpts[b.Bug.Id()] = NewBugExcerpt(b.Bug, &snap)
|
c.bugExcerpts[b.Bug.Id()] = NewBugExcerpt(b.Bug, snap)
|
||||||
|
|
||||||
if err := c.addBugToSearchIndex(&snap); err != nil {
|
if err := c.addBugToSearchIndex(snap); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +222,7 @@ func (c *RepoCache) buildCache() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// repoIsAvailable check is the given repository is locked by a Cache.
|
// repoIsAvailable check is the given repository is locked by a Cache.
|
||||||
// Note: this is a smart function that will cleanup the lock file if the
|
// Note: this is a smart function that will clean the lock file if the
|
||||||
// corresponding process is not there anymore.
|
// corresponding process is not there anymore.
|
||||||
// If no error is returned, the repo is free to edit.
|
// If no error is returned, the repo is free to edit.
|
||||||
func repoIsAvailable(repo repository.RepoStorage) error {
|
func repoIsAvailable(repo repository.RepoStorage) error {
|
||||||
|
6
cache/repo_cache_bug.go
vendored
6
cache/repo_cache_bug.go
vendored
@ -461,15 +461,11 @@ func (c *RepoCache) NewBugWithFiles(title string, message string, files []reposi
|
|||||||
// well as metadata for the Create operation.
|
// well as metadata for the Create operation.
|
||||||
// The new bug is written in the repository (commit)
|
// The new bug is written in the repository (commit)
|
||||||
func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title string, message string, files []repository.Hash, metadata map[string]string) (*BugCache, *bug.CreateOperation, error) {
|
func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title string, message string, files []repository.Hash, metadata map[string]string) (*BugCache, *bug.CreateOperation, error) {
|
||||||
b, op, err := bug.CreateWithFiles(author.Identity, unixTime, title, message, files)
|
b, op, err := bug.Create(author.Identity, unixTime, title, message, files, metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range metadata {
|
|
||||||
op.SetMetadata(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = b.Commit(c.repo)
|
err = b.Commit(c.repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
4
cache/repo_cache_common.go
vendored
4
cache/repo_cache_common.go
vendored
@ -36,7 +36,7 @@ func (c *RepoCache) Keyring() repository.Keyring {
|
|||||||
return c.repo.Keyring()
|
return c.repo.Keyring()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserName returns the name the the user has used to configure git
|
// GetUserName returns the name the user has used to configure git
|
||||||
func (c *RepoCache) GetUserName() (string, error) {
|
func (c *RepoCache) GetUserName() (string, error) {
|
||||||
return c.repo.GetUserName()
|
return c.repo.GetUserName()
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func (c *RepoCache) MergeAll(remote string) <-chan entity.MergeResult {
|
|||||||
b := result.Entity.(*bug.Bug)
|
b := result.Entity.(*bug.Bug)
|
||||||
snap := b.Compile()
|
snap := b.Compile()
|
||||||
c.muBug.Lock()
|
c.muBug.Lock()
|
||||||
c.bugExcerpts[result.Id] = NewBugExcerpt(b, &snap)
|
c.bugExcerpts[result.Id] = NewBugExcerpt(b, snap)
|
||||||
c.muBug.Unlock()
|
c.muBug.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ func generateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug {
|
|||||||
time.Now().Unix(),
|
time.Now().Unix(),
|
||||||
fake.Sentence(),
|
fake.Sentence(),
|
||||||
paragraphs(),
|
paragraphs(),
|
||||||
|
nil, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -143,19 +144,19 @@ func paragraphs() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func comment(b bug.Interface, p identity.Interface, timestamp int64) {
|
func comment(b bug.Interface, p identity.Interface, timestamp int64) {
|
||||||
_, _ = bug.AddComment(b, p, timestamp, paragraphs())
|
_, _ = bug.AddComment(b, p, timestamp, paragraphs(), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func title(b bug.Interface, p identity.Interface, timestamp int64) {
|
func title(b bug.Interface, p identity.Interface, timestamp int64) {
|
||||||
_, _ = bug.SetTitle(b, p, timestamp, fake.Sentence())
|
_, _ = bug.SetTitle(b, p, timestamp, fake.Sentence(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func open(b bug.Interface, p identity.Interface, timestamp int64) {
|
func open(b bug.Interface, p identity.Interface, timestamp int64) {
|
||||||
_, _ = bug.Open(b, p, timestamp)
|
_, _ = bug.Open(b, p, timestamp, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func close(b bug.Interface, p identity.Interface, timestamp int64) {
|
func close(b bug.Interface, p identity.Interface, timestamp int64) {
|
||||||
_, _ = bug.Close(b, p, timestamp)
|
_, _ = bug.Close(b, p, timestamp, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var addedLabels []string
|
var addedLabels []string
|
||||||
@ -182,5 +183,5 @@ func labels(b bug.Interface, p identity.Interface, timestamp int64) {
|
|||||||
// ignore error
|
// ignore error
|
||||||
// if the randomisation produce no changes, no op
|
// if the randomisation produce no changes, no op
|
||||||
// is added to the bug
|
// is added to the bug
|
||||||
_, _, _ = bug.ChangeLabels(b, p, timestamp, added, removed)
|
_, _, _ = bug.ChangeLabels(b, p, timestamp, added, removed, nil)
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ func (repo *GoGitRepo) Keyring() Keyring {
|
|||||||
return repo.keyring
|
return repo.keyring
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserName returns the name the the user has used to configure git
|
// GetUserName returns the name the user has used to configure git
|
||||||
func (repo *GoGitRepo) GetUserName() (string, error) {
|
func (repo *GoGitRepo) GetUserName() (string, error) {
|
||||||
return repo.AnyConfig().ReadString("user.name")
|
return repo.AnyConfig().ReadString("user.name")
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ type RepoKeyring interface {
|
|||||||
Keyring() Keyring
|
Keyring() Keyring
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoCommon represent the common function the we want all the repo to implement
|
// RepoCommon represent the common function we want all repos to implement
|
||||||
type RepoCommon interface {
|
type RepoCommon interface {
|
||||||
// GetUserName returns the name the the user has used to configure git
|
// GetUserName returns the name the user has used to configure git
|
||||||
GetUserName() (string, error)
|
GetUserName() (string, error)
|
||||||
|
|
||||||
// GetUserEmail returns the email address that the user has used to configure git.
|
// GetUserEmail returns the email address that the user has used to configure git.
|
||||||
|
Loading…
Reference in New Issue
Block a user