Skip to content

Commit 1e02465

Browse files
committed
Move Comment into separate package
1 parent 6bfb32c commit 1e02465

18 files changed

Lines changed: 118 additions & 106 deletions

File tree

api/graphql/connections/connections.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//go:generate genny -in=connection_template.go -out=gen_lazy_identity.go gen "Name=LazyIdentity NodeType=entity.Id EdgeType=LazyIdentityEdge ConnectionType=models.IdentityConnection"
33
//go:generate genny -in=connection_template.go -out=gen_identity.go gen "Name=Identity NodeType=models.IdentityWrapper EdgeType=models.IdentityEdge ConnectionType=models.IdentityConnection"
44
//go:generate genny -in=connection_template.go -out=gen_operation.go gen "Name=Operation NodeType=bug.Operation EdgeType=models.OperationEdge ConnectionType=models.OperationConnection"
5-
//go:generate genny -in=connection_template.go -out=gen_comment.go gen "Name=Comment NodeType=bug.Comment EdgeType=models.CommentEdge ConnectionType=models.CommentConnection"
5+
//go:generate genny -in=connection_template.go -out=gen_comment.go gen "Name=Comment NodeType=commentary.Comment EdgeType=models.CommentEdge ConnectionType=models.CommentConnection"
66
//go:generate genny -in=connection_template.go -out=gen_timeline.go gen "Name=TimelineItem NodeType=bug.TimelineItem EdgeType=models.TimelineItemEdge ConnectionType=models.TimelineItemConnection"
77
//go:generate genny -in=connection_template.go -out=gen_label.go gen "Name=Label NodeType=bug.Label EdgeType=models.LabelEdge ConnectionType=models.LabelConnection"
88

api/graphql/connections/gen_comment.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import (
88
"fmt"
99

1010
"github.com/MichaelMure/git-bug/api/graphql/models"
11-
"github.com/MichaelMure/git-bug/bug"
11+
"github.com/MichaelMure/git-bug/commentary"
1212
)
1313

14-
// BugCommentEdgeMaker define a function that take a bug.Comment and an offset and
14+
// CommentaryCommentEdgeMaker define a function that take a commentary.Comment and an offset and
1515
// create an Edge.
16-
type CommentEdgeMaker func(value bug.Comment, offset int) Edge
16+
type CommentEdgeMaker func(value commentary.Comment, offset int) Edge
1717

1818
// CommentConMaker define a function that create a models.CommentConnection
1919
type CommentConMaker func(
2020
edges []*models.CommentEdge,
21-
nodes []bug.Comment,
21+
nodes []commentary.Comment,
2222
info *models.PageInfo,
2323
totalCount int) (*models.CommentConnection, error)
2424

