Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/graphql/models/lazy_bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (lb *lazyBug) load() error {
return err
}

lb.snap = b.Snapshot()
lb.snap = b.Compile()
return nil
}

Expand Down
18 changes: 9 additions & 9 deletions api/graphql/resolvers/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r mutationResolver) NewBug(ctx context.Context, input models.NewBugInput)

return &models.NewBugPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
Operation: op,
}, nil
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func (r mutationResolver) AddComment(ctx context.Context, input models.AddCommen

return &models.AddCommentPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
Operation: op,
}, nil
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (r mutationResolver) AddCommentAndClose(ctx context.Context, input models.A

return &models.AddCommentAndCloseBugPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
CommentOperation: opAddComment,
StatusOperation: opClose,
}, nil
Expand Down Expand Up @@ -169,7 +169,7 @@ func (r mutationResolver) AddCommentAndReopen(ctx context.Context, input models.

return &models.AddCommentAndReopenBugPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
CommentOperation: opAddComment,
StatusOperation: opReopen,
}, nil
Expand Down Expand Up @@ -209,7 +209,7 @@ func (r mutationResolver) EditComment(ctx context.Context, input models.EditComm

return &models.EditCommentPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
Operation: op,
}, nil
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func (r mutationResolver) ChangeLabels(ctx context.Context, input *models.Change

return &models.ChangeLabelPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
Operation: op,
Results: resultsPtr,
}, nil
Expand Down Expand Up @@ -277,7 +277,7 @@ func (r mutationResolver) OpenBug(ctx context.Context, input models.OpenBugInput

return &models.OpenBugPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
Operation: op,
}, nil
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func (r mutationResolver) CloseBug(ctx context.Context, input models.CloseBugInp

return &models.CloseBugPayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
Operation: op,
}, nil
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func (r mutationResolver) SetTitle(ctx context.Context, input models.SetTitleInp

return &models.SetTitlePayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
Bug: models.NewLoadedBug(b.Compile()),
Operation: op,
}, nil
}
4 changes: 2 additions & 2 deletions bridge/github/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (ge *githubExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
return

default:
snapshot := b.Snapshot()
snapshot := b.Compile()

// ignore issues created before since date
// TODO: compare the Lamport time instead of using the unix time
Expand All @@ -197,7 +197,7 @@ func (ge *githubExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,

// exportBug publish bugs and related events
func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, out chan<- core.ExportResult) {
snapshot := b.Snapshot()
snapshot := b.Compile()
var bugUpdated bool

var bugGithubID string
Expand Down
10 changes: 5 additions & 5 deletions bridge/github/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ func TestGithubPushPull(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
// for each operation a SetMetadataOperation will be added
// so number of operations should double
require.Len(t, tt.bug.Snapshot().Operations, tt.numOrOp*2)
require.Len(t, tt.bug.Compile().Operations, tt.numOrOp*2)

// verify operation have correct metadata
for _, op := range tt.bug.Snapshot().Operations {
for _, op := range tt.bug.Compile().Operations {
// Check if the originals operations (*not* SetMetadata) are tagged properly
if _, ok := op.(dag.OperationDoesntChangeSnapshot); !ok {
_, haveIDMetadata := op.GetMetadata(metaKeyGithubId)
Expand All @@ -264,18 +264,18 @@ func TestGithubPushPull(t *testing.T) {
}

// get bug github ID
bugGithubID, ok := tt.bug.Snapshot().GetCreateMetadata(metaKeyGithubId)
bugGithubID, ok := tt.bug.Compile().GetCreateMetadata(metaKeyGithubId)
require.True(t, ok)

// retrieve bug from backendTwo
importedBug, err := backendTwo.Bugs().ResolveBugCreateMetadata(metaKeyGithubId, bugGithubID)
require.NoError(t, err)

// verify bug have same number of original operations
require.Len(t, importedBug.Snapshot().Operations, tt.numOrOp)
require.Len(t, importedBug.Compile().Operations, tt.numOrOp)

// verify bugs are tagged with origin=github
issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.MetaKeyOrigin)
issueOrigin, ok := importedBug.Compile().GetCreateMetadata(core.MetaKeyOrigin)
require.True(t, ok)
require.Equal(t, issueOrigin, target)

Expand Down
6 changes: 3 additions & 3 deletions bridge/github/import_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ func TestGithubImporterIntegration(t *testing.T) {

b1, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/1")
require.NoError(t, err)
ops1 := b1.Snapshot().Operations
ops1 := b1.Compile().Operations
require.Equal(t, "marcus", ops1[0].Author().Name())
require.Equal(t, "title 1", ops1[0].(*bug.CreateOperation).Title)
require.Equal(t, "body text 1", ops1[0].(*bug.CreateOperation).Message)

b3, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/3")
require.NoError(t, err)
ops3 := b3.Snapshot().Operations
ops3 := b3.Compile().Operations
require.Equal(t, "issue 3 comment 1", ops3[1].(*bug.AddCommentOperation).Message)
require.Equal(t, "issue 3 comment 2", ops3[2].(*bug.AddCommentOperation).Message)
require.Equal(t, []bug.Label{"bug"}, ops3[3].(*bug.LabelChangeOperation).Added)
require.Equal(t, "title 3, edit 1", ops3[4].(*bug.SetTitleOperation).Title)

b4, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/4")
require.NoError(t, err)
ops4 := b4.Snapshot().Operations
ops4 := b4.Compile().Operations
require.Equal(t, "edited", ops4[1].(*bug.EditCommentOperation).Message)

}
Expand Down
4 changes: 2 additions & 2 deletions bridge/github/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ func TestGithubImporter(t *testing.T) {
b, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, tt.url)
require.NoError(t, err)

ops := b.Snapshot().Operations
require.Len(t, tt.bug.Operations, len(b.Snapshot().Operations))
ops := b.Compile().Operations
require.Len(t, tt.bug.Operations, len(b.Compile().Operations))

for i, op := range tt.bug.Operations {
require.IsType(t, ops[i], op)
Expand Down
4 changes: 2 additions & 2 deletions bridge/gitlab/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (ge *gitlabExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
return
}

snapshot := b.Snapshot()
snapshot := b.Compile()

// ignore issues created before since date
// TODO: compare the Lamport time instead of using the unix time
Expand All @@ -150,7 +150,7 @@ func (ge *gitlabExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,

// exportBug publish bugs and related events
func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, out chan<- core.ExportResult) {
snapshot := b.Snapshot()
snapshot := b.Compile()

var bugUpdated bool
var err error
Expand Down
10 changes: 5 additions & 5 deletions bridge/gitlab/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ func TestGitlabPushPull(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
// for each operation a SetMetadataOperation will be added
// so number of operations should double
require.Len(t, tt.bug.Snapshot().Operations, tt.numOpExp)
require.Len(t, tt.bug.Compile().Operations, tt.numOpExp)

// verify operation have correct metadata
for _, op := range tt.bug.Snapshot().Operations {
for _, op := range tt.bug.Compile().Operations {
// Check if the originals operations (*not* SetMetadata) are tagged properly
if _, ok := op.(dag.OperationDoesntChangeSnapshot); !ok {
_, haveIDMetadata := op.GetMetadata(metaKeyGitlabId)
Expand All @@ -260,18 +260,18 @@ func TestGitlabPushPull(t *testing.T) {
}

// get bug gitlab ID
bugGitlabID, ok := tt.bug.Snapshot().GetCreateMetadata(metaKeyGitlabId)
bugGitlabID, ok := tt.bug.Compile().GetCreateMetadata(metaKeyGitlabId)
require.True(t, ok)

// retrieve bug from backendTwo
importedBug, err := backendTwo.Bugs().ResolveBugCreateMetadata(metaKeyGitlabId, bugGitlabID)
require.NoError(t, err)

// verify bug have same number of original operations
require.Len(t, importedBug.Snapshot().Operations, tt.numOpImp)
require.Len(t, importedBug.Compile().Operations, tt.numOpImp)

// verify bugs are tagged with origin=gitlab
issueOrigin, ok := importedBug.Snapshot().GetCreateMetadata(core.MetaKeyOrigin)
issueOrigin, ok := importedBug.Compile().GetCreateMetadata(core.MetaKeyOrigin)
require.True(t, ok)
require.Equal(t, issueOrigin, target)

Expand Down
4 changes: 2 additions & 2 deletions bridge/gitlab/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (gi *gitlabImporter) ensureIssueEvent(repo *cache.RepoCache, b *cache.BugCa
gi.out <- core.NewImportStatusChange(b.Id(), op.Id())

case EventDescriptionChanged:
firstComment := b.Snapshot().Comments[0]
firstComment := b.Compile().Comments[0]
// since gitlab doesn't provide the issue history
// we should check for "changed the description" notes and compare issue texts
// TODO: Check only one time and ignore next 'description change' within one issue
Expand Down Expand Up @@ -247,7 +247,7 @@ func (gi *gitlabImporter) ensureIssueEvent(repo *cache.RepoCache, b *cache.BugCa
// if comment was already exported

// search for last comment update
comment, err := b.Snapshot().SearchCommentByOpId(id)
comment, err := b.Compile().SearchCommentByOpId(id)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion bridge/gitlab/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestGitlabImport(t *testing.T) {
b, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGitlabUrl, tt.url)
require.NoError(t, err)

ops := b.Snapshot().Operations
ops := b.Compile().Operations
require.Len(t, tt.bug.Operations, len(ops))

for i, op := range tt.bug.Operations {
Expand Down
4 changes: 2 additions & 2 deletions bridge/jira/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (je *jiraExporter) ExportAll(ctx context.Context, repo *cache.RepoCache, si
return

default:
snapshot := b.Snapshot()
snapshot := b.Compile()

// ignore issues whose last modification date is before the query date
// TODO: compare the Lamport time instead of using the unix time
Expand Down Expand Up @@ -189,7 +189,7 @@ func (je *jiraExporter) ExportAll(ctx context.Context, repo *cache.RepoCache, si

// exportBug publish bugs and related events
func (je *jiraExporter) exportBug(ctx context.Context, b *cache.BugCache, out chan<- core.ExportResult) error {
snapshot := b.Snapshot()
snapshot := b.Compile()

var bugJiraID string

Expand Down
4 changes: 2 additions & 2 deletions bridge/jira/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (ji *jiraImporter) ImportAll(ctx context.Context, repo *cache.RepoCache, si
out <- core.NewImportError(commentIter.Err, "")
}

snapshot := b.Snapshot()
snapshot := b.Compile()
opIdx := 0

var changelogIter *ChangeLogIterator
Expand Down Expand Up @@ -466,7 +466,7 @@ func (ji *jiraImporter) ensureChange(repo *cache.RepoCache, b *cache.BugCache, e
// title but it's actually the body
opr, isRightType := potentialOp.(*bug.EditCommentOperation)
if isRightType &&
opr.Target == b.Snapshot().Operations[0].Id() &&
opr.Target == b.Compile().Operations[0].Id() &&
opr.Message == item.ToString {
_, err := b.SetMetadata(opr.Id(), map[string]string{
metaKeyJiraDerivedId: entry.ID,
Expand Down
23 changes: 12 additions & 11 deletions cache/bug_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"time"

"github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
"github.com/MichaelMure/git-bug/repository"
)

var ErrNoMatchingOp = fmt.Errorf("no matching operation found")

var _ bug.Interface = &BugCache{}

// BugCache is a wrapper around a Bug. It provides multiple functions:
//
// 1. Provide a higher level API to use than the raw API from Bug.
Expand Down Expand Up @@ -46,7 +47,7 @@ func (c *BugCache) AddCommentWithFiles(message string, files []repository.Hash)
return c.AddCommentRaw(author, time.Now().Unix(), message, files, nil)
}

func (c *BugCache) AddCommentRaw(author identity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *bug.AddCommentOperation, error) {
func (c *BugCache) AddCommentRaw(author entity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *bug.AddCommentOperation, error) {
c.mu.Lock()
commentId, op, err := bug.AddComment(c.entity, author, unixTime, message, files, metadata)
c.mu.Unlock()
Expand All @@ -65,7 +66,7 @@ func (c *BugCache) ChangeLabels(added []string, removed []string) ([]bug.LabelCh
return c.ChangeLabelsRaw(author, time.Now().Unix(), added, removed, nil)
}

func (c *BugCache) ChangeLabelsRaw(author identity.Interface, unixTime int64, added []string, removed []string, metadata map[string]string) ([]bug.LabelChangeResult, *bug.LabelChangeOperation, error) {
func (c *BugCache) ChangeLabelsRaw(author entity.Interface, unixTime int64, added []string, removed []string, metadata map[string]string) ([]bug.LabelChangeResult, *bug.LabelChangeOperation, error) {
c.mu.Lock()
changes, op, err := bug.ChangeLabels(c.entity, author, unixTime, added, removed, metadata)
c.mu.Unlock()
Expand All @@ -84,7 +85,7 @@ func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.Lab
return c.ForceChangeLabelsRaw(author, time.Now().Unix(), added, removed, nil)
}

func (c *BugCache) ForceChangeLabelsRaw(author identity.Interface, unixTime int64, added []string, removed []string, metadata map[string]string) (*bug.LabelChangeOperation, error) {
func (c *BugCache) ForceChangeLabelsRaw(author entity.Interface, unixTime int64, added []string, removed []string, metadata map[string]string) (*bug.LabelChangeOperation, error) {
c.mu.Lock()
op, err := bug.ForceChangeLabels(c.entity, author, unixTime, added, removed, metadata)
c.mu.Unlock()
Expand All @@ -103,7 +104,7 @@ func (c *BugCache) Open() (*bug.SetStatusOperation, error) {
return c.OpenRaw(author, time.Now().Unix(), nil)
}

func (c *BugCache) OpenRaw(author identity.Interface, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
func (c *BugCache) OpenRaw(author entity.Interface, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
c.mu.Lock()
op, err := bug.Open(c.entity, author, unixTime, metadata)
c.mu.Unlock()
Expand All @@ -122,7 +123,7 @@ func (c *BugCache) Close() (*bug.SetStatusOperation, error) {
return c.CloseRaw(author, time.Now().Unix(), nil)
}

func (c *BugCache) CloseRaw(author identity.Interface, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
func (c *BugCache) CloseRaw(author entity.Interface, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error) {
c.mu.Lock()
op, err := bug.Close(c.entity, author, unixTime, metadata)
c.mu.Unlock()
Expand All @@ -141,7 +142,7 @@ func (c *BugCache) SetTitle(title string) (*bug.SetTitleOperation, error) {
return c.SetTitleRaw(author, time.Now().Unix(), title, nil)
}

func (c *BugCache) SetTitleRaw(author identity.Interface, unixTime int64, title string, metadata map[string]string) (*bug.SetTitleOperation, error) {
func (c *BugCache) SetTitleRaw(author entity.Interface, unixTime int64, title string, metadata map[string]string) (*bug.SetTitleOperation, error) {
c.mu.Lock()
op, err := bug.SetTitle(c.entity, author, unixTime, title, metadata)
c.mu.Unlock()
Expand All @@ -162,7 +163,7 @@ func (c *BugCache) EditCreateComment(body string) (entity.CombinedId, *bug.EditC
}

// EditCreateCommentRaw is a convenience function to edit the body of a bug (the first comment)
func (c *BugCache) EditCreateCommentRaw(author identity.Interface, unixTime int64, body string, metadata map[string]string) (entity.CombinedId, *bug.EditCommentOperation, error) {
func (c *BugCache) EditCreateCommentRaw(author entity.Interface, unixTime int64, body string, metadata map[string]string) (entity.CombinedId, *bug.EditCommentOperation, error) {
c.mu.Lock()
commentId, op, err := bug.EditCreateComment(c.entity, author, unixTime, body, nil, metadata)
c.mu.Unlock()
Expand All @@ -181,8 +182,8 @@ func (c *BugCache) EditComment(target entity.CombinedId, message string) (*bug.E
return c.EditCommentRaw(author, time.Now().Unix(), target, message, nil)
}

func (c *BugCache) EditCommentRaw(author identity.Interface, unixTime int64, target entity.CombinedId, message string, metadata map[string]string) (*bug.EditCommentOperation, error) {
comment, err := c.Snapshot().SearchComment(target)
func (c *BugCache) EditCommentRaw(author entity.Interface, unixTime int64, target entity.CombinedId, message string, metadata map[string]string) (*bug.EditCommentOperation, error) {
comment, err := c.Compile().SearchComment(target)
if err != nil {
return nil, err
}
Expand All @@ -208,7 +209,7 @@ func (c *BugCache) SetMetadata(target entity.Id, newMetadata map[string]string)
return c.SetMetadataRaw(author, time.Now().Unix(), target, newMetadata)
}

func (c *BugCache) SetMetadataRaw(author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*bug.Snapshot], error) {
func (c *BugCache) SetMetadataRaw(author entity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*bug.Snapshot], error) {
c.mu.Lock()
op, err := bug.SetMetadata(c.entity, author, unixTime, target, newMetadata)
c.mu.Unlock()
Expand Down
Loading