mutation.go

 1package resolvers
 2
 3import (
 4	"context"
 5	"github.com/MichaelMure/git-bug/bug"
 6	"github.com/MichaelMure/git-bug/cache"
 7)
 8
 9type mutationResolver struct {
10	cache cache.Cacher
11}
12
13func (r mutationResolver) getRepo(repoRef *string) (cache.RepoCacher, error) {
14	if repoRef != nil {
15		return r.cache.ResolveRepo(*repoRef)
16	}
17
18	return r.cache.DefaultRepo()
19}
20
21func (r mutationResolver) NewBug(ctx context.Context, repoRef *string, title string, message string) (bug.Snapshot, error) {
22	repo, err := r.getRepo(repoRef)
23	if err != nil {
24		return bug.Snapshot{}, err
25	}
26
27	b, err := repo.NewBug(title, message)
28	if err != nil {
29		return bug.Snapshot{}, err
30	}
31
32	snap := b.Snapshot()
33
34	return *snap, nil
35}