Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/metal-squids-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'grafana-github-datasource': minor
---

Feature: Add labels to Pull Requests query type
16 changes: 16 additions & 0 deletions pkg/github/pull_requests.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 Down Expand Up @@ -56,6 +57,11 @@ type PullRequest struct {
MergedAt githubv4.DateTime
Mergeable githubv4.MergeableState
MergedBy *PullRequestAuthor
Labels struct {
Nodes []struct {
Name string
}
} `graphql:"labels(first: 100)"`
Repository Repository
}

Expand Down Expand Up @@ -96,6 +102,7 @@ func (p PullRequests) Frames() data.Frames {
data.NewField("updated_at", nil, []time.Time{}),
data.NewField("created_at", nil, []time.Time{}),
openTime,
data.NewField("labels", nil, []json.RawMessage{}),
)

for _, v := range p {
Expand Down Expand Up @@ -150,6 +157,14 @@ func (p PullRequests) Frames() data.Frames {
}
}

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.Number,
v.Title,
Expand All @@ -176,6 +191,7 @@ func (p PullRequests) Frames() data.Frames {
v.UpdatedAt.Time,
v.CreatedAt.Time,
secondsOpen,
rawLabelArray,
)
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/github/pull_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func TestPullRequestsDataFrame(t *testing.T) {
},
Mergeable: githubv4.MergeableStateMergeable,
MergedBy: nil,
Labels: struct {
Nodes []struct{ Name string }
}{
Nodes: []struct{ Name string }{
{Name: "bug"},
{Name: "enhancement"},
},
},
},
{
Number: 2,
Expand Down Expand Up @@ -118,6 +126,13 @@ func TestPullRequestsDataFrame(t *testing.T) {
MergedBy: &PullRequestAuthor{
User: firstUser,
},
Labels: struct {
Nodes []struct{ Name string }
}{
Nodes: []struct{ Name string }{
{Name: "documentation"},
},
},
},
{
Number: 3,
Expand Down Expand Up @@ -145,6 +160,11 @@ func TestPullRequestsDataFrame(t *testing.T) {
Time: openedAt.Add(time.Hour * 2),
},
Mergeable: githubv4.MergeableStateMergeable,
Labels: struct {
Nodes []struct{ Name string }
}{
Nodes: []struct{ Name string }{},
},
},
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/github/testdata/commits.golden.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// Frame[0]
// Name: commits
// Dimensions: 8 Fields by 2 Rows
// +----------------+-----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+
// | Name: id | Name: author | Name: author_login | Name: author_email | Name: author_company | Name: committed_at | Name: pushed_at | Name: message |
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []string | Type: []time.Time | Type: []time.Time | Type: []string |
// +----------------+-----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+
// | | firstCommitter | firstCommitter | first@example.com | ACME Corp | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 16:23:56 +0000 +0000 | commit #1 |
// | | secondCommitter | secondCommitter | second@example.com | ACME Corp | 2020-08-25 17:21:56 +0000 +0000 | 2020-08-25 18:21:56 +0000 +0000 | commit #2 |
// +----------------+-----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+
// +----------------+-----------------+--------------------+--------------------+----------------------+-------------------------------+-------------------------------+----------------+
// | Name: id | Name: author | Name: author_login | Name: author_email | Name: author_company | Name: committed_at | Name: pushed_at | Name: message |
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []string | Type: []time.Time | Type: []time.Time | Type: []string |
// +----------------+-----------------+--------------------+--------------------+----------------------+-------------------------------+-------------------------------+----------------+
// | | firstCommitter | firstCommitter | first@example.com | ACME Corp | 2020-08-25 16:21:56 +0000 UTC | 2020-08-25 16:23:56 +0000 UTC | commit #1 |
// | | secondCommitter | secondCommitter | second@example.com | ACME Corp | 2020-08-25 17:21:56 +0000 UTC | 2020-08-25 18:21:56 +0000 UTC | commit #2 |
// +----------------+-----------------+--------------------+--------------------+----------------------+-------------------------------+-------------------------------+----------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down
18 changes: 9 additions & 9 deletions pkg/github/testdata/issues.golden.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// Frame[0]
// Name: issues
// 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 | [] | [] |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+---------------------------------+---------------------------------+---------------------------------+-------------------------+----------------------------+
// +----------------+----------------+----------------------+-----------------+---------------+--------------+-------------------------------+-------------------------------+-------------------------------+-------------------------+----------------------------+
// | 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 UTC | null | 2020-08-25 16:21:56 +0000 UTC | ["bug","help wanted"] | ["firstUser","secondUser"] |
// | Issue #2 | secondUser | ACME Corp | grafana/grafana | 2 | true | 2020-08-25 16:21:56 +0000 UTC | 2020-08-25 22:21:56 +0000 UTC | 2020-08-25 22:21:56 +0000 UTC | ["enhancement"] | ["firstUser"] |
// | Issue #3 | firstUser | ACME Corp | grafana/grafana | 3 | false | 2020-08-25 16:21:56 +0000 UTC | null | 2020-08-25 16:21:56 +0000 UTC | [] | [] |
// +----------------+----------------+----------------------+-----------------+---------------+--------------+-------------------------------+-------------------------------+-------------------------------+-------------------------+----------------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down
18 changes: 9 additions & 9 deletions pkg/github/testdata/milestones.golden.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// Frame[0]
// Name: milestones
// Dimensions: 7 Fields by 3 Rows
// +------------------+----------------+--------------+----------------+---------------------------------+---------------------------------+---------------------------------+
// | Name: title | Name: author | Name: closed | Name: state | Name: created_at | Name: closed_at | Name: due_at |
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
// | Type: []string | Type: []string | Type: []bool | Type: []string | Type: []time.Time | Type: []*time.Time | Type: []*time.Time |
// +------------------+----------------+--------------+----------------+---------------------------------+---------------------------------+---------------------------------+
// | first milestone | testUser | false | OPEN | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-29 20:21:56 +0000 +0000 |
// | second milestone | testUser2 | true | CLOSED | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-26 02:21:56 +0000 +0000 | 2020-08-29 20:21:56 +0000 +0000 |
// | third milestone | testUser2 | false | OPEN | 2020-08-25 16:21:56 +0000 +0000 | null | 2020-08-30 16:21:56 +0000 +0000 |
// +------------------+----------------+--------------+----------------+---------------------------------+---------------------------------+---------------------------------+
// +------------------+----------------+--------------+----------------+-------------------------------+-------------------------------+-------------------------------+
// | Name: title | Name: author | Name: closed | Name: state | Name: created_at | Name: closed_at | Name: due_at |
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
// | Type: []string | Type: []string | Type: []bool | Type: []string | Type: []time.Time | Type: []*time.Time | Type: []*time.Time |
// +------------------+----------------+--------------+----------------+-------------------------------+-------------------------------+-------------------------------+
// | first milestone | testUser | false | OPEN | 2020-08-25 16:21:56 +0000 UTC | null | 2020-08-29 20:21:56 +0000 UTC |
// | second milestone | testUser2 | true | CLOSED | 2020-08-25 16:21:56 +0000 UTC | 2020-08-26 02:21:56 +0000 UTC | 2020-08-29 20:21:56 +0000 UTC |
// | third milestone | testUser2 | false | OPEN | 2020-08-25 16:21:56 +0000 UTC | null | 2020-08-30 16:21:56 +0000 UTC |
// +------------------+----------------+--------------+----------------+-------------------------------+-------------------------------+-------------------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
Expand Down
Loading
Loading