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
26 changes: 16 additions & 10 deletions cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
"mage_output_file.go",
"package.json",
"renovate.json",
"query.panel.schema.json",
"query.request.schema.json",
"query.types.json",
"yarn.lock"
],
"ignoreRegExpList": [
"import\\s*\\((.|[\r\n])*?\\)",
"import\\s*.*\".*?\""
],
"ignoreRegExpList": ["import\\s*\\((.|[\r\n])*?\\)", "import\\s*.*\".*?\""],
"words": [
"apiserver",
"dataplane",
"araddon",
"bmike",
"combobox",
"confg",
"CTAV",
"combobox",
"Dataframe",
Expand All @@ -26,6 +30,7 @@
"dompurify",
"dserrors",
"errorsource",
"featuretoggles",
"ghinstallation",
"githubclient",
"githubv",
Expand All @@ -36,13 +41,17 @@
"healthcheck",
"httpclient",
"HTMLURL",
"httpclient",
"instancemgmt",
"jackspeak",
"kminehart",
"mergeable",
"Mergeable",
"mjseaman",
"nazzzzz",
"octocat",
"oldorg",
"oldrepo",
"prismjs",
"promop",
"PTRACE",
Expand All @@ -52,6 +61,8 @@
"querytype",
"rgba",
"RUBYGEMS",
"schemabuilder",
"schemads",
"seccomp",
"shurcoo",
"stretchr",
Expand All @@ -71,11 +82,6 @@
"vals",
"vladimirdotk",
"Wrapf",
"confg",
"octocat",
"schemads",
"featuretoggles",
"oldorg",
"oldrepo"
"yesoreyeram"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@changesets/cli": "2.30.0",
"@grafana/e2e-selectors": "12.4.2",
"@grafana/eslint-config": "9.0.0",
"@grafana/plugin-e2e": "3.4.13",
"@grafana/plugin-e2e": "3.5.1",
"@grafana/plugin-meta-extractor": "0.12.2",
"@grafana/tsconfig": "2.0.1",
"@openfeature/web-sdk": "1.7.3",
Expand Down
51 changes: 27 additions & 24 deletions pkg/github/query_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"encoding/json"

"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
"github.com/pkg/errors"

"github.com/grafana/github-datasource/pkg/models"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
)

