X Tutup
Skip to content

Commit e63904b

Browse files
committed
Expose more fields for PR JSON export
1 parent a516ee6 commit e63904b

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

api/export_pr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
6464
data[f] = pr.ProjectCards.Nodes
6565
case "reviews":
6666
data[f] = pr.Reviews.Nodes
67+
case "files":
68+
data[f] = pr.Files.Nodes
6769
case "reviewRequests":
6870
requests := make([]interface{}, 0, len(pr.ReviewRequests.Nodes))
6971
for _, req := range pr.ReviewRequests.Nodes {

api/queries_pr.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,22 @@ type PullRequest struct {
4242
Mergeable string
4343
Additions int
4444
Deletions int
45+
ChangedFiles int
4546
MergeStateStatus string
4647
CreatedAt time.Time
4748
UpdatedAt time.Time
4849
ClosedAt *time.Time
4950
MergedAt *time.Time
5051

52+
MergeCommit *Commit
53+
PotentialMergeCommit *Commit
54+
55+
Files struct {
56+
Nodes []PullRequestFile
57+
}
58+
5159
Author Author
60+
MergedBy *Author
5261
HeadRepositoryOwner struct {
5362
Login string `json:"login"`
5463
}
@@ -104,6 +113,16 @@ type PullRequest struct {
104113
ReviewRequests ReviewRequests
105114
}
106115

116+
type Commit struct {
117+
OID string `json:"oid"`
118+
}
119+
120+
type PullRequestFile struct {
121+
Path string `json:"path"`
122+
Additions int `json:"additions"`
123+
Deletions int `json:"deletions"`
124+
}
125+
107126
type ReviewRequests struct {
108127
Nodes []struct {
109128
RequestedReviewer struct {

api/queries_pr_review.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ type PullRequestReview struct {
3131
Author Author `json:"author"`
3232
AuthorAssociation string `json:"authorAssociation"`
3333
Body string `json:"body"`
34-
CreatedAt time.Time `json:"createdAt"`
34+
SubmittedAt *time.Time `json:"submittedAt"`
3535
IncludesCreatedEdit bool `json:"includesCreatedEdit"`
3636
ReactionGroups ReactionGroups `json:"reactionGroups"`
3737
State string `json:"state"`
38-
URL string `json:"url"`
38+
URL string `json:"url,omitempty"`
3939
}
4040

4141
func AddReview(client *Client, repo ghrepo.Interface, pr *PullRequest, input *PullRequestReviewInput) error {
@@ -115,7 +115,10 @@ func (prr PullRequestReview) Content() string {
115115
}
116116

117117
func (prr PullRequestReview) Created() time.Time {
118-
return prr.CreatedAt
118+
if prr.SubmittedAt == nil {
119+
return time.Time{}
120+
}
121+
return *prr.SubmittedAt
119122
}
120123

121124
func (prr PullRequestReview) HiddenReason() string {

api/query_builder.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ var prReviewRequests = shortenQuery(`
4646
}
4747
`)
4848

49+
var prReviews = shortenQuery(`
50+
reviews(last: 100) {
51+
nodes {
52+
author{login},
53+
authorAssociation,
54+
submittedAt,
55+
body,
56+
state,
57+
reactionGroups{content,users{totalCount}}
58+
}
59+
}
60+
`)
61+
62+
var prFiles = shortenQuery(`
63+
files(first: 100) {
64+
nodes {
65+
additions,
66+
deletions,
67+
path
68+
}
69+
}
70+
`)
71+
4972
var prStatusCheckRollup = shortenQuery(`
5073
commits(last: 1) {
5174
totalCount,
@@ -100,18 +123,24 @@ var IssueFields = []string{
100123
var PullRequestFields = append(IssueFields,
101124
"additions",
102125
"baseRefName",
126+
"changedFiles",
103127
"deletions",
128+
"files",
104129
"headRefName",
105130
"headRepository",
106131
"headRepositoryOwner",
107132
"isCrossRepository",
108133
"isDraft",
109134
"maintainerCanModify",
110135
"mergeable",
136+
"mergeCommit",
111137
"mergedAt",
138+
"mergedBy",
112139
"mergeStateStatus",
140+
"potentialMergeCommit",
113141
"reviewDecision",
114142
"reviewRequests",
143+
"reviews",
115144
"statusCheckRollup",
116145
)
117146

@@ -121,6 +150,8 @@ func PullRequestGraphQL(fields []string) string {
121150
switch field {
122151
case "author":
123152
q = append(q, `author{login}`)
153+
case "mergedBy":
154+
q = append(q, `mergedBy{login}`)
124155
case "headRepositoryOwner":
125156
q = append(q, `headRepositoryOwner{login}`)
126157
case "headRepository":
@@ -135,10 +166,18 @@ func PullRequestGraphQL(fields []string) string {
135166
q = append(q, `milestone{title}`)
136167
case "reactionGroups":
137168
q = append(q, `reactionGroups{content,users{totalCount}}`)
169+
case "mergeCommit":
170+
q = append(q, `mergeCommit{oid}`)
171+
case "potentialMergeCommit":
172+
q = append(q, `potentialMergeCommit{oid}`)
138173
case "comments":
139174
q = append(q, issueComments)
140175
case "reviewRequests":
141176
q = append(q, prReviewRequests)
177+
case "reviews":
178+
q = append(q, prReviews)
179+
case "files":
180+
q = append(q, prFiles)
142181
case "statusCheckRollup":
143182
q = append(q, prStatusCheckRollup)
144183
default:

0 commit comments

Comments
 (0)
X Tutup