aboutsummaryrefslogtreecommitdiffstats
path: root/entities
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-11-29 13:01:53 +0100
committerMichael Muré <batolettre@gmail.com>2022-11-29 13:01:53 +0100
commit4a341b5e1714a6a36ec7f5839a6a1b73571d4851 (patch)
tree261e108d1c9bd78e15e19379f611cfecb900fef5 /entities
parent0ac39a7ab5db077fcf0df827e32bf6e625e980da (diff)
downloadgit-bug-4a341b5e1714a6a36ec7f5839a6a1b73571d4851.tar.gz
WIP
Diffstat (limited to 'entities')
-rw-r--r--entities/bug/bug.go59
-rw-r--r--entities/bug/bug_actions.go23
2 files changed, 21 insertions, 61 deletions
diff --git a/entities/bug/bug.go b/entities/bug/bug.go
index b0f46c0b..4c4a9a74 100644
--- a/entities/bug/bug.go
+++ b/entities/bug/bug.go
@@ -27,6 +27,15 @@ var def = dag.Definition{
FormatVersion: formatVersion,
}
+var Actions = dag.Actions[*Bug]{
+ Wrap: wrapper,
+ New: NewBug,
+ Read: Read,
+ ReadWithResolver: ReadWithResolver,
+ ReadAll: ReadAll,
+ ListLocalIds: ListLocalIds,
+}
+
var ClockLoader = dag.ClockLoader(def)
type Interface interface {
@@ -42,9 +51,11 @@ type Bug struct {
// NewBug create a new Bug
func NewBug() *Bug {
- return &Bug{
- Entity: dag.New(def),
- }
+ return wrapper(dag.New(def))
+}
+
+func wrapper(e *dag.Entity) *Bug {
+ return &Bug{Entity: e}
}
func simpleResolvers(repo repository.ClockedRepo) entity.Resolvers {
@@ -60,49 +71,17 @@ func Read(repo repository.ClockedRepo, id entity.Id) (*Bug, error) {
// ReadWithResolver will read a bug from its Id, with custom resolvers
func ReadWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers, id entity.Id) (*Bug, error) {
- e, err := dag.Read(def, repo, resolvers, id)
- if err != nil {
- return nil, err
- }
- return &Bug{Entity: e}, nil
-}
-
-type StreamedBug struct {
- Bug *Bug
- Err error
+ return dag.Read(def, wrapper, repo, resolvers, id)
}
// ReadAll read and parse all local bugs
-func ReadAll(repo repository.ClockedRepo) <-chan StreamedBug {
- return readAll(repo, simpleResolvers(repo))
+func ReadAll(repo repository.ClockedRepo) <-chan dag.StreamedEntity[*Bug] {
+ return dag.ReadAll(def, wrapper, repo, simpleResolvers(repo))
}
// ReadAllWithResolver read and parse all local bugs
-func ReadAllWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers) <-chan StreamedBug {
- return readAll(repo, resolvers)
-}
-
-// Read and parse all available bug with a given ref prefix
-func readAll(repo repository.ClockedRepo, resolvers entity.Resolvers) <-chan StreamedBug {
- out := make(chan StreamedBug)
-
- go func() {
- defer close(out)
-
- for streamedEntity := range dag.ReadAll(def, repo, resolvers) {
- if streamedEntity.Err != nil {
- out <- StreamedBug{
- Err: streamedEntity.Err,
- }
- } else {
- out <- StreamedBug{
- Bug: &Bug{Entity: streamedEntity.Entity},
- }
- }
- }
- }()
-
- return out
+func ReadAllWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers) <-chan dag.StreamedEntity[*Bug] {
+ return dag.ReadAll(def, wrapper, repo, resolvers)
}
// ListLocalIds list all the available local bug ids
diff --git a/entities/bug/bug_actions.go b/entities/bug/bug_actions.go
index c25b9243..198e4ed0 100644
--- a/entities/bug/bug_actions.go
+++ b/entities/bug/bug_actions.go
@@ -23,33 +23,14 @@ func Push(repo repository.Repo, remote string) (string, error) {
// 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)
+ return dag.Pull(def, wrapper, repo, resolvers, remote, mergeAuthor)
}
// 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 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 = &Bug{
- Entity: result.Entity.(*dag.Entity),
- }
- }
- out <- result
- }
- }()
-
- return out
+ return dag.MergeAll(def, wrapper, repo, resolvers, remote, mergeAuthor)
}
// Remove will remove a local bug from its entity.Id