@@ -4,15 +4,17 @@ import (
44 "context"
55 "time"
66
7- "github.com/cli/cli/internal/ghrepo"
87 "github.com/shurcooL/githubv4"
98 "github.com/shurcooL/graphql"
109)
1110
1211type Comments struct {
1312 Nodes []Comment
1413 TotalCount int
15- PageInfo PageInfo
14+ PageInfo struct {
15+ HasNextPage bool
16+ EndCursor string
17+ }
1618}
1719
1820type Comment struct {
@@ -26,83 +28,6 @@ type Comment struct {
2628 ReactionGroups ReactionGroups `json:"reactionGroups"`
2729}
2830
29- type PageInfo struct {
30- HasNextPage bool
31- EndCursor string
32- }
33-
34- func CommentsForIssue (client * Client , repo ghrepo.Interface , issue * Issue ) (* Comments , error ) {
35- type response struct {
36- Repository struct {
37- Issue struct {
38- Comments Comments `graphql:"comments(first: 100, after: $endCursor)"`
39- } `graphql:"issue(number: $number)"`
40- } `graphql:"repository(owner: $owner, name: $repo)"`
41- }
42-
43- variables := map [string ]interface {}{
44- "owner" : githubv4 .String (repo .RepoOwner ()),
45- "repo" : githubv4 .String (repo .RepoName ()),
46- "number" : githubv4 .Int (issue .Number ),
47- "endCursor" : (* githubv4 .String )(nil ),
48- }
49-
50- gql := graphQLClient (client .http , repo .RepoHost ())
51-
52- var comments []Comment
53- for {
54- var query response
55- err := gql .QueryNamed (context .Background (), "CommentsForIssue" , & query , variables )
56- if err != nil {
57- return nil , err
58- }
59-
60- comments = append (comments , query .Repository .Issue .Comments .Nodes ... )
61- if ! query .Repository .Issue .Comments .PageInfo .HasNextPage {
62- break
63- }
64- variables ["endCursor" ] = githubv4 .String (query .Repository .Issue .Comments .PageInfo .EndCursor )
65- }
66-
67- return & Comments {Nodes : comments , TotalCount : len (comments )}, nil
68- }
69-
70- func CommentsForPullRequest (client * Client , repo ghrepo.Interface , pr * PullRequest ) (* Comments , error ) {
71- type response struct {
72- Repository struct {
73- PullRequest struct {
74- Comments Comments `graphql:"comments(first: 100, after: $endCursor)"`
75- } `graphql:"pullRequest(number: $number)"`
76- } `graphql:"repository(owner: $owner, name: $repo)"`
77- }
78-
79- variables := map [string ]interface {}{
80- "owner" : githubv4 .String (repo .RepoOwner ()),
81- "repo" : githubv4 .String (repo .RepoName ()),
82- "number" : githubv4 .Int (pr .Number ),
83- "endCursor" : (* githubv4 .String )(nil ),
84- }
85-
86- gql := graphQLClient (client .http , repo .RepoHost ())
87-
88- var comments []Comment
89- for {
90- var query response
91- err := gql .QueryNamed (context .Background (), "CommentsForPullRequest" , & query , variables )
92- if err != nil {
93- return nil , err
94- }
95-
96- comments = append (comments , query .Repository .PullRequest .Comments .Nodes ... )
97- if ! query .Repository .PullRequest .Comments .PageInfo .HasNextPage {
98- break
99- }
100- variables ["endCursor" ] = githubv4 .String (query .Repository .PullRequest .Comments .PageInfo .EndCursor )
101- }
102-
103- return & Comments {Nodes : comments , TotalCount : len (comments )}, nil
104- }
105-
10631type CommentCreateInput struct {
10732 Body string
10833 SubjectId string
0 commit comments