2525
// CommentCon will paginate a source according to the input of a relay connection
26-
func CommentCon(source []bug.Comment, edgeMaker CommentEdgeMaker, conMaker CommentConMaker, input models.ConnectionInput) (*models.CommentConnection, error) {
27-
var nodes []bug.Comment
26+
func CommentCon(source []commentary.Comment, edgeMaker CommentEdgeMaker, conMaker CommentConMaker, input models.ConnectionInput) (*models.CommentConnection, error) {
27+
var nodes []commentary.Comment
2828
var edges []*models.CommentEdge
2929
var cursors []string
3030
var pageInfo = &models.PageInfo{}

api/graphql/gqlgen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ models:
2525
Color:
2626
model: image/color.RGBA
2727
Comment:
28-
model: github.com/MichaelMure/git-bug/bug.Comment
28+
model: github.com/MichaelMure/git-bug/commentary.Comment
2929
Alteration:
30-
model: github.com/MichaelMure/git-bug/bug.Alteration
30+
model: github.com/MichaelMure/git-bug/commentary.Alteration
3131
Identity:
3232
model: github.com/MichaelMure/git-bug/api/graphql/models.IdentityWrapper
3333
Label:

api/graphql/graph/gen_graph.go

Lines changed: 42 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/graphql/models/gen_models.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/graphql/models/lazy_bug.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/MichaelMure/git-bug/bug"
88
"github.com/MichaelMure/git-bug/cache"
9+
"github.com/MichaelMure/git-bug/commentary"
910
"github.com/MichaelMure/git-bug/entity"
1011
)
1112

@@ -17,8 +18,8 @@ type BugWrapper interface {
1718
LastEdit() time.Time
1819
Status() bug.Status
1920
Title() string
20-
Description() (*bug.Comment, error)
21-
Comments() ([]bug.Comment, error)
21+
Description() (*commentary.Comment, error)
22+
Comments() ([]commentary.Comment, error)
2223
Labels() []bug.Label
2324
Author() (IdentityWrapper, error)
2425
Actors() ([]IdentityWrapper, error)
@@ -93,7 +94,7 @@ func (lb *lazyBug) Title() string {
9394
return lb.excerpt.Title
9495
}
9596

96-
func (lb *lazyBug) Description() (*bug.Comment, error) {
97+
func (lb *lazyBug) Description() (*commentary.Comment, error) {
9798
err := lb.load()
9899
if err != nil {
99100
return nil, err
@@ -102,7 +103,7 @@ func (lb *lazyBug) Description() (*bug.Comment, error) {
102103
return &desc, nil
103104
}
104105

105-
func (lb *lazyBug) Comments() ([]bug.Comment, error) {
106+
func (lb *lazyBug) Comments() ([]commentary.Comment, error) {
106107
err := lb.load()
107108
if err != nil {
108109
return nil, err
@@ -184,12 +185,12 @@ func (l *loadedBug) Title() string {
184185
return l.Snapshot.Title()
185186
}
186187

187-
func (l *loadedBug) Description() (*bug.Comment, error) {
188+
func (l *loadedBug) Description() (*commentary.Comment, error) {
188189
desc := l.Snapshot.Description()
189190
return &desc, nil
190191
}
191192

192-
func (l *loadedBug) Comments() ([]bug.Comment, error) {
193+
func (l *loadedBug) Comments() ([]commentary.Comment, error) {
193194
return l.Snapshot.Comments(), nil
194195
}
195196

api/graphql/resolvers/bug.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/MichaelMure/git-bug/api/graphql/graph"
88
"github.com/MichaelMure/git-bug/api/graphql/models"
99
"github.com/MichaelMure/git-bug/bug"
10+
"github.com/MichaelMure/git-bug/commentary"
1011
)
1112

1213
var _ graph.BugResolver = &bugResolver{}
@@ -33,15 +34,15 @@ func (bugResolver) Comments(_ context.Context, obj models.BugWrapper, after *str
3334
Last: last,
3435
}
3536

36-
edger := func(comment bug.Comment, offset int) connections.Edge {
37+
edger := func(comment commentary.Comment, offset int) connections.Edge {
3738
return models.CommentEdge{
3839
Node: &comment,
3940
Cursor: connections.OffsetToCursor(offset),
4041
}
4142
}
4243

43-
conMaker := func(edges []*models.CommentEdge, nodes []bug.Comment, info *models.PageInfo, totalCount int) (*models.CommentConnection, error) {
44-
var commentNodes []*bug.Comment
44+
conMaker := func(edges []*models.CommentEdge, nodes []commentary.Comment, info *models.PageInfo, totalCount int) (*models.CommentConnection, error) {
45+
var commentNodes []*commentary.Comment
4546
for _, c := range nodes {
4647
commentNodes = append(commentNodes, &c)
4748
}

api/graphql/resolvers/comment.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
"github.com/MichaelMure/git-bug/api/graphql/graph"
88
"github.com/MichaelMure/git-bug/api/graphql/models"
9-
"github.com/MichaelMure/git-bug/bug"
109
"github.com/MichaelMure/git-bug/cache"
10+
"github.com/MichaelMure/git-bug/commentary"
1111
"github.com/MichaelMure/git-bug/entity"
1212
"github.com/MichaelMure/git-bug/repository"
1313
)
@@ -16,7 +16,7 @@ var _ graph.AlterationResolver = alterationResolver{}
1616

1717
type alterationResolver struct{}
1818

19-
func (alterationResolver) Date(_ context.Context, obj *bug.Alteration) (*time.Time, error) {
19+
func (alterationResolver) Date(_ context.Context, obj *commentary.Alteration) (*time.Time, error) {
2020
t := obj.CreatedAt.Time()
2121
return &t, nil
2222
}
@@ -29,7 +29,7 @@ type commentResolver struct {
2929

3030
// getComment is a helper function to fetch a comment with the given Id from
3131
// the repository.
32-
func (r commentResolver) getComment(id entity.Id) (*bug.Comment, error) {
32+
func (r commentResolver) getComment(id entity.Id) (*commentary.Comment, error) {
3333
var repo, err = r.cache.DefaultRepo()
3434
if err != nil {
3535
return nil, err
@@ -42,19 +42,19 @@ func (r commentResolver) getComment(id entity.Id) (*bug.Comment, error) {
4242
return bug.Snapshot().SearchComment(commentId)
4343
}
4444

45-
func (commentResolver) ID(_ context.Context, obj *bug.Comment) (string, error) {
45+
func (commentResolver) ID(_ context.Context, obj *commentary.Comment) (string, error) {
4646
return obj.Id().String(), nil
4747
}
4848

49-
func (r commentResolver) Author(_ context.Context, obj *bug.Comment) (models.IdentityWrapper, error) {
49+
func (r commentResolver) Author(_ context.Context, obj *commentary.Comment) (models.IdentityWrapper, error) {
5050
comment, err := r.getComment(obj.Id())
5151
if err != nil {
5252
return nil, err
5353
}
5454
return models.NewLoadedIdentity(comment.Author()), nil
5555
}
5656

57-
func (r commentResolver) CreatedAt(_ context.Context, obj *bug.Comment) (*time.Time, error) {
57+
func (r commentResolver) CreatedAt(_ context.Context, obj *commentary.Comment) (*time.Time, error) {
5858
comment, err := r.getComment(obj.Id())
5959
if err != nil {
6060
return nil, err
@@ -63,7 +63,7 @@ func (r commentResolver) CreatedAt(_ context.Context, obj *bug.Comment) (*time.T
6363
return &t, nil
6464
}
6565

66-
func (r commentResolver) LastEdited(_ context.Context, obj *bug.Comment) (*time.Time, error) {
66+
func (r commentResolver) LastEdited(_ context.Context, obj *commentary.Comment) (*time.Time, error) {
6767
comment, err := r.getComment(obj.Id())
6868
if err != nil {
6969
return nil, err
@@ -72,39 +72,39 @@ func (r commentResolver) LastEdited(_ context.Context, obj *bug.Comment) (*time.
7272
return &t, nil
7373
}
7474

75-
func (r commentResolver) WasEdited(_ context.Context, obj *bug.Comment) (bool, error) {
75+
func (r commentResolver) WasEdited(_ context.Context, obj *commentary.Comment) (bool, error) {
7676
comment, err := r.getComment(obj.Id())
7777
if err != nil {
7878
return false, err
7979
}
8080
return comment.WasEdited(), nil
8181
}
8282

83-
func (r commentResolver) Message(_ context.Context, obj *bug.Comment) (string, error) {
83+
func (r commentResolver) Message(_ context.Context, obj *commentary.Comment) (string, error) {
8484
comment, err := r.getComment(obj.Id())
8585
if err != nil {
8686
return "", err
8787
}
8888
return comment.Message(), nil
8989
}
9090

91-
func (r commentResolver) HasEmptyMessage(_ context.Context, obj *bug.Comment) (bool, error) {
91+
func (r commentResolver) HasEmptyMessage(_ context.Context, obj *commentary.Comment) (bool, error) {
9292
comment, err := r.getComment(obj.Id())
9393
if err != nil {
9494
return false, err
9595
}
9696
return comment.HasEmptyMessage(), nil
9797
}
9898

99-
func (r commentResolver) Files(_ context.Context, obj *bug.Comment) ([]repository.Hash, error) {
99+
func (r commentResolver) Files(_ context.Context, obj *commentary.Comment) ([]repository.Hash, error) {
100100
comment, err := r.getComment(obj.Id())
101101
if err != nil {
102102
return nil, err
103103
}
104104
return comment.Files(), nil
105105
}
106106

107-
func (r commentResolver) History(_ context.Context, obj *bug.Comment) ([]*bug.Alteration, error) {
107+
func (r commentResolver) History(_ context.Context, obj *commentary.Comment) ([]*commentary.Alteration, error) {
108108
comment, err := r.getComment(obj.Id())
109109
if err != nil {
110110
return nil, err
@@ -113,7 +113,7 @@ func (r commentResolver) History(_ context.Context, obj *bug.Comment) ([]*bug.Al
113113
// to type of []*Alteration. This is due to the gqlgen generated
114114
// the code, which expects a slice of pointers as return. Don't know how
115115
// to fix this otherwise *sigh*
116-
history := make([]*bug.Alteration, len(comment.History()))
116+
history := make([]*commentary.Alteration, len(comment.History()))
117117
for edit := range comment.History() {
118118
history[edit] = &comment.History()[edit]
119119
}

api/graphql/resolvers/timeline.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/MichaelMure/git-bug/api/graphql/graph"
88
"github.com/MichaelMure/git-bug/api/graphql/models"
99
"github.com/MichaelMure/git-bug/bug"
10+
"github.com/MichaelMure/git-bug/commentary"
1011
"github.com/MichaelMure/git-bug/entity"
1112
"github.com/MichaelMure/git-bug/repository"
1213
)
@@ -17,7 +18,7 @@ type commentTimelineItemResolver struct {
1718
commentResolver
1819
}
1920

20-
func (r commentTimelineItemResolver) getComment(id entity.Id) (*bug.Comment, error) {
21+
func (r commentTimelineItemResolver) getComment(id entity.Id) (*commentary.Comment, error) {
2122
return r.commentResolver.getComment(id)
2223
}
2324

@@ -83,16 +84,16 @@ func (r commentTimelineItemResolver) Files(_ context.Context, obj *bug.CommentTi
8384
return comment.Files(), nil
8485
}
8586

86-
func (r commentTimelineItemResolver) History(_ context.Context, obj *bug.CommentTimelineItem) ([]*bug.Alteration, error) {
87+
func (r commentTimelineItemResolver) History(_ context.Context, obj *bug.CommentTimelineItem) ([]*commentary.Alteration, error) {
8788
comment, err := r.getComment(obj.Id())
8889
if err != nil {
8990
return nil, err
9091
}
91-
// NOTE have to convert the comment history of type []Alteration
92-
// to type of []*Alteration. This is due to the gqlgen generated
92+
// NOTE have to convert the comment history of type []commentary.Alteration
93+
// to type of []*commentary.Alteration. This is due to the gqlgen generated
9394
// the code, which expects a slice of pointers as return. Don't know how
9495
// to fix this otherwise *sigh*
95-
history := make([]*bug.Alteration, len(comment.History()))
96+
history := make([]*commentary.Alteration, len(comment.History()))
9697
for edit := range comment.History() {
9798
history[edit] = &comment.History()[edit]
9899
}

bug/op_add_comment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66

7+
"github.com/MichaelMure/git-bug/commentary"
78
"github.com/MichaelMure/git-bug/entity"
89
"github.com/MichaelMure/git-bug/entity/dag"
910
"github.com/MichaelMure/git-bug/identity"
@@ -30,7 +31,7 @@ func (op *AddCommentOperation) Id() entity.Id {
3031
func (op *AddCommentOperation) Apply(snapshot *Snapshot) {
3132
snapshot.addActor(op.Author_)
3233
snapshot.addParticipant(op.Author_)
33-
var comment, _ = UnsafeComment{
34+
var comment, _ = commentary.UnsafeComment{
3435
Id: entity.CombineIds(snapshot.Id(), op.Id()),
3536
Message: op.Message,
3637
Author: op.Author_,

0 commit comments

Comments
 (0)