aboutsummaryrefslogtreecommitdiffstats
path: root/api/graphql/resolvers
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-05-24 09:43:37 +0200
committerGitHub <noreply@github.com>2021-05-24 09:43:37 +0200
commitcda3037c7cd053d5521f7928ae6c5e2801dc42d7 (patch)
treefe28abae16a509e4b92b3bd063df6a9200660123 /api/graphql/resolvers
parent13d9632fb888dde9962e122ef06614ca9e9da83d (diff)
parent4043f5da0965bca1ffc717c1ceca265ec8b9ae17 (diff)
downloadgit-bug-cda3037c7cd053d5521f7928ae6c5e2801dc42d7.tar.gz
Merge pull request #665 from GlancingMind/Implement-CommentAndCloseMutation
GraphQL: Implement AddCommentAndCloseBug mutation
Diffstat (limited to 'api/graphql/resolvers')
-rw-r--r--api/graphql/resolvers/mutation.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/api/graphql/resolvers/mutation.go b/api/graphql/resolvers/mutation.go
index 00c9e3c1..b55270c2 100644
--- a/api/graphql/resolvers/mutation.go
+++ b/api/graphql/resolvers/mutation.go
@@ -100,6 +100,44 @@ func (r mutationResolver) AddComment(ctx context.Context, input models.AddCommen
}, nil
}
+func (r mutationResolver) AddCommentAndClose(ctx context.Context, input models.AddCommentAndCloseBugInput) (*models.AddCommentAndCloseBugPayload, error) {
+ repo, b, err := r.getBug(input.RepoRef, input.Prefix)
+ if err != nil {
+ return nil, err
+ }
+
+ author, err := auth.UserFromCtx(ctx, repo)
+ if err != nil {
+ return nil, err
+ }
+
+ opAddComment, err := b.AddCommentRaw(author,
+ time.Now().Unix(),
+ text.Cleanup(input.Message),
+ input.Files,
+ nil)
+ if err != nil {
+ return nil, err
+ }
+
+ opClose, err := b.CloseRaw(author, time.Now().Unix(), nil)
+ if err != nil {
+ return nil, err
+ }
+
+ err = b.Commit()
+ if err != nil {
+ return nil, err
+ }
+
+ return &models.AddCommentAndCloseBugPayload{
+ ClientMutationID: input.ClientMutationID,
+ Bug: models.NewLoadedBug(b.Snapshot()),
+ CommentOperation: opAddComment,
+ StatusOperation: opClose,
+ }, nil
+}
+
func (r mutationResolver) EditComment(ctx context.Context, input models.EditCommentInput) (*models.EditCommentPayload, error) {
repo, b, err := r.getBug(input.RepoRef, input.Prefix)
if err != nil {