MCPcopy Create free account
hub / github.com/rilldata/rill / yamlForCommittedReport

Method yamlForCommittedReport

admin/server/reports.go:595–648  ·  view source on GitHub ↗
(opts *adminv1.ReportOptions)

Source from the content-addressed store, hash-verified

593}
594
595func (s *Server) yamlForCommittedReport(opts *adminv1.ReportOptions) ([]byte, error) {
596 // Format args as pretty YAML
597 var args map[string]interface{}
598 if opts.QueryArgsJson != "" { // nolint:staticcheck // backwards compatibility
599 err := json.Unmarshal([]byte(opts.QueryArgsJson), &args) // nolint:staticcheck // backwards compatibility
600 if err != nil {
601 return nil, fmt.Errorf("failed to parse queryArgsJSON: %w", err)
602 }
603 }
604
605 // Format export format as pretty string
606 var exportFormat string
607 switch opts.ExportFormat {
608 case runtimev1.ExportFormat_EXPORT_FORMAT_CSV:
609 exportFormat = "csv"
610 case runtimev1.ExportFormat_EXPORT_FORMAT_PARQUET:
611 exportFormat = "parquet"
612 case runtimev1.ExportFormat_EXPORT_FORMAT_XLSX:
613 exportFormat = "xlsx"
614 default:
615 exportFormat = opts.ExportFormat.String()
616 }
617
618 res := reportYAML{}
619 res.Type = "report"
620 res.DisplayName = opts.DisplayName
621 res.Refresh.Cron = opts.RefreshCron
622 res.Refresh.TimeZone = opts.RefreshTimeZone
623 res.Watermark = "inherit"
624 res.Intervals.Duration = opts.IntervalDuration
625 if opts.Resolver != "" {
626 res.Data = map[string]any{
627 opts.Resolver: opts.ResolverProperties,
628 }
629 }
630 res.Query.Name = opts.QueryName // nolint:staticcheck // backwards compatibility
631 res.Query.Args = args
632 res.Export.Format = exportFormat
633 res.Export.IncludeHeader = opts.ExportIncludeHeader
634 res.Export.Limit = uint(opts.ExportLimit)
635 res.Notify.Email.Recipients = opts.EmailRecipients
636 res.Notify.Slack.Channels = opts.SlackChannels
637 res.Notify.Slack.Users = opts.SlackUsers
638 res.Notify.Slack.Webhooks = opts.SlackWebhooks
639 res.Annotations.WebOpenPath = opts.WebOpenPath
640 res.Annotations.WebOpenMode = WebOpenMode(opts.WebOpenMode)
641 if res.Annotations.WebOpenMode == "" {
642 res.Annotations.WebOpenMode = WebOpenModeRecipient // Backwards compatibility
643 }
644 if !res.Annotations.WebOpenMode.Valid() {
645 return nil, fmt.Errorf("invalid web open mode %q", opts.WebOpenMode)
646 }
647 return yaml.Marshal(res)
648}
649
650// generateReportName generates a random report name with the display name as a seed.
651// Example: "My report!" -> "my-report-5b3f7e1a".

Callers 1

GenerateReportYAMLMethod · 0.95

Calls 4

WebOpenModeTypeAlias · 0.85
ErrorfMethod · 0.65
StringMethod · 0.65
ValidMethod · 0.45

Tested by

no test coverage detected