2018-07-30 02:36:41 +03:00
|
|
|
package resolvers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-08-01 22:57:12 +03:00
|
|
|
|
2018-07-30 02:36:41 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2018-08-03 00:37:49 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util"
|
2018-07-30 02:36:41 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type mutationResolver struct {
|
|
|
|
cache cache.Cacher
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r mutationResolver) getRepo(repoRef *string) (cache.RepoCacher, error) {
|
|
|
|
if repoRef != nil {
|
|
|
|
return r.cache.ResolveRepo(*repoRef)
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.cache.DefaultRepo()
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:37:49 +03:00
|
|
|
func (r mutationResolver) NewBug(ctx context.Context, repoRef *string, title string, message string, files []util.Hash) (bug.Snapshot, error) {
|
2018-07-30 02:36:41 +03:00
|
|
|
repo, err := r.getRepo(repoRef)
|
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:37:49 +03:00
|
|
|
b, err := repo.NewBugWithFiles(title, message, files)
|
2018-07-30 02:36:41 +03:00
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
snap := b.Snapshot()
|
|
|
|
|
|
|
|
return *snap, nil
|
|
|
|
}
|
2018-08-01 22:57:12 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
err = b.Commit()
|
2018-08-01 22:57:12 +03:00
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
snap := b.Snapshot()
|
|
|
|
|
|
|
|
return *snap, nil
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:37:49 +03:00
|
|
|
func (r mutationResolver) AddComment(ctx context.Context, repoRef *string, prefix string, message string, files []util.Hash) (bug.Snapshot, error) {
|
2018-08-01 22:57:12 +03:00
|
|
|
repo, err := r.getRepo(repoRef)
|
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:56:50 +03:00
|
|
|
b, err := repo.ResolveBugPrefix(prefix)
|
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:37:49 +03:00
|
|
|
err = b.AddCommentWithFiles(message, files)
|
2018-08-01 22:57:12 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:56:50 +03:00
|
|
|
b, err := repo.ResolveBugPrefix(prefix)
|
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
err = b.ChangeLabels(added, removed)
|
2018-08-01 22:57:12 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:56:50 +03:00
|
|
|
b, err := repo.ResolveBugPrefix(prefix)
|
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
err = b.Open()
|
2018-08-01 22:57:12 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:56:50 +03:00
|
|
|
b, err := repo.ResolveBugPrefix(prefix)
|
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
err = b.Close()
|
2018-08-01 22:57:12 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:56:50 +03:00
|
|
|
b, err := repo.ResolveBugPrefix(prefix)
|
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:35:13 +03:00
|
|
|
err = b.SetTitle(title)
|
2018-08-01 22:57:12 +03:00
|
|
|
if err != nil {
|
|
|
|
return bug.Snapshot{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
snap := b.Snapshot()
|
|
|
|
|
|
|
|
return *snap, nil
|
|
|
|
}
|