Skip to content

Commit

Permalink
return labels when querying issues (#411)
Browse files Browse the repository at this point in the history
adds a new `labels` field to the response as an array.

<img width="1728" alt="Screenshot 2025-01-23 at 23 37 30"
src="https://github.com/user-attachments/assets/9309e23b-6034-45fa-8856-17f17cc34ab3"
/>

Closes #410
  • Loading branch information
gwdawson authored Jan 30, 2025
1 parent ae63ce7 commit a3cb73c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
18 changes: 17 additions & 1 deletion pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
Expand All @@ -20,7 +21,12 @@ type Issue struct {
CreatedAt githubv4.DateTime
UpdatedAt githubv4.DateTime
Closed bool
Author struct {
Labels struct {
Nodes []struct {
Name string
}
} `graphql:"labels(first: 100)"`
Author struct {
models.User `graphql:"... on User"`
}
Repository Repository
Expand All @@ -42,6 +48,7 @@ func (c Issues) Frames() data.Frames {
data.NewField("created_at", nil, []time.Time{}),
data.NewField("closed_at", nil, []*time.Time{}),
data.NewField("updated_at", nil, []time.Time{}),
data.NewField("labels", nil, []json.RawMessage{}),
)

for _, v := range c {
Expand All @@ -51,6 +58,14 @@ func (c Issues) Frames() data.Frames {
closedAt = &t
}

labels := make([]string, len(v.Labels.Nodes))
for i, label := range v.Labels.Nodes {
labels[i] = label.Name
}

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

frame.AppendRow(
v.Title,
v.Author.User.Login,
Expand All @@ -61,6 +76,7 @@ func (c Issues) Frames() data.Frames {
v.CreatedAt.Time,
closedAt,
v.UpdatedAt.Time,
rawLabelArray,
)
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func TestIssuesDataframe(t *testing.T) {
Time: createdAt,
},
Closed: false,
Labels: struct {
Nodes []struct{ Name string }
}{
Nodes: []struct{ Name string }{
{Name: "bug"},
{Name: "help wanted"},
},
},
Author: struct {
models.User "graphql:\"... on User\""
}{
Expand Down Expand Up @@ -94,6 +102,13 @@ func TestIssuesDataframe(t *testing.T) {
Time: createdAt.Add(time.Hour * 6),
},
Closed: true,
Labels: struct {
Nodes []struct{ Name string }
}{
Nodes: []struct{ Name string }{
{Name: "enhancement"},
},
},
Author: struct {
models.User "graphql:\"... on User\""
}{
Expand Down Expand Up @@ -135,6 +150,11 @@ func TestIssuesDataframe(t *testing.T) {
Time: createdAt,
},
Closed: false,
Labels: struct {
Nodes []struct{ Name string }
}{
Nodes: []struct{ Name string }{},
},
Author: struct {
models.User "graphql:\"... on User\""
}{
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: 9 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 |
// | 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 |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+
// | 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 |
// | 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 |
// | 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: 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 | [] |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down Expand Up @@ -85,6 +85,13 @@
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "labels",
"type": "other",
"typeInfo": {
"frame": "json.RawMessage"
}
}
]
},
Expand Down Expand Up @@ -134,6 +141,16 @@
1598372516000,
1598394116000,
1598372516000
],
[
[
"bug",
"help wanted"
],
[
"enhancement"
],
[]
]
]
}
Expand Down

0 comments on commit a3cb73c

Please sign in to comment.