// QueryHandler is the main handler for datasource queries.
Expand Down Expand Up @@ -42,29 +42,32 @@ func UnmarshalQuery(b []byte, v interface{}) *backend.DataResponse {
// GetQueryHandlers creates the QueryTypeMux type for handling queries
func GetQueryHandlers(s *QueryHandler) *datasource.QueryTypeMux {
mux := datasource.NewQueryTypeMux()
register := func(qt models.QueryType, handler backend.QueryDataHandlerFunc) {
mux.HandleFunc(string(qt), handler)
}

mux.HandleFunc(models.QueryTypeCommits, s.HandleCommits)
mux.HandleFunc(models.QueryTypeIssues, s.HandleIssues)
mux.HandleFunc(models.QueryTypeContributors, s.HandleContributors)
mux.HandleFunc(models.QueryTypeLabels, s.HandleLabels)
mux.HandleFunc(models.QueryTypePullRequests, s.HandlePullRequests)
mux.HandleFunc(models.QueryTypePullRequestReviews, s.HandlePullRequestReviews)
mux.HandleFunc(models.QueryTypeReleases, s.HandleReleases)
mux.HandleFunc(models.QueryTypeTags, s.HandleTags)
mux.HandleFunc(models.QueryTypePackages, s.HandlePackages)
mux.HandleFunc(models.QueryTypeMilestones, s.HandleMilestones)
mux.HandleFunc(models.QueryTypeRepositories, s.HandleRepositories)
mux.HandleFunc(models.QueryTypeVulnerabilities, s.HandleVulnerabilities)
mux.HandleFunc(models.QueryTypeProjects, s.HandleProjects)
mux.HandleFunc(models.QueryTypeStargazers, s.HandleStargazers)
mux.HandleFunc(models.QueryTypeWorkflows, s.HandleWorkflows)
mux.HandleFunc(models.QueryTypeWorkflowUsage, s.HandleWorkflowUsage)
mux.HandleFunc(models.QueryTypeWorkflowRuns, s.HandleWorkflowRuns)
mux.HandleFunc(models.QueryTypeCodeScanning, s.HandleCodeScanning)
mux.HandleFunc(models.QueryTypeDeployments, s.HandleDeployments)
mux.HandleFunc(models.QueryTypeOrganizations, s.HandleOrganizations)
mux.HandleFunc(models.QueryTypeCommitFiles, s.HandleCommitFiles)
mux.HandleFunc(models.QueryTypePullRequestFiles, s.HandlePullRequestFiles)
register(models.QueryTypeCommits, s.HandleCommits)
register(models.QueryTypeIssues, s.HandleIssues)
register(models.QueryTypeContributors, s.HandleContributors)
register(models.QueryTypeLabels, s.HandleLabels)
register(models.QueryTypePullRequests, s.HandlePullRequests)
register(models.QueryTypePullRequestReviews, s.HandlePullRequestReviews)
register(models.QueryTypeReleases, s.HandleReleases)
register(models.QueryTypeTags, s.HandleTags)
register(models.QueryTypePackages, s.HandlePackages)
register(models.QueryTypeMilestones, s.HandleMilestones)
register(models.QueryTypeRepositories, s.HandleRepositories)
register(models.QueryTypeVulnerabilities, s.HandleVulnerabilities)
register(models.QueryTypeProjects, s.HandleProjects)
register(models.QueryTypeStargazers, s.HandleStargazers)
register(models.QueryTypeWorkflows, s.HandleWorkflows)
register(models.QueryTypeWorkflowUsage, s.HandleWorkflowUsage)
register(models.QueryTypeWorkflowRuns, s.HandleWorkflowRuns)
register(models.QueryTypeCodeScanning, s.HandleCodeScanning)
register(models.QueryTypeDeployments, s.HandleDeployments)
register(models.QueryTypeOrganizations, s.HandleOrganizations)
register(models.QueryTypeCommitFiles, s.HandleCommitFiles)
register(models.QueryTypePullRequestFiles, s.HandlePullRequestFiles)

return mux
}
4 changes: 2 additions & 2 deletions pkg/github/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,6 @@ func timeFieldValuesForTable(tableName string) []string {
return nil
}

func normalizeTableNames(table string) string {
return strings.ToLower(strings.ReplaceAll(table, "_", "-"))
func normalizeTableNames(table models.QueryType) string {
return strings.ToLower(strings.ReplaceAll(string(table), "_", "-"))
}
14 changes: 7 additions & 7 deletions pkg/github/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
// tableToQueryType maps normalized table names to their QueryType constants.
// Built from the query type constants via normalizeTableNames so the schema
// table definitions and this map stay in sync automatically.
var tableToQueryType = func() map[string]string {
qts := []string{
var tableToQueryType = func() map[string]models.QueryType {
qts := []models.QueryType{
models.QueryTypeCommits,
models.QueryTypeIssues,
models.QueryTypePullRequests,
Expand All @@ -37,7 +37,7 @@ var tableToQueryType = func() map[string]string {
models.QueryTypeOrganizations,
models.QueryTypeGraphQL,
}
m := make(map[string]string, len(qts))
m := make(map[string]models.QueryType, len(qts))
for _, qt := range qts {
m[normalizeTableNames(qt)] = qt
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func extractFilterValues(condition schemas.FilterCondition) []string {
// applyFilters maps SQL filter predicates to GitHub API query options.
// It modifies the options map in-place and returns a list of GitHub search
// qualifiers for query types that use the search API.
func applyFilters(queryType string, options map[string]interface{}, filters []schemas.ColumnFilter) []string {
func applyFilters(queryType models.QueryType, options map[string]interface{}, filters []schemas.ColumnFilter) []string {
var searchQualifiers []string

opts, _ := options["options"].(map[string]interface{})
Expand Down Expand Up @@ -242,7 +242,7 @@ func applyFilters(queryType string, options map[string]interface{}, filters []sc
return searchQualifiers
}

func resolveTimeField(queryType, value string) (any, bool) {
func resolveTimeField(queryType models.QueryType, value string) (any, bool) {
switch queryType {
case models.QueryTypeIssues:
switch value {
Expand Down Expand Up @@ -275,7 +275,7 @@ func resolveTimeField(queryType, value string) (any, bool) {
return 0, false
}

func defaultTimeField(queryType string) int {
func defaultTimeField(queryType models.QueryType) int {
switch queryType {
case models.QueryTypePullRequests, models.QueryTypePullRequestReviews:
return int(models.PullRequestCreatedAt)
Expand Down Expand Up @@ -380,7 +380,7 @@ func normalizeGrafanaSQLRequest(req *backend.QueryDataRequest) *backend.QueryDat
}
queries = append(queries, backend.DataQuery{
RefID: q.RefID,
QueryType: queryType,
QueryType: string(queryType),
MaxDataPoints: q.MaxDataPoints,
Interval: q.Interval,
TimeRange: q.TimeRange,
Expand Down
38 changes: 19 additions & 19 deletions pkg/github/sql_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func pluginCtxWithFeatureToggle() backend.PluginContext {
}

func TestTableToQueryTypeCoversAllTypes(t *testing.T) {
allQueryTypes := []string{
allQueryTypes := []models.QueryType{
models.QueryTypeCommits, models.QueryTypeIssues,
models.QueryTypePullRequests, models.QueryTypePullRequestReviews,
models.QueryTypeRepositories, models.QueryTypeContributors,
Expand All @@ -43,7 +43,7 @@ func TestNormalizeAllTableTypes(t *testing.T) {
tests := []struct {
name string
table string
wantType string
wantType models.QueryType
wantOwner string
wantRepo string
unchanged bool
Expand Down Expand Up @@ -90,8 +90,8 @@ func TestNormalizeAllTableTypes(t *testing.T) {
}
return
}
if q.QueryType != tt.wantType {
t.Errorf("queryType: got %q, want %q", q.QueryType, tt.wantType)
if q.QueryType != string(tt.wantType) {
t.Errorf("queryType: got %q, want %q", q.QueryType, string(tt.wantType))
}
var raw map[string]interface{}
if err := json.Unmarshal(q.JSON, &raw); err != nil {
Expand Down Expand Up @@ -121,14 +121,14 @@ func TestNormalizeGrafanaSQLRequest(t *testing.T) {
t.Fatalf("expected one query, got %v", out)
}
q := out.Queries[0]
if q.QueryType != models.QueryTypePullRequests {
if q.QueryType != string(models.QueryTypePullRequests) {
t.Errorf("queryType: got %q, want %q", q.QueryType, models.QueryTypePullRequests)
}
var raw map[string]interface{}
var raw map[string]any
if err := json.Unmarshal(q.JSON, &raw); err != nil {
t.Fatal(err)
}
if raw["queryType"] != models.QueryTypePullRequests {
if raw["queryType"] != string(models.QueryTypePullRequests) {
t.Errorf("JSON queryType: got %v", raw["queryType"])
}
if raw["owner"] != "grafana" || raw["repository"] != "grafana" {
Expand All @@ -149,8 +149,8 @@ func TestNormalizeGrafanaSQLRequest(t *testing.T) {
t.Fatalf("expected one query")
}
q := out.Queries[0]
if q.QueryType != models.QueryTypeIssues {
t.Errorf("queryType: got %q, want %q", q.QueryType, models.QueryTypeIssues)
if q.QueryType != string(models.QueryTypeIssues) {
t.Errorf("queryType: got %q, want %q", q.QueryType, string(models.QueryTypeIssues))
}
var raw map[string]interface{}
if err := json.Unmarshal(q.JSON, &raw); err != nil {
Expand All @@ -173,8 +173,8 @@ func TestNormalizeGrafanaSQLRequest(t *testing.T) {
if out == nil || len(out.Queries) != 1 {
t.Fatalf("expected one query")
}
if out.Queries[0].QueryType != models.QueryTypeCommits {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, models.QueryTypeCommits)
if out.Queries[0].QueryType != string(models.QueryTypeCommits) {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, string(models.QueryTypeCommits))
}
})

Expand All @@ -190,8 +190,8 @@ func TestNormalizeGrafanaSQLRequest(t *testing.T) {
if out == nil || len(out.Queries) != 1 {
t.Fatalf("expected one query")
}
if out.Queries[0].QueryType != models.QueryTypeCodeScanning {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, models.QueryTypeCodeScanning)
if out.Queries[0].QueryType != string(models.QueryTypeCodeScanning) {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, string(models.QueryTypeCodeScanning))
}
})

Expand All @@ -208,8 +208,8 @@ func TestNormalizeGrafanaSQLRequest(t *testing.T) {
t.Fatalf("expected one query")
}
q := out.Queries[0]
if q.QueryType != models.QueryTypeOrganizations {
t.Errorf("queryType: got %q, want %q", q.QueryType, models.QueryTypeOrganizations)
if q.QueryType != string(models.QueryTypeOrganizations) {
t.Errorf("queryType: got %q, want %q", q.QueryType, string(models.QueryTypeOrganizations))
}
var raw map[string]interface{}
if err := json.Unmarshal(q.JSON, &raw); err != nil {
Expand All @@ -235,8 +235,8 @@ func TestNormalizeGrafanaSQLRequest(t *testing.T) {
if out == nil || len(out.Queries) != 1 {
t.Fatalf("expected one query")
}
if out.Queries[0].QueryType != models.QueryTypeWorkflowRuns {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, models.QueryTypeWorkflowRuns)
if out.Queries[0].QueryType != string(models.QueryTypeWorkflowRuns) {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, string(models.QueryTypeWorkflowRuns))
}
})

Expand Down Expand Up @@ -781,8 +781,8 @@ func TestNormalizeGrafanaSQLRequestWithFilters(t *testing.T) {
if out == nil || len(out.Queries) != 1 {
t.Fatalf("expected one query")
}
if out.Queries[0].QueryType != models.QueryTypeIssues {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, models.QueryTypeIssues)
if out.Queries[0].QueryType != string(models.QueryTypeIssues) {
t.Errorf("queryType: got %q, want %q", out.Queries[0].QueryType, string(models.QueryTypeIssues))
}
})
}
Expand Down
Loading
Loading