@@ -60,9 +60,52 @@ type ghAuthor struct {
6060}
6161
6262type githubPullResponse struct {
63- Head struct {
64- SHA string `json:"sha"`
63+ Title string `json:"title"`
64+ State string `json:"state"`
65+ Draft bool `json:"draft"`
66+ Merged bool `json:"merged"`
67+ CreatedAt time.Time `json:"created_at"`
68+ UpdatedAt time.Time `json:"updated_at"`
69+ Additions int `json:"additions"`
70+ Deletions int `json:"deletions"`
71+ Changed int `json:"changed_files"`
72+ Commits int `json:"commits"`
73+ User * ghAuthor `json:"user"`
74+ Head struct {
75+ SHA string `json:"sha"`
76+ Ref string `json:"ref"`
77+ Label string `json:"label"`
78+ Repo struct {
79+ FullName string `json:"full_name"`
80+ } `json:"repo"`
6581 } `json:"head"`
82+ Base struct {
83+ Ref string `json:"ref"`
84+ Label string `json:"label"`
85+ Repo struct {
86+ FullName string `json:"full_name"`
87+ } `json:"repo"`
88+ } `json:"base"`
89+ }
90+
91+ type pullRequestInfoResponse struct {
92+ Title string `json:"title"`
93+ State string `json:"state"`
94+ Draft bool `json:"draft"`
95+ Merged bool `json:"merged"`
96+ Author string `json:"author"`
97+ CreatedAt time.Time `json:"createdAt"`
98+ UpdatedAt time.Time `json:"updatedAt"`
99+ Additions int `json:"additions"`
100+ Deletions int `json:"deletions"`
101+ ChangedFiles int `json:"changedFiles"`
102+ Commits int `json:"commits"`
103+ HeadRef string `json:"headRef"`
104+ HeadLabel string `json:"headLabel"`
105+ HeadRepo string `json:"headRepo"`
106+ BaseRef string `json:"baseRef"`
107+ BaseLabel string `json:"baseLabel"`
108+ BaseRepo string `json:"baseRepo"`
66109}
67110
68111type githubCreatedComment struct {
@@ -243,23 +286,57 @@ func (s *Server) findPullRequestThread(ctx context.Context, org, repo, number st
243286}
244287
245288func (s * Server ) pullRequestHeadSHA (ctx context.Context , org , repo , number string ) (string , error ) {
289+ response , err := s .pullRequest (ctx , org , repo , number )
290+ if err != nil {
291+ return "" , err
292+ }
293+ if response .Head .SHA == "" {
294+ return "" , errors .New ("pull request head sha is missing" )
295+ }
296+ return response .Head .SHA , nil
297+ }
298+
299+ func (s * Server ) pullRequestInfo (ctx context.Context , org , repo , number string ) (pullRequestInfoResponse , error ) {
300+ response , err := s .pullRequest (ctx , org , repo , number )
301+ if err != nil {
302+ return pullRequestInfoResponse {}, err
303+ }
304+ return pullRequestInfoResponse {
305+ Title : response .Title ,
306+ State : response .State ,
307+ Draft : response .Draft ,
308+ Merged : response .Merged ,
309+ Author : commentAuthor (githubReviewComment {Author : response .User }),
310+ CreatedAt : response .CreatedAt ,
311+ UpdatedAt : response .UpdatedAt ,
312+ Additions : response .Additions ,
313+ Deletions : response .Deletions ,
314+ ChangedFiles : response .Changed ,
315+ Commits : response .Commits ,
316+ HeadRef : response .Head .Ref ,
317+ HeadLabel : response .Head .Label ,
318+ HeadRepo : response .Head .Repo .FullName ,
319+ BaseRef : response .Base .Ref ,
320+ BaseLabel : response .Base .Label ,
321+ BaseRepo : response .Base .Repo .FullName ,
322+ }, nil
323+ }
324+
325+ func (s * Server ) pullRequest (ctx context.Context , org , repo , number string ) (githubPullResponse , error ) {
246326 out , err := s .ghOutput (ctx , "gh api pull request" ,
247327 "api" ,
248328 fmt .Sprintf ("repos/%s/%s/pulls/%s" , org , repo , number ),
249329 "--hostname" ,
250330 s .githubHost ,
251331 )
252332 if err != nil {
253- return "" , err
333+ return githubPullResponse {} , err
254334 }
255335 var response githubPullResponse
256336 if err := json .Unmarshal ([]byte (out ), & response ); err != nil {
257- return "" , err
337+ return githubPullResponse {} , err
258338 }
259- if response .Head .SHA == "" {
260- return "" , errors .New ("pull request head sha is missing" )
261- }
262- return response .Head .SHA , nil
339+ return response , nil
263340}
264341
265342func convertGitHubThread (thread githubReviewThread ) (comments.Thread , bool ) {
0 commit comments