aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/resolvers
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-14 22:56:59 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-14 22:56:59 +0100
commite9aff2a2a103b43852ecf7b57ae9ab297890eeed (patch)
treed66cb75151e42ada31e1d0179f8dba0ace388989 /graphql/resolvers
parentb2ca506210b3eb63c4964e5bb47203fd5341ddf4 (diff)
parent2df72942f2b057956c7873f908b64880ab647331 (diff)
downloadgit-bug-e9aff2a2a103b43852ecf7b57ae9ab297890eeed.tar.gz
Merge remote-tracking branch 'origin/master' into cheshirekow-jira
Diffstat (limited to 'graphql/resolvers')
-rw-r--r--graphql/resolvers/mutation.go83
-rw-r--r--graphql/resolvers/query.go11
-rw-r--r--graphql/resolvers/repo.go7
3 files changed, 39 insertions, 62 deletions
diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go
index 889edbc8..850645f4 100644
--- a/graphql/resolvers/mutation.go
+++ b/graphql/resolvers/mutation.go
@@ -23,6 +23,15 @@ func (r mutationResolver) getRepo(ref *string) (*cache.RepoCache, error) {
return r.cache.DefaultRepo()
}
+func (r mutationResolver) getBug(repoRef *string, bugPrefix string) (*cache.BugCache, error) {
+ repo, err := r.getRepo(repoRef)
+ if err != nil {
+ return nil, err
+ }
+
+ return repo.ResolveBugPrefix(bugPrefix)
+}
+
func (r mutationResolver) NewBug(_ context.Context, input models.NewBugInput) (*models.NewBugPayload, error) {
repo, err := r.getRepo(input.RepoRef)
if err != nil {
@@ -42,17 +51,17 @@ func (r mutationResolver) NewBug(_ context.Context, input models.NewBugInput) (*
}
func (r mutationResolver) AddComment(_ context.Context, input models.AddCommentInput) (*models.AddCommentPayload, error) {
- repo, err := r.getRepo(input.RepoRef)
+ b, err := r.getBug(input.RepoRef, input.Prefix)
if err != nil {
return nil, err
}
- b, err := repo.ResolveBugPrefix(input.Prefix)
+ op, err := b.AddCommentWithFiles(input.Message, input.Files)
if err != nil {
return nil, err
}
- op, err := b.AddCommentWithFiles(input.Message, input.Files)
+ err = b.Commit()
if err != nil {
return nil, err
}
@@ -65,17 +74,17 @@ func (r mutationResolver) AddComment(_ context.Context, input models.AddCommentI
}
func (r mutationResolver) ChangeLabels(_ context.Context, input *models.ChangeLabelInput) (*models.ChangeLabelPayload, error) {
- repo, err := r.getRepo(input.RepoRef)
+ b, err := r.getBug(input.RepoRef, input.Prefix)
if err != nil {
return nil, err
}
- b, err := repo.ResolveBugPrefix(input.Prefix)
+ results, op, err := b.ChangeLabels(input.Added, input.Removed)
if err != nil {
return nil, err
}
- results, op, err := b.ChangeLabels(input.Added, input.Removed)
+ err = b.Commit()
if err != nil {
return nil, err
}
@@ -94,17 +103,17 @@ func (r mutationResolver) ChangeLabels(_ context.Context, input *models.ChangeLa
}
func (r mutationResolver) OpenBug(_ context.Context, input models.OpenBugInput) (*models.OpenBugPayload, error) {
- repo, err := r.getRepo(input.RepoRef)
+ b, err := r.getBug(input.RepoRef, input.Prefix)
if err != nil {
return nil, err
}
- b, err := repo.ResolveBugPrefix(input.Prefix)
+ op, err := b.Open()
if err != nil {
return nil, err
}
- op, err := b.Open()
+ err = b.Commit()
if err != nil {
return nil, err
}
@@ -117,17 +126,17 @@ func (r mutationResolver) OpenBug(_ context.Context, input models.OpenBugInput)
}
func (r mutationResolver) CloseBug(_ context.Context, input models.CloseBugInput) (*models.CloseBugPayload, error) {
- repo, err := r.getRepo(input.RepoRef)
+ b, err := r.getBug(input.RepoRef, input.Prefix)
if err != nil {
return nil, err
}
- b, err := repo.ResolveBugPrefix(input.Prefix)
+ op, err := b.Close()
if err != nil {
return nil, err
}
- op, err := b.Close()
+ err = b.Commit()
if err != nil {
return nil, err
}
@@ -140,12 +149,7 @@ func (r mutationResolver) CloseBug(_ context.Context, input models.CloseBugInput
}
func (r mutationResolver) SetTitle(_ context.Context, input models.SetTitleInput) (*models.SetTitlePayload, error) {
- repo, err := r.getRepo(input.RepoRef)
- if err != nil {
- return nil, err
- }
-
- b, err := repo.ResolveBugPrefix(input.Prefix)
+ b, err := r.getBug(input.RepoRef, input.Prefix)
if err != nil {
return nil, err
}
@@ -155,53 +159,14 @@ func (r mutationResolver) SetTitle(_ context.Context, input models.SetTitleInput
return nil, err
}
- return &models.SetTitlePayload{
- ClientMutationID: input.ClientMutationID,
- Bug: models.NewLoadedBug(b.Snapshot()),
- Operation: op,
- }, nil
-}
-
-func (r mutationResolver) Commit(_ context.Context, input models.CommitInput) (*models.CommitPayload, error) {
- repo, err := r.getRepo(input.RepoRef)
- if err != nil {
- return nil, err
- }
-
- b, err := repo.ResolveBugPrefix(input.Prefix)
- if err != nil {
- return nil, err
- }
-
err = b.Commit()
if err != nil {
return nil, err
}
- return &models.CommitPayload{
- ClientMutationID: input.ClientMutationID,
- Bug: models.NewLoadedBug(b.Snapshot()),
- }, nil
-}
-
-func (r mutationResolver) CommitAsNeeded(_ context.Context, input models.CommitAsNeededInput) (*models.CommitAsNeededPayload, error) {
- repo, err := r.getRepo(input.RepoRef)
- if err != nil {
- return nil, err
- }
-
- b, err := repo.ResolveBugPrefix(input.Prefix)
- if err != nil {
- return nil, err
- }
-
- err = b.CommitAsNeeded()
- if err != nil {
- return nil, err
- }
-
- return &models.CommitAsNeededPayload{
+ return &models.SetTitlePayload{
ClientMutationID: input.ClientMutationID,
Bug: models.NewLoadedBug(b.Snapshot()),
+ Operation: op,
}, nil
}
diff --git a/graphql/resolvers/query.go b/graphql/resolvers/query.go
index 9503ccf4..6fb18638 100644
--- a/graphql/resolvers/query.go
+++ b/graphql/resolvers/query.go
@@ -27,8 +27,15 @@ func (r rootQueryResolver) DefaultRepository(_ context.Context) (*models.Reposit
}, nil
}
-func (r rootQueryResolver) Repository(_ context.Context, ref string) (*models.Repository, error) {
- repo, err := r.cache.ResolveRepo(ref)
+func (r rootQueryResolver) Repository(_ context.Context, ref *string) (*models.Repository, error) {
+ var repo *cache.RepoCache
+ var err error
+
+ if ref == nil {
+ repo, err = r.cache.DefaultRepo()
+ } else {
+ repo, err = r.cache.ResolveRepo(*ref)
+ }
if err != nil {
return nil, err
diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go
index 3b0aa9a1..d090544d 100644
--- a/graphql/resolvers/repo.go
+++ b/graphql/resolvers/repo.go
@@ -15,6 +15,11 @@ var _ graph.RepositoryResolver = &repoResolver{}
type repoResolver struct{}
+func (repoResolver) Name(_ context.Context, obj *models.Repository) (*string, error) {
+ name := obj.Repo.Name()
+ return &name, nil
+}
+
func (repoResolver) AllBugs(_ context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, queryStr *string) (*models.BugConnection, error) {
input := models.ConnectionInput{
Before: before,
@@ -153,7 +158,7 @@ func (repoResolver) UserIdentity(_ context.Context, obj *models.Repository) (mod
return models.NewLazyIdentity(obj.Repo, excerpt), nil
}
-func (resolver repoResolver) ValidLabels(_ context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.LabelConnection, error) {
+func (repoResolver) ValidLabels(_ context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (*models.LabelConnection, error) {
input := models.ConnectionInput{
Before: before,
After: after,