diff options
author | Michael Muré <batolettre@gmail.com> | 2018-08-01 21:57:12 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-08-01 21:57:12 +0200 |
commit | e5a6a71b78b0d8c5ef0d52c3eeb279d5738b9cf7 (patch) | |
tree | b61cfb5f121a6988aa811566c8cc04e4834c87b8 /graphql/resolvers/mutation.go | |
parent | 15f282421941b90e1f62912cf68b7556a8ce7b33 (diff) | |
download | git-bug-e5a6a71b78b0d8c5ef0d52c3eeb279d5738b9cf7.tar.gz |
graphql: implement the missing mutations
Diffstat (limited to 'graphql/resolvers/mutation.go')
-rw-r--r-- | graphql/resolvers/mutation.go | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go index b06e94cc..8f172ec2 100644 --- a/graphql/resolvers/mutation.go +++ b/graphql/resolvers/mutation.go @@ -2,6 +2,7 @@ package resolvers import ( "context" + "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" ) @@ -33,3 +34,104 @@ func (r mutationResolver) NewBug(ctx context.Context, repoRef *string, title str return *snap, nil } + +func (r mutationResolver) Commit(ctx context.Context, repoRef *string, prefix string) (bug.Snapshot, error) { + repo, err := r.getRepo(repoRef) + if err != nil { + return bug.Snapshot{}, err + } + + b, err := repo.ResolveBugPrefix(prefix) + if err != nil { + return bug.Snapshot{}, err + } + + err = repo.Commit(b) + if err != nil { + return bug.Snapshot{}, err + } + + snap := b.Snapshot() + + return *snap, nil +} + +func (r mutationResolver) AddComment(ctx context.Context, repoRef *string, prefix string, message string) (bug.Snapshot, error) { + repo, err := r.getRepo(repoRef) + if err != nil { + return bug.Snapshot{}, err + } + + b, err := repo.AddComment(repoRef, prefix, message) + if err != nil { + return bug.Snapshot{}, err + } + + snap := b.Snapshot() + + return *snap, nil +} + +func (r mutationResolver) ChangeLabels(ctx context.Context, repoRef *string, prefix string, added []string, removed []string) (bug.Snapshot, error) { + repo, err := r.getRepo(repoRef) + if err != nil { + return bug.Snapshot{}, err + } + + b, err := repo.ChangeLabels(repoRef, prefix, added, removed) + if err != nil { + return bug.Snapshot{}, err + } + + snap := b.Snapshot() + + return *snap, nil +} + +func (r mutationResolver) Open(ctx context.Context, repoRef *string, prefix string) (bug.Snapshot, error) { + repo, err := r.getRepo(repoRef) + if err != nil { + return bug.Snapshot{}, err + } + + b, err := repo.Open(repoRef, prefix) + if err != nil { + return bug.Snapshot{}, err + } + + snap := b.Snapshot() + + return *snap, nil +} + +func (r mutationResolver) Close(ctx context.Context, repoRef *string, prefix string) (bug.Snapshot, error) { + repo, err := r.getRepo(repoRef) + if err != nil { + return bug.Snapshot{}, err + } + + b, err := repo.Close(repoRef, prefix) + if err != nil { + return bug.Snapshot{}, err + } + + snap := b.Snapshot() + + return *snap, nil +} + +func (r mutationResolver) SetTitle(ctx context.Context, repoRef *string, prefix string, title string) (bug.Snapshot, error) { + repo, err := r.getRepo(repoRef) + if err != nil { + return bug.Snapshot{}, err + } + + b, err := repo.SetTitle(repoRef, prefix, title) + if err != nil { + return bug.Snapshot{}, err + } + + snap := b.Snapshot() + + return *snap, nil +} |