-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1889d65
commit 386f3f8
Showing
18 changed files
with
462 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package board | ||
|
||
import ( | ||
"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" | ||
) | ||
|
||
// Fetch retrieve updates from a remote | ||
// This does not change the local board state | ||
func Fetch(repo repository.Repo, remote string) (string, error) { | ||
return dag.Fetch(def, repo, remote) | ||
} | ||
|
||
// Push update a remote with the local changes | ||
func Push(repo repository.Repo, remote string) (string, error) { | ||
return dag.Push(def, repo, remote) | ||
} | ||
|
||
// 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 Pull(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) error { | ||
return dag.Pull(def, repo, resolvers, remote, mergeAuthor) | ||
} | ||
|
||
// MergeAll will merge all the available remote board | ||
// 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 MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) <-chan entity.MergeResult { | ||
out := make(chan entity.MergeResult) | ||
|
||
go func() { | ||
defer close(out) | ||
|
||
results := dag.MergeAll(def, repo, resolvers, remote, mergeAuthor) | ||
|
||
// wrap the dag.Entity into a complete Bug | ||
for result := range results { | ||
result := result | ||
if result.Entity != nil { | ||
result.Entity = &Board{ | ||
Entity: result.Entity.(*dag.Entity), | ||
} | ||
} | ||
out <- result | ||
} | ||
}() | ||
|
||
return out | ||
} | ||
|
||
// Remove will remove a local bug from its entity.Id | ||
func Remove(repo repository.ClockedRepo, id entity.Id) error { | ||
return dag.Remove(def, repo, id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package board | ||
|
||
import ( | ||
"github.com/MichaelMure/git-bug/entities/bug" | ||
"github.com/MichaelMure/git-bug/entity" | ||
) | ||
|
||
var _ Item = &BugItem{} | ||
|
||
type BugItem struct { | ||
combinedId entity.CombinedId | ||
bug bug.Interface | ||
} | ||
|
||
func (e *BugItem) CombinedId() entity.CombinedId { | ||
if e.combinedId == "" || e.combinedId == entity.UnsetCombinedId { | ||
// simply panic as it would be a coding error (no id provided at construction) | ||
panic("no combined id") | ||
} | ||
return e.combinedId | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,101 @@ | ||
package board | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/MichaelMure/git-bug/entities/common" | ||
"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" | ||
"github.com/MichaelMure/git-bug/util/text" | ||
"github.com/MichaelMure/git-bug/util/timestamp" | ||
) | ||
|
||
var _ Operation = &AddItemDraftOperation{} | ||
|
||
type AddItemDraftOperation struct { | ||
dag.OpBase | ||
Title string `json:"title"` | ||
Message string `json:"message"` | ||
ColumnId entity.Id `json:"column"` | ||
Title string `json:"title"` | ||
Message string `json:"message"` | ||
Files []repository.Hash `json:"files"` | ||
} | ||
|
||
func (op *AddItemDraftOperation) Id() entity.Id { | ||
return dag.IdOperation(op, &op.OpBase) | ||
} | ||
|
||
func (op *AddItemDraftOperation) GetFiles() []repository.Hash { | ||
return op.Files | ||
} | ||
|
||
func (op *AddItemDraftOperation) Validate() error { | ||
// TODO implement me | ||
panic("implement me") | ||
if err := op.OpBase.Validate(op, AddItemDraftOp); err != nil { | ||
return err | ||
} | ||
|
||
if err := op.ColumnId.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
if text.Empty(op.Title) { | ||
return fmt.Errorf("title is empty") | ||
} | ||
if !text.SafeOneLine(op.Title) { | ||
return fmt.Errorf("title has unsafe characters") | ||
} | ||
|
||
if !text.Safe(op.Message) { | ||
return fmt.Errorf("message is not fully printable") | ||
} | ||
|
||
for _, file := range op.Files { | ||
if !file.IsValid() { | ||
return fmt.Errorf("invalid file hash") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (op *AddItemDraftOperation) Apply(snapshot *Snapshot) { | ||
// TODO implement me | ||
panic("implement me") | ||
snapshot.addActor(op.Author()) | ||
|
||
for _, column := range snapshot.Columns { | ||
if column.Id == op.ColumnId { | ||
column.Items = append(column.Items, &Draft{ | ||
combinedId: entity.CombineIds(snapshot.id, op.Id()), | ||
author: op.Author(), | ||
status: common.OpenStatus, | ||
title: op.Title, | ||
message: op.Message, | ||
unixTime: timestamp.Timestamp(op.UnixTime), | ||
}) | ||
return | ||
} | ||
} | ||
} | ||
|
||
func NewAddItemDraftOp(author identity.Interface, unixTime int64, columnId entity.Id, title, message string, files []repository.Hash) *AddItemDraftOperation { | ||
return &AddItemDraftOperation{ | ||
OpBase: dag.NewOpBase(AddItemDraftOp, author, unixTime), | ||
ColumnId: columnId, | ||
Title: title, | ||
Message: message, | ||
Files: files, | ||
} | ||
} | ||
|
||
// AddItemDraft is a convenience function to add a draft item to a Board | ||
func AddItemDraft(b *Board, author identity.Interface, unixTime int64, columnId entity.Id, title, message string, files []repository.Hash, metadata map[string]string) (*AddItemDraftOperation, error) { | ||
op := NewAddItemDraftOp(author, unixTime, columnId, title, message, files) | ||
for key, val := range metadata { | ||
op.SetMetadata(key, val) | ||
} | ||
if err := op.Validate(); err != nil { | ||
return nil, err | ||
} | ||
b.Append(op) | ||
return op, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package board | ||
|
||
import ( | ||
"testing" | ||
|
||
"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" | ||
) | ||
|
||
func TestAddItemDraftOpSerialize(t *testing.T) { | ||
dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*AddItemDraftOperation, entity.Resolvers) { | ||
return NewAddItemDraftOp(author, unixTime, "foo", "title", "message", nil), nil | ||
}) | ||
dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*AddItemDraftOperation, entity.Resolvers) { | ||
return NewAddItemDraftOp(author, unixTime, "foo", "title", "message", []repository.Hash{"hash1", "hash2"}), nil | ||
}) | ||
} |
Oops, something went wrong.