X Tutup
Skip to content

Commit de73b16

Browse files
committed
Move CreateComment mutation
1 parent 1fc8b66 commit de73b16

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

api/queries_comments.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/cli/cli/internal/ghrepo"
88
"github.com/shurcooL/githubv4"
9+
"github.com/shurcooL/graphql"
910
)
1011

1112
type Comments struct {
@@ -99,3 +100,30 @@ func CommentsForPullRequest(client *Client, repo ghrepo.Interface, pr *PullReque
99100

100101
return &Comments{Nodes: comments, TotalCount: len(comments)}, nil
101102
}
103+
104+
func CommentCreate(client *Client, repoHost string, params map[string]string) (string, error) {
105+
var mutation struct {
106+
AddComment struct {
107+
CommentEdge struct {
108+
Node struct {
109+
URL string
110+
}
111+
}
112+
} `graphql:"addComment(input: $input)"`
113+
}
114+
115+
variables := map[string]interface{}{
116+
"input": githubv4.AddCommentInput{
117+
Body: githubv4.String(params["body"]),
118+
SubjectID: graphql.ID(params["subjectId"]),
119+
},
120+
}
121+
122+
gql := graphQLClient(client.http, repoHost)
123+
err := gql.MutateNamed(context.Background(), "CommentCreate", &mutation, variables)
124+
if err != nil {
125+
return "", err
126+
}
127+
128+
return mutation.AddComment.CommentEdge.Node.URL, nil
129+
}

api/queries_issue.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/cli/cli/internal/ghrepo"
1212
"github.com/shurcooL/githubv4"
13-
"github.com/shurcooL/graphql"
1413
)
1514

1615
type IssuesPayload struct {
@@ -124,33 +123,6 @@ func IssueCreate(client *Client, repo *Repository, params map[string]interface{}
124123
return &result.CreateIssue.Issue, nil
125124
}
126125

127-
func CommentCreate(client *Client, repoHost string, params map[string]string) (string, error) {
128-
var mutation struct {
129-
AddComment struct {
130-
CommentEdge struct {
131-
Node struct {
132-
URL string
133-
}
134-
}
135-
} `graphql:"addComment(input: $input)"`
136-
}
137-
138-
variables := map[string]interface{}{
139-
"input": githubv4.AddCommentInput{
140-
Body: githubv4.String(params["body"]),
141-
SubjectID: graphql.ID(params["subjectId"]),
142-
},
143-
}
144-
145-
gql := graphQLClient(client.http, repoHost)
146-
err := gql.MutateNamed(context.Background(), "CommentCreate", &mutation, variables)
147-
if err != nil {
148-
return "", err
149-
}
150-
151-
return mutation.AddComment.CommentEdge.Node.URL, nil
152-
}
153-
154126
func IssueStatus(client *Client, repo ghrepo.Interface, currentUsername string) (*IssuesPayload, error) {
155127
type response struct {
156128
Repository struct {

0 commit comments

Comments
 (0)
X Tutup