Skip to content

Return assignees with issues queries #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type Issue struct {
Name string
}
} `graphql:"labels(first: 100)"`
Assignees struct {
Nodes []struct {
models.User
}
} `graphql:"assignees(first: 10)"`
Author struct {
models.User `graphql:"... on User"`
}
Expand All @@ -49,6 +54,7 @@ func (c Issues) Frames() data.Frames {
data.NewField("closed_at", nil, []*time.Time{}),
data.NewField("updated_at", nil, []time.Time{}),
data.NewField("labels", nil, []json.RawMessage{}),
data.NewField("assignees", nil, []json.RawMessage{}),
)

for _, v := range c {
Expand All @@ -63,8 +69,16 @@ func (c Issues) Frames() data.Frames {
labels[i] = label.Name
}

assignees := make([]string, len(v.Assignees.Nodes))
for i, assignee := range v.Assignees.Nodes {
assignees[i] = assignee.User.Login
}

labelsBytes, _ := json.Marshal(labels)
rawLabelArray := json.RawMessage(labelsBytes)

assigneesBytes, _ := json.Marshal(assignees)
Comment on lines 77 to +80
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the error returned by json.Marshal can mask serialization failures. Consider capturing and handling or logging the error to aid troubleshooting.

Suggested change
labelsBytes, _ := json.Marshal(labels)
rawLabelArray := json.RawMessage(labelsBytes)
assigneesBytes, _ := json.Marshal(assignees)
labelsBytes, err := json.Marshal(labels)
if err != nil {
fmt.Printf("Error marshaling labels for issue %d: %v\n", v.Number, err)
continue
}
rawLabelArray := json.RawMessage(labelsBytes)
assigneesBytes, err := json.Marshal(assignees)
if err != nil {
fmt.Printf("Error marshaling assignees for issue %d: %v\n", v.Number, err)
continue
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with array of strings, then we probably don't need this logic.

rawAssigneesArray := json.RawMessage(assigneesBytes)

frame.AppendRow(
v.Title,
Expand All @@ -77,6 +91,7 @@ func (c Issues) Frames() data.Frames {
closedAt,
v.UpdatedAt.Time,
rawLabelArray,
rawAssigneesArray,
)
}

Expand Down
44 changes: 23 additions & 21 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,13 @@ func TestIssuesDataframe(t *testing.T) {
Time: createdAt,
},
Closed: false,
Labels: struct {
Nodes []struct{ Name string }
}{
Labels: struct { Nodes []struct{ Name string } }{
Nodes: []struct{ Name string }{
{Name: "bug"},
{Name: "help wanted"},
{ Name: "bug" },
{ Name: "help wanted" },
},
},
Author: struct {
models.User "graphql:\"... on User\""
}{
Author: struct { models.User "graphql:\"... on User\"" }{
User: models.User{
ID: "1",
Login: "firstUser",
Expand All @@ -73,6 +69,12 @@ func TestIssuesDataframe(t *testing.T) {
URL: "",
},
},
Assignees: struct { Nodes []struct { models.User } }{
Nodes: []struct { models.User }{
{ User: models.User{ Login: "firstUser" } },
{ User: models.User{ Login: "secondUser" } },
},
},
Repository: Repository{
Name: "grafana",
Owner: struct{ Login string }{
Expand Down Expand Up @@ -102,16 +104,12 @@ func TestIssuesDataframe(t *testing.T) {
Time: createdAt.Add(time.Hour * 6),
},
Closed: true,
Labels: struct {
Nodes []struct{ Name string }
}{
Labels: struct { Nodes []struct{ Name string } }{
Nodes: []struct{ Name string }{
{Name: "enhancement"},
{ Name: "enhancement" },
},
},
Author: struct {
models.User "graphql:\"... on User\""
}{
Author: struct { models.User "graphql:\"... on User\"" }{
User: models.User{
ID: "2",
Login: "secondUser",
Expand All @@ -121,6 +119,11 @@ func TestIssuesDataframe(t *testing.T) {
URL: "",
},
},
Assignees: struct { Nodes []struct { models.User } }{
Nodes: []struct { models.User }{
{ User: models.User{ Login: "firstUser" } },
},
},
Repository: Repository{
Name: "grafana",
Owner: struct{ Login string }{
Expand Down Expand Up @@ -150,14 +153,10 @@ func TestIssuesDataframe(t *testing.T) {
Time: createdAt,
},
Closed: false,
Labels: struct {
Nodes []struct{ Name string }
}{
Labels: struct { Nodes []struct{ Name string } }{
Nodes: []struct{ Name string }{},
},
Author: struct {
models.User "graphql:\"... on User\""
}{
Author: struct { models.User "graphql:\"... on User\"" }{
User: models.User{
ID: "3",
Login: "firstUser",
Expand All @@ -167,6 +166,9 @@ func TestIssuesDataframe(t *testing.T) {
URL: "",
},
},
Assignees: struct { Nodes []struct { models.User }}{
Nodes: []struct { models.User }{},
},
Repository: Repository{
Name: "grafana",
Owner: struct{ Login string }{
Expand Down
37 changes: 27 additions & 10 deletions pkg/github/testdata/issues.golden.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
//
// Frame[0]
// Name: issues
// Dimensions: 10 Fields by 3 Rows
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+
// | Name: title | Name: author | Name: author_company | Name: repo | Name: number | Name: closed | Name: created_at | Name: closed_at | Name: updated_at | Name: labels |
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []int64 | Type: []bool | Type: []time.Time | Type: []*time.Time | Type: []time.Time | Type: []json.RawMessage |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+
// | Issue #1 | firstUser | ACME Corp | grafana/grafana | 1 | false | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-25 16:21:56 +0000 +0000 | ["bug","help wanted"] |
// | Issue #2 | secondUser | ACME Corp | grafana/grafana | 2 | true | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 22:21:56 +0000 +0000 | 2020-08-25 22:21:56 +0000 +0000 | ["enhancement"] |
// | Issue #3 | firstUser | ACME Corp | grafana/grafana | 3 | false | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-25 16:21:56 +0000 +0000 | [] |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+
// Dimensions: 11 Fields by 3 Rows
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+----------------------------+
// | Name: title | Name: author | Name: author_company | Name: repo | Name: number | Name: closed | Name: created_at | Name: closed_at | Name: updated_at | Name: labels | Name: assignees |
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []int64 | Type: []bool | Type: []time.Time | Type: []*time.Time | Type: []time.Time | Type: []json.RawMessage | Type: []json.RawMessage |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+----------------------------+
// | Issue #1 | firstUser | ACME Corp | grafana/grafana | 1 | false | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-25 16:21:56 +0000 +0000 | ["bug","help wanted"] | ["firstUser","secondUser"] |
// | Issue #2 | secondUser | ACME Corp | grafana/grafana | 2 | true | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 22:21:56 +0000 +0000 | 2020-08-25 22:21:56 +0000 +0000 | ["enhancement"] | ["firstUser"] |
// | Issue #3 | firstUser | ACME Corp | grafana/grafana | 3 | false | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-25 16:21:56 +0000 +0000 | [] | [] |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+----------------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down Expand Up @@ -92,6 +92,13 @@
"typeInfo": {
"frame": "json.RawMessage"
}
},
{
"name": "assignees",
"type": "other",
"typeInfo": {
"frame": "json.RawMessage"
}
}
]
},
Expand Down Expand Up @@ -151,6 +158,16 @@
"enhancement"
],
[]
],
[
[
"firstUser",
"secondUser"
],
[
"firstUser"
],
[]
]
]
}
Expand Down