Skip to content

Commit 42155c7

Browse files
committed
Export more IDs in issue/pr JSON payload
1 parent e758f30 commit 42155c7

File tree

12 files changed

+57
-42
lines changed

12 files changed

+57
-42
lines changed

api/export_pr.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ func (issue *Issue) ExportData(fields []string) *map[string]interface{} {
1111

1212
for _, f := range fields {
1313
switch f {
14-
case "milestone":
15-
if issue.Milestone.Title != "" {
16-
data[f] = map[string]string{"title": issue.Milestone.Title}
17-
} else {
18-
data[f] = nil
19-
}
2014
case "comments":
2115
data[f] = issue.Comments.Nodes
2216
case "assignees":
@@ -41,13 +35,7 @@ func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
4135
for _, f := range fields {
4236
switch f {
4337
case "headRepository":
44-
data[f] = map[string]string{"name": pr.HeadRepository.Name}
45-
case "milestone":
46-
if pr.Milestone.Title != "" {
47-
data[f] = map[string]string{"title": pr.Milestone.Title}
48-
} else {
49-
data[f] = nil
50-
}
38+
data[f] = pr.HeadRepository
5139
case "statusCheckRollup":
5240
if n := pr.StatusCheckRollup.Nodes; len(n) > 0 {
5341
data[f] = n[0].Commit.StatusCheckRollup.Contexts.Nodes

api/export_pr_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func TestIssue_ExportData(t *testing.T) {
4040
outputJSON: heredoc.Doc(`
4141
{
4242
"milestone": {
43-
"title": "The next big thing"
43+
"number": 0,
44+
"title": "The next big thing",
45+
"description": "",
46+
"dueOn": null
4447
},
4548
"number": 2345
4649
}
@@ -119,7 +122,10 @@ func TestPullRequest_ExportData(t *testing.T) {
119122
outputJSON: heredoc.Doc(`
120123
{
121124
"milestone": {
122-
"title": "The next big thing"
125+
"number": 0,
126+
"title": "The next big thing",
127+
"description": "",
128+
"dueOn": null
123129
},
124130
"number": 2345
125131
}

api/queries_issue.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ type Issue struct {
3636
Assignees Assignees
3737
Labels Labels
3838
ProjectCards ProjectCards
39-
Milestone Milestone
39+
Milestone *Milestone
4040
ReactionGroups ReactionGroups
4141
}
4242

4343
type Assignees struct {
44-
Nodes []struct {
45-
Login string `json:"login"`
46-
}
44+
Nodes []GitHubUser
4745
TotalCount int
4846
}
4947

@@ -56,9 +54,7 @@ func (a Assignees) Logins() []string {
5654
}
5755

5856
type Labels struct {
59-
Nodes []struct {
60-
Name string `json:"name"`
61-
}
57+
Nodes []IssueLabel
6258
TotalCount int
6359
}
6460

@@ -102,10 +98,14 @@ type IssuesDisabledError struct {
10298
}
10399

104100
type Owner struct {
101+
ID string `json:"id,omitempty"`
102+
Name string `json:"name,omitempty"`
105103
Login string `json:"login"`
106104
}
107105

108106
type Author struct {
107+
ID string `json:"id,omitempty"`
108+
Name string `json:"name,omitempty"`
109109
Login string `json:"login"`
110110
}
111111

@@ -273,13 +273,18 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
273273
createdAt
274274
assignees(first: 100) {
275275
nodes {
276+
id
277+
name
276278
login
277279
}
278280
totalCount
279281
}
280282
labels(first: 100) {
281283
nodes {
284+
id
282285
name
286+
description
287+
color
283288
}
284289
totalCount
285290
}
@@ -295,7 +300,10 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
295300
totalCount
296301
}
297302
milestone {
303+
number
298304
title
305+
description
306+
dueOn
299307
}
300308
reactionGroups {
301309
content

api/queries_pr.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type PullRequest struct {
5858
Author Author
5959
MergedBy *Author
6060
HeadRepositoryOwner Owner
61-
HeadRepository PRRepository
61+
HeadRepository *PRRepository
6262
IsCrossRepository bool
6363
IsDraft bool
6464
MaintainerCanModify bool
@@ -105,15 +105,16 @@ type PullRequest struct {
105105
Assignees Assignees
106106
Labels Labels
107107
ProjectCards ProjectCards
108-
Milestone Milestone
108+
Milestone *Milestone
109109
Comments Comments
110110
ReactionGroups ReactionGroups
111111
Reviews PullRequestReviews
112112
ReviewRequests ReviewRequests
113113
}
114114

115115
type PRRepository struct {
116-
Name string
116+
ID string `json:"id"`
117+
Name string `json:"name"`
117118
}
118119

119120
// Commit loads just the commit SHA and nothing else

api/query_builder.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func shortenQuery(q string) string {
2121
var issueComments = shortenQuery(`
2222
comments(first: 100) {
2323
nodes {
24-
author{login},
24+
author{login,...on User{id,name}},
2525
authorAssociation,
2626
body,
2727
createdAt,
@@ -177,21 +177,21 @@ func PullRequestGraphQL(fields []string) string {
177177
for _, field := range fields {
178178
switch field {
179179
case "author":
180-
q = append(q, `author{login}`)
180+
q = append(q, `author{login,...on User{id,name}}`)
181181
case "mergedBy":
182-
q = append(q, `mergedBy{login}`)
182+
q = append(q, `mergedBy{login,,...on User{id,name}}`)
183183
case "headRepositoryOwner":
184-
q = append(q, `headRepositoryOwner{login}`)
184+
q = append(q, `headRepositoryOwner{id,login,,...on User{name}}`)
185185
case "headRepository":
186-
q = append(q, `headRepository{name}`)
186+
q = append(q, `headRepository{id,name}`)
187187
case "assignees":
188-
q = append(q, `assignees(first:100){nodes{login},totalCount}`)
188+
q = append(q, `assignees(first:100){nodes{id,login,name},totalCount}`)
189189
case "labels":
190-
q = append(q, `labels(first:100){nodes{name},totalCount}`)
190+
q = append(q, `labels(first:100){nodes{id,name,description,color},totalCount}`)
191191
case "projectCards":
192192
q = append(q, `projectCards(first:100){nodes{project{name}column{name}},totalCount}`)
193193
case "milestone":
194-
q = append(q, `milestone{title}`)
194+
q = append(q, `milestone{number,title,description,dueOn}`)
195195
case "reactionGroups":
196196
q = append(q, `reactionGroups{content,users{totalCount}}`)
197197
case "mergeCommit":

api/query_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestPullRequestGraphQL(t *testing.T) {
2121
{
2222
name: "fields with nested structures",
2323
fields: []string{"author", "assignees"},
24-
want: "author{login},assignees(first:100){nodes{login},totalCount}",
24+
want: "author{login,...on User{id,name}},assignees(first:100){nodes{id,login,name},totalCount}",
2525
},
2626
{
2727
name: "compressed query",

pkg/cmd/issue/edit/edit.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ func editRun(opts *EditOptions) error {
149149
editable.Assignees.Default = issue.Assignees.Logins()
150150
editable.Labels.Default = issue.Labels.Names()
151151
editable.Projects.Default = issue.ProjectCards.ProjectNames()
152-
editable.Milestone.Default = issue.Milestone.Title
152+
if issue.Milestone != nil {
153+
editable.Milestone.Default = issue.Milestone.Title
154+
}
153155

154156
if opts.Interactive {
155157
err = opts.FieldsToEditSurvey(&editable)

pkg/cmd/issue/view/view.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ func printRawIssuePreview(out io.Writer, issue *api.Issue) error {
155155
fmt.Fprintf(out, "comments:\t%d\n", issue.Comments.TotalCount)
156156
fmt.Fprintf(out, "assignees:\t%s\n", assignees)
157157
fmt.Fprintf(out, "projects:\t%s\n", projects)
158-
fmt.Fprintf(out, "milestone:\t%s\n", issue.Milestone.Title)
158+
var milestoneTitle string
159+
if issue.Milestone != nil {
160+
milestoneTitle = issue.Milestone.Title
161+
}
162+
fmt.Fprintf(out, "milestone:\t%s\n", milestoneTitle)
159163
fmt.Fprintln(out, "--")
160164
fmt.Fprintln(out, issue.Body)
161165
return nil
@@ -196,7 +200,7 @@ func printHumanIssuePreview(opts *ViewOptions, issue *api.Issue) error {
196200
fmt.Fprint(out, cs.Bold("Projects: "))
197201
fmt.Fprintln(out, projects)
198202
}
199-
if issue.Milestone.Title != "" {
203+
if issue.Milestone != nil {
200204
fmt.Fprint(out, cs.Bold("Milestone: "))
201205
fmt.Fprintln(out, issue.Milestone.Title)
202206
}

pkg/cmd/pr/checkout/checkout_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func stubPR(repo, prHead string) (ghrepo.Interface, *api.PullRequest) {
5353
Number: 123,
5454
HeadRefName: headRefName,
5555
HeadRepositoryOwner: api.Owner{Login: headRepo.RepoOwner()},
56-
HeadRepository: api.PRRepository{Name: headRepo.RepoName()},
56+
HeadRepository: &api.PRRepository{Name: headRepo.RepoName()},
5757
IsCrossRepository: !ghrepo.IsSame(baseRepo, headRepo),
5858
MaintainerCanModify: false,
5959
}

pkg/cmd/pr/close/close_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func stubPR(repo, prHead string) (ghrepo.Interface, *api.PullRequest) {
5353
State: "OPEN",
5454
HeadRefName: headRefName,
5555
HeadRepositoryOwner: api.Owner{Login: headRepo.RepoOwner()},
56-
HeadRepository: api.PRRepository{Name: headRepo.RepoName()},
56+
HeadRepository: &api.PRRepository{Name: headRepo.RepoName()},
5757
IsCrossRepository: !ghrepo.IsSame(baseRepo, headRepo),
5858
}
5959
}

0 commit comments

Comments
 (0)