@@ -10,12 +10,6 @@ import (
1010)
1111
1212var (
13- timeRangeOperators = []schemas.Operator {
14- schemas .OperatorGreaterThan ,
15- schemas .OperatorGreaterThanOrEqual ,
16- schemas .OperatorLessThan ,
17- schemas .OperatorLessThanOrEqual ,
18- }
1913 equalityOperators = []schemas.Operator {
2014 schemas .OperatorEquals ,
2115 schemas .OperatorIn ,
2923 {Name : "repository" , DependsOn : []string {"organization" }, Required : true },
3024 }
3125
26+ repoScopedWithTimeFieldTableParameters = []schemas.TableParameter {
27+ {Name : "organization" , Root : true , Required : true },
28+ {Name : "repository" , DependsOn : []string {"organization" }, Required : true },
29+ {Name : "timeField" , Root : true },
30+ }
31+
3232 orgOnlyTableParameters = []schemas.TableParameter {
3333 {Name : "organization" , Root : true , Required : true },
3434 }
@@ -61,14 +61,31 @@ func (p *SchemaProvider) Schema(ctx context.Context, req *schemas.SchemaRequest)
6161 tables := getAllTables ()
6262
6363 var tableParamValues map [string ]map [string ][]string
64- if len (orgRepos .Orgs ) > 0 {
65- tableParamValues = make (map [string ]map [string ][]string )
66- for _ , t := range tables {
67- for _ , tp := range t .TableParameters {
68- if tp .Root && tp .Name == "organization" {
69- tableParamValues [t .Name ] = map [string ][]string {
70- "organization" : orgRepos .Orgs ,
64+ for _ , t := range tables {
65+ for _ , tp := range t .TableParameters {
66+ if ! tp .Root {
67+ continue
68+ }
69+ switch tp .Name {
70+ case "organization" :
71+ if len (orgRepos .Orgs ) > 0 {
72+ if tableParamValues == nil {
73+ tableParamValues = make (map [string ]map [string ][]string )
74+ }
75+ if tableParamValues [t .Name ] == nil {
76+ tableParamValues [t .Name ] = make (map [string ][]string )
7177 }
78+ tableParamValues [t .Name ]["organization" ] = orgRepos .Orgs
79+ }
80+ case "timeField" :
81+ if vals := timeFieldValuesForTable (t .Name ); len (vals ) > 0 {
82+ if tableParamValues == nil {
83+ tableParamValues = make (map [string ]map [string ][]string )
84+ }
85+ if tableParamValues [t .Name ] == nil {
86+ tableParamValues [t .Name ] = make (map [string ][]string )
87+ }
88+ tableParamValues [t .Name ]["timeField" ] = vals
7289 }
7390 }
7491 }
@@ -141,6 +158,10 @@ func (p *SchemaProvider) TableParameterValues(ctx context.Context, req *schemas.
141158 names [i ] = r .Name
142159 }
143160 result [param ] = names
161+ case "timeField" :
162+ if vals := timeFieldValuesForTable (stripTableParameterValues (req .Table )); len (vals ) > 0 {
163+ result [param ] = vals
164+ }
144165 case "workflow" :
145166 org := req .DependencyValues ["organization" ]
146167 repo := req .DependencyValues ["repository" ]
@@ -202,14 +223,14 @@ func getAllTables() []schemas.Table {
202223 {Name : "author_login" , Type : schemas .ColumnTypeString },
203224 {Name : "author_email" , Type : schemas .ColumnTypeString },
204225 {Name : "author_company" , Type : schemas .ColumnTypeString },
205- {Name : "committed_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
226+ {Name : "committed_at" , Type : schemas .ColumnTypeDatetime },
206227 {Name : "pushed_at" , Type : schemas .ColumnTypeDatetime },
207228 {Name : "message" , Type : schemas .ColumnTypeString },
208229 },
209230 },
210231 {
211232 Name : normalizeTableNames (models .QueryTypeIssues ),
212- TableParameters : repoScopedTableParameters ,
233+ TableParameters : repoScopedWithTimeFieldTableParameters ,
213234 Columns : []schemas.Column {
214235 {Name : "title" , Type : schemas .ColumnTypeString },
215236 {Name : "author" , Type : schemas .ColumnTypeString , Operators : equalityOperators },
@@ -218,17 +239,17 @@ func getAllTables() []schemas.Table {
218239 {Name : "number" , Type : schemas .ColumnTypeInt64 },
219240 {Name : "state" , Type : schemas .ColumnTypeEnum , Values : []string {"open" , "closed" }, Operators : equalityOperators },
220241 {Name : "closed" , Type : schemas .ColumnTypeBoolean },
221- {Name : "created_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
222- {Name : "closed_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
223- {Name : "updated_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
242+ {Name : "created_at" , Type : schemas .ColumnTypeDatetime },
243+ {Name : "closed_at" , Type : schemas .ColumnTypeDatetime },
244+ {Name : "updated_at" , Type : schemas .ColumnTypeDatetime },
224245 {Name : "labels" , Type : schemas .ColumnTypeJSON , Operators : equalityOperators },
225246 {Name : "assignees" , Type : schemas .ColumnTypeJSON , Operators : equalityOperators },
226247 {Name : "milestone" , Type : schemas .ColumnTypeString , Operators : equalityOperators },
227248 },
228249 },
229250 {
230251 Name : normalizeTableNames (models .QueryTypePullRequests ),
231- TableParameters : repoScopedTableParameters ,
252+ TableParameters : repoScopedWithTimeFieldTableParameters ,
232253 Columns : []schemas.Column {
233254 {Name : "number" , Type : schemas .ColumnTypeInt64 },
234255 {Name : "title" , Type : schemas .ColumnTypeString },
@@ -246,21 +267,21 @@ func getAllTables() []schemas.Table {
246267 {Name : "locked" , Type : schemas .ColumnTypeBoolean },
247268 {Name : "merged" , Type : schemas .ColumnTypeBoolean },
248269 {Name : "mergeable" , Type : schemas .ColumnTypeString },
249- {Name : "closed_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
250- {Name : "merged_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
270+ {Name : "closed_at" , Type : schemas .ColumnTypeDatetime },
271+ {Name : "merged_at" , Type : schemas .ColumnTypeDatetime },
251272 {Name : "merged_by_name" , Type : schemas .ColumnTypeString },
252273 {Name : "merged_by_login" , Type : schemas .ColumnTypeString },
253274 {Name : "merged_by_email" , Type : schemas .ColumnTypeString },
254275 {Name : "merged_by_company" , Type : schemas .ColumnTypeString },
255- {Name : "updated_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
256- {Name : "created_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
276+ {Name : "updated_at" , Type : schemas .ColumnTypeDatetime },
277+ {Name : "created_at" , Type : schemas .ColumnTypeDatetime },
257278 {Name : "open_time" , Type : schemas .ColumnTypeFloat64 },
258279 {Name : "labels" , Type : schemas .ColumnTypeJSON , Operators : equalityOperators },
259280 },
260281 },
261282 {
262283 Name : normalizeTableNames (models .QueryTypePullRequestReviews ),
263- TableParameters : repoScopedTableParameters ,
284+ TableParameters : repoScopedWithTimeFieldTableParameters ,
264285 Columns : []schemas.Column {
265286 {Name : "pull_request_number" , Type : schemas .ColumnTypeInt64 },
266287 {Name : "pull_request_title" , Type : schemas .ColumnTypeString },
@@ -278,8 +299,8 @@ func getAllTables() []schemas.Table {
278299 {Name : "review_url" , Type : schemas .ColumnTypeString },
279300 {Name : "review_state" , Type : schemas .ColumnTypeString },
280301 {Name : "review_comment_count" , Type : schemas .ColumnTypeInt64 },
281- {Name : "review_updated_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
282- {Name : "review_created_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
302+ {Name : "review_updated_at" , Type : schemas .ColumnTypeDatetime },
303+ {Name : "review_created_at" , Type : schemas .ColumnTypeDatetime },
283304 },
284305 },
285306 {
@@ -318,7 +339,7 @@ func getAllTables() []schemas.Table {
318339 {Name : "author_login" , Type : schemas .ColumnTypeString },
319340 {Name : "author_email" , Type : schemas .ColumnTypeString },
320341 {Name : "author_company" , Type : schemas .ColumnTypeString },
321- {Name : "date" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
342+ {Name : "date" , Type : schemas .ColumnTypeDatetime },
322343 },
323344 },
324345 {
@@ -332,7 +353,7 @@ func getAllTables() []schemas.Table {
332353 {Name : "tag" , Type : schemas .ColumnTypeString },
333354 {Name : "url" , Type : schemas .ColumnTypeString },
334355 {Name : "created_at" , Type : schemas .ColumnTypeDatetime },
335- {Name : "published_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
356+ {Name : "published_at" , Type : schemas .ColumnTypeDatetime },
336357 },
337358 },
338359 {
@@ -385,8 +406,8 @@ func getAllTables() []schemas.Table {
385406 {Name : "cvssScore" , Type : schemas .ColumnTypeFloat64 },
386407 {Name : "cvssVector" , Type : schemas .ColumnTypeString },
387408 {Name : "permalink" , Type : schemas .ColumnTypeString },
388- {Name : "severity" , Type : schemas .ColumnTypeString , Operators : equalityOperators },
389- {Name : "state" , Type : schemas .ColumnTypeString , Operators : equalityOperators },
409+ {Name : "severity" , Type : schemas .ColumnTypeString },
410+ {Name : "state" , Type : schemas .ColumnTypeString },
390411 },
391412 },
392413 {
@@ -408,7 +429,7 @@ func getAllTables() []schemas.Table {
408429 Name : normalizeTableNames (models .QueryTypeStargazers ),
409430 TableParameters : repoScopedTableParameters ,
410431 Columns : []schemas.Column {
411- {Name : "starred_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
432+ {Name : "starred_at" , Type : schemas .ColumnTypeDatetime },
412433 {Name : "star_count" , Type : schemas .ColumnTypeInt64 },
413434 {Name : "id" , Type : schemas .ColumnTypeString },
414435 {Name : "login" , Type : schemas .ColumnTypeString },
@@ -420,14 +441,14 @@ func getAllTables() []schemas.Table {
420441 },
421442 {
422443 Name : normalizeTableNames (models .QueryTypeWorkflows ),
423- TableParameters : repoScopedTableParameters ,
444+ TableParameters : repoScopedWithTimeFieldTableParameters ,
424445 Columns : []schemas.Column {
425446 {Name : "id" , Type : schemas .ColumnTypeInt64 },
426447 {Name : "name" , Type : schemas .ColumnTypeString },
427448 {Name : "path" , Type : schemas .ColumnTypeString },
428449 {Name : "state" , Type : schemas .ColumnTypeString },
429- {Name : "created_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
430- {Name : "updated_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
450+ {Name : "created_at" , Type : schemas .ColumnTypeDatetime },
451+ {Name : "updated_at" , Type : schemas .ColumnTypeDatetime },
431452 {Name : "url" , Type : schemas .ColumnTypeString },
432453 {Name : "html_url" , Type : schemas .ColumnTypeString },
433454 {Name : "badge_url" , Type : schemas .ColumnTypeString },
@@ -466,7 +487,7 @@ func getAllTables() []schemas.Table {
466487 {Name : "name" , Type : schemas .ColumnTypeString },
467488 {Name : "head_branch" , Type : schemas .ColumnTypeString , Operators : []schemas.Operator {schemas .OperatorEquals }},
468489 {Name : "head_sha" , Type : schemas .ColumnTypeString },
469- {Name : "created_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
490+ {Name : "created_at" , Type : schemas .ColumnTypeDatetime },
470491 {Name : "updated_at" , Type : schemas .ColumnTypeDatetime },
471492 {Name : "run_started_at" , Type : schemas .ColumnTypeDatetime },
472493 {Name : "html_url" , Type : schemas .ColumnTypeString },
@@ -514,8 +535,8 @@ func getAllTables() []schemas.Table {
514535 {Name : "environment" , Type : schemas .ColumnTypeString },
515536 {Name : "description" , Type : schemas .ColumnTypeString },
516537 {Name : "creator" , Type : schemas .ColumnTypeString },
517- {Name : "created_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
518- {Name : "updated_at" , Type : schemas .ColumnTypeDatetime , Operators : timeRangeOperators },
538+ {Name : "created_at" , Type : schemas .ColumnTypeDatetime },
539+ {Name : "updated_at" , Type : schemas .ColumnTypeDatetime },
519540 {Name : "url" , Type : schemas .ColumnTypeString },
520541 {Name : "statuses_url" , Type : schemas .ColumnTypeString },
521542 },
@@ -536,6 +557,19 @@ func getAllTables() []schemas.Table {
536557 }
537558}
538559
560+ func timeFieldValuesForTable (tableName string ) []string {
561+ switch tableName {
562+ case normalizeTableNames (models .QueryTypeIssues ):
563+ return []string {"created" , "closed" , "updated" }
564+ case normalizeTableNames (models .QueryTypePullRequests ),
565+ normalizeTableNames (models .QueryTypePullRequestReviews ):
566+ return []string {"created" , "closed" , "merged" , "updated" }
567+ case normalizeTableNames (models .QueryTypeWorkflows ):
568+ return []string {"created" , "updated" }
569+ }
570+ return nil
571+ }
572+
539573func normalizeTableNames (table string ) string {
540574 return strings .ToLower (strings .ReplaceAll (table , "_" , "-" ))
541575}
0 commit comments