From 5e3343360355ce2bd75b2865887ad7a7a6d2c9b0 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 22 Apr 2026 16:20:04 +0300 Subject: [PATCH 1/2] use enum for query type --- .bra.toml | 22 + .changeset/README.md | 8 + .changeset/changelog.js | 32 + .changeset/config.json | 11 + .config/.cprc.json | 4 + .config/.eslintrc | 13 - .config/Dockerfile | 69 +- .config/README.md | 17 +- .config/bundler/externals.ts | 43 + .config/docker-compose-base.yaml | 31 + .config/entrypoint.sh | 18 + .config/eslint.config.mjs | 31 + .config/jest-setup.js | 9 +- .config/jest.config.js | 5 +- .config/jest/utils.js | 11 +- .config/supervisord/supervisord.conf | 47 + .config/tsconfig.json | 2 +- .config/types/bundler-rules.d.ts | 37 + .config/types/setupTests.d.ts | 1 + .config/types/webpack-plugins.d.ts | 83 + .config/webpack/BuildModeWebpackPlugin.ts | 33 + .config/webpack/utils.ts | 53 +- .config/webpack/webpack.config.ts | 393 +- .cprc.json | 7 + .eslintrc | 7 - .github/CODEOWNERS | 2 +- .github/workflows/add-to-project.yml | 17 +- .github/workflows/lint.yml | 15 - .github/workflows/publish.yaml | 38 + .github/workflows/push.yaml | 21 + .github/workflows/update-create-plugin.yml | 23 + .gitignore | 25 +- .golangci.toml | 20 - .nvmrc | 2 +- .yarn/releases/yarn-4.13.0.cjs | 940 + .yarnrc.yml | 3 + CHANGELOG.md | 232 +- README.md | 151 +- cspell.config.json | 37 +- cypress/integration/smoke.spec.ts | 57 - cypress/integration/utils.ts | 15 - .../smoke.spec.ts/panel-visualization (1).png | Bin 9320 -> 0 bytes .../smoke.spec.ts/panel-visualization.png | Bin 9320 -> 0 bytes cypress/tsconfig.json | 9 - docker-compose.yaml | 15 +- docs/Makefile | 8 + docs/developer-guide.md | 20 +- docs/docs.mk | 115 + docs/make-docs | 955 + docs/sources/_index.md | 92 + docs/sources/annotations/_index.md | 60 + docs/sources/query/_index.md | 792 + docs/sources/sample-dashboards/_index.md | 53 + docs/sources/setup/_index.md | 22 + docs/sources/setup/datasource.md | 46 + docs/sources/setup/installation.md | 100 + docs/sources/setup/provisioning.md | 43 + docs/sources/setup/token.md | 74 + docs/sources/troubleshoot/_index.md | 39 + docs/sources/variables-and-macros/_index.md | 22 + docs/sources/variables-and-macros/macros.md | 29 + .../sources/variables-and-macros/variables.md | 32 + docs/variables.mk | 1 + eslint.config.mjs | 31 + go.mod | 179 +- go.sum | 513 +- jest-setup.js | 30 + jest.config.js | 8 +- package.json | 152 +- pkg/dfutil/framer.go | 7 +- pkg/github/client/client.go | 230 +- pkg/github/client/errorsourcehandling.go | 108 + pkg/github/client/errorsourcehandling_test.go | 244 + pkg/github/codescanning.go | 188 + pkg/github/codescanning_handler.go | 25 + pkg/github/codescanning_test.go | 195 + pkg/github/commit_files.go | 144 + pkg/github/commit_files_handler.go | 40 + pkg/github/commit_files_test.go | 258 + pkg/github/commits.go | 27 + pkg/github/commits_test.go | 135 + pkg/github/datasource.go | 91 +- pkg/github/deployments.go | 123 + pkg/github/deployments_handler.go | 24 + pkg/github/deployments_test.go | 339 + pkg/github/docs.go | 2 +- pkg/github/issues.go | 58 +- pkg/github/issues_test.go | 54 +- pkg/github/macros.go | 2 +- pkg/github/milestones.go | 4 +- pkg/github/organizations.go | 24 +- pkg/github/organizations_handler.go | 24 + pkg/github/projects/project_items.go | 8 + pkg/github/projects/project_items_models.go | 2 +- pkg/github/pull_request_reviews.go | 244 + pkg/github/pull_request_reviews_handler.go | 24 + pkg/github/pull_request_reviews_test.go | 166 + pkg/github/pull_requests.go | 65 +- pkg/github/pull_requests_test.go | 30 +- pkg/github/query_handler.go | 47 +- pkg/github/repositories.go | 53 +- pkg/github/schema.go | 575 + pkg/github/sql.go | 395 + pkg/github/sql_handler_test.go | 995 + pkg/github/stargazers.go | 2 +- pkg/github/tags.go | 5 +- pkg/github/testdata/commit_files.golden.jsonc | 111 + pkg/github/testdata/commits.golden.jsonc | 29 +- .../testdata/commits_with_files.golden.jsonc | 199 + pkg/github/testdata/issues.golden.jsonc | 91 +- .../pull_request_reviews.golden.jsonc | 268 + .../testdata/pull_requests.golden.jsonc | 125 +- pkg/github/testdata/workflowRuns.golden.jsonc | 212 + .../testdata/workflowUsage.golden.jsonc | 26 +- pkg/github/vulnerabilities.go | 14 +- pkg/github/workflows.go | 123 +- pkg/github/workflows_handler.go | 16 + pkg/github/workflows_test.go | 75 +- pkg/main.go | 3 +- pkg/models/client.go | 9 +- pkg/models/codescanning.go | 27 + pkg/models/commit_files.go | 35 + pkg/models/commits.go | 14 +- pkg/models/deployments.go | 22 + pkg/models/issues.go | 4 +- pkg/models/packages.go | 42 +- pkg/models/packages_test.go | 83 + pkg/models/pull_requests.go | 4 +- pkg/models/query.go | 92 +- pkg/models/settings.go | 59 +- pkg/models/settings_test.go | 112 + pkg/models/vulnerabilities.go | 3 - pkg/models/workflows.go | 10 +- pkg/plugin/datasource.go | 9 +- pkg/plugin/datasource_caching.go | 79 +- pkg/plugin/datasource_caching_test.go | 133 + pkg/plugin/instance.go | 65 +- pkg/plugin/resource_handlers.go | 22 - pkg/testutil/client.go | 40 +- pkg/testutil/frames.go | 3 +- playwright.config.ts | 52 + renovate.json | 6 + src/DataSource.test.ts | 77 + src/DataSource.ts | 100 +- src/common/annotationsFromDataFrame.test.ts | 85 - src/common/annotationsFromDataFrame.ts | 136 - src/components/Divider.tsx | 20 - src/components/FieldSelect.tsx | 6 +- src/components/Filters.tsx | 4 +- src/components/Forms.tsx | 23 - src/components/LabelSelector.tsx | 28 - src/components/ResetButton.tsx | 17 - src/components/selectors.ts | 14 +- src/constants.ts | 66 + .../Github projects-1667481831135.json | 761 - src/module.ts | 15 +- src/plugin.json | 30 +- src/tracking.ts | 5 +- src/types.ts | 158 - src/types/config.ts | 19 + src/types/query.ts | 201 + src/validation.ts | 30 +- src/variables.test.ts | 10 +- src/variables.ts | 36 +- src/views/ConfigEditor.spec.tsx | 38 +- src/views/ConfigEditor.tsx | 225 +- src/views/QueryEditor.tsx | 211 +- src/views/QueryEditorCodeScanning.tsx | 37 + src/views/QueryEditorCommitFiles.tsx | 26 + src/views/QueryEditorCommits.tsx | 33 +- src/views/QueryEditorContributors.tsx | 20 +- src/views/QueryEditorDeployments.tsx | 77 + src/views/QueryEditorIssues.test.tsx | 46 + src/views/QueryEditorIssues.tsx | 39 +- src/views/QueryEditorLabels.tsx | 36 +- src/views/QueryEditorMilestones.tsx | 23 +- src/views/QueryEditorPackages.test.tsx | 24 + src/views/QueryEditorPackages.tsx | 85 +- src/views/QueryEditorProjects.tsx | 159 +- src/views/QueryEditorPullRequestFiles.tsx | 32 + src/views/QueryEditorPullRequestReviews.tsx | 72 + src/views/QueryEditorPullRequests.tsx | 41 +- src/views/QueryEditorReleases.tsx | 5 - src/views/QueryEditorRepository.test.tsx | 129 + src/views/QueryEditorRepository.tsx | 72 +- src/views/QueryEditorTags.tsx | 4 - src/views/QueryEditorVulnerabilities.tsx | 27 - src/views/QueryEditorWorkflowRuns.tsx | 45 + src/views/QueryEditorWorkflowUsage.tsx | 25 +- src/views/QueryEditorWorkflows.tsx | 32 +- src/views/VariableQueryEditor.tsx | 111 +- tests/ConfigEditor.spec.ts | 29 + tests/QueryEditor.spec.ts | 30 + tests/mocks/github-response.ts | 86 + tsconfig.json | 5 +- yarn.lock | 26335 ++++++++-------- 196 files changed, 27594 insertions(+), 15605 deletions(-) create mode 100644 .bra.toml create mode 100644 .changeset/README.md create mode 100644 .changeset/changelog.js create mode 100644 .changeset/config.json create mode 100644 .config/.cprc.json delete mode 100644 .config/.eslintrc create mode 100644 .config/bundler/externals.ts create mode 100644 .config/docker-compose-base.yaml create mode 100644 .config/entrypoint.sh create mode 100644 .config/eslint.config.mjs create mode 100644 .config/supervisord/supervisord.conf create mode 100644 .config/types/bundler-rules.d.ts create mode 100644 .config/types/setupTests.d.ts create mode 100644 .config/types/webpack-plugins.d.ts create mode 100644 .config/webpack/BuildModeWebpackPlugin.ts create mode 100644 .cprc.json delete mode 100644 .eslintrc delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/push.yaml create mode 100644 .github/workflows/update-create-plugin.yml delete mode 100644 .golangci.toml create mode 100755 .yarn/releases/yarn-4.13.0.cjs create mode 100644 .yarnrc.yml delete mode 100644 cypress/integration/smoke.spec.ts delete mode 100644 cypress/integration/utils.ts delete mode 100644 cypress/screenshots/expected/smoke.spec.ts/panel-visualization (1).png delete mode 100644 cypress/screenshots/expected/smoke.spec.ts/panel-visualization.png delete mode 100644 cypress/tsconfig.json create mode 100644 docs/Makefile create mode 100644 docs/docs.mk create mode 100755 docs/make-docs create mode 100644 docs/sources/_index.md create mode 100644 docs/sources/annotations/_index.md create mode 100644 docs/sources/query/_index.md create mode 100644 docs/sources/sample-dashboards/_index.md create mode 100644 docs/sources/setup/_index.md create mode 100644 docs/sources/setup/datasource.md create mode 100644 docs/sources/setup/installation.md create mode 100644 docs/sources/setup/provisioning.md create mode 100644 docs/sources/setup/token.md create mode 100644 docs/sources/troubleshoot/_index.md create mode 100644 docs/sources/variables-and-macros/_index.md create mode 100644 docs/sources/variables-and-macros/macros.md create mode 100644 docs/sources/variables-and-macros/variables.md create mode 100644 docs/variables.mk create mode 100644 eslint.config.mjs create mode 100644 pkg/github/client/errorsourcehandling.go create mode 100644 pkg/github/client/errorsourcehandling_test.go create mode 100644 pkg/github/codescanning.go create mode 100644 pkg/github/codescanning_handler.go create mode 100644 pkg/github/codescanning_test.go create mode 100644 pkg/github/commit_files.go create mode 100644 pkg/github/commit_files_handler.go create mode 100644 pkg/github/commit_files_test.go create mode 100644 pkg/github/deployments.go create mode 100644 pkg/github/deployments_handler.go create mode 100644 pkg/github/deployments_test.go create mode 100644 pkg/github/organizations_handler.go create mode 100644 pkg/github/pull_request_reviews.go create mode 100644 pkg/github/pull_request_reviews_handler.go create mode 100644 pkg/github/pull_request_reviews_test.go create mode 100644 pkg/github/schema.go create mode 100644 pkg/github/sql.go create mode 100644 pkg/github/sql_handler_test.go create mode 100644 pkg/github/testdata/commit_files.golden.jsonc create mode 100644 pkg/github/testdata/commits_with_files.golden.jsonc create mode 100644 pkg/github/testdata/pull_request_reviews.golden.jsonc create mode 100644 pkg/github/testdata/workflowRuns.golden.jsonc create mode 100644 pkg/models/codescanning.go create mode 100644 pkg/models/commit_files.go create mode 100644 pkg/models/deployments.go create mode 100644 pkg/models/packages_test.go create mode 100644 pkg/models/settings_test.go create mode 100644 pkg/plugin/datasource_caching_test.go delete mode 100644 pkg/plugin/resource_handlers.go create mode 100644 playwright.config.ts create mode 100644 renovate.json create mode 100644 src/DataSource.test.ts delete mode 100644 src/common/annotationsFromDataFrame.test.ts delete mode 100644 src/common/annotationsFromDataFrame.ts delete mode 100644 src/components/Divider.tsx delete mode 100644 src/components/Forms.tsx delete mode 100644 src/components/LabelSelector.tsx delete mode 100644 src/components/ResetButton.tsx create mode 100644 src/constants.ts delete mode 100644 src/dashboards/Github projects-1667481831135.json delete mode 100644 src/types.ts create mode 100644 src/types/config.ts create mode 100644 src/types/query.ts create mode 100644 src/views/QueryEditorCodeScanning.tsx create mode 100644 src/views/QueryEditorCommitFiles.tsx create mode 100644 src/views/QueryEditorDeployments.tsx create mode 100644 src/views/QueryEditorIssues.test.tsx create mode 100644 src/views/QueryEditorPackages.test.tsx create mode 100644 src/views/QueryEditorPullRequestFiles.tsx create mode 100644 src/views/QueryEditorPullRequestReviews.tsx delete mode 100644 src/views/QueryEditorReleases.tsx create mode 100644 src/views/QueryEditorRepository.test.tsx delete mode 100644 src/views/QueryEditorTags.tsx delete mode 100644 src/views/QueryEditorVulnerabilities.tsx create mode 100644 src/views/QueryEditorWorkflowRuns.tsx create mode 100644 tests/ConfigEditor.spec.ts create mode 100644 tests/QueryEditor.spec.ts create mode 100644 tests/mocks/github-response.ts diff --git a/.bra.toml b/.bra.toml new file mode 100644 index 00000000..89989fa0 --- /dev/null +++ b/.bra.toml @@ -0,0 +1,22 @@ +# default configuration created by the `mage watch` command. +# this file can be edited and should be checked into source control. +# see https://github.com/unknwon/bra/blob/master/templates/default.bra.toml for more configuration options. +[run] +init_cmds = [ + ["mage", "-v", "build:debug"], + ["mage", "-v" , "reloadPlugin"] +] +watch_all = true +follow_symlinks = false +ignore = [".git", "node_modules", "dist"] +ignore_files = ["mage_output_file.go"] +watch_dirs = [ + "pkg", + "src", +] +watch_exts = [".go", ".json"] +build_delay = 2000 +cmds = [ + ["mage", "-v", "build:debug"], + ["mage", "-v" , "reloadPlugin"] +] diff --git a/.changeset/README.md b/.changeset/README.md new file mode 100644 index 00000000..e5b6d8d6 --- /dev/null +++ b/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/changelog.js b/.changeset/changelog.js new file mode 100644 index 00000000..c4524b77 --- /dev/null +++ b/.changeset/changelog.js @@ -0,0 +1,32 @@ +const changelogFunctions = { + getReleaseLine: async (changeset, type, options) => { + let prefix = '🎉'; + if (type === 'major') { + prefix = '🎉'; + } else if (type === 'minor') { + prefix = '🚀'; + } else if (type === 'patch') { + prefix = '🐛'; + } + if (changeset && changeset.summary) { + const summary = changeset.summary || ''; + if (summary.indexOf('Docs') > -1) { + prefix = '📝'; + } + if ( + summary.indexOf('Chore') > -1 || + summary.indexOf('grafana-plugin-sdk-go') > -1 || + summary.indexOf('compiled') > -1 + ) { + prefix = '⚙️'; + } + return [prefix, summary].join(' '); + } + return [prefix, changeset?.summary].join(' '); + }, + getDependencyReleaseLine: async (changesets, dependenciesUpdated, options) => { + return '\n'; + }, +}; + +module.exports = changelogFunctions; diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 00000000..aa148f46 --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@3.0.5/schema.json", + "changelog": "./changelog.js", + "commit": false, + "fixed": [], + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/.config/.cprc.json b/.config/.cprc.json new file mode 100644 index 00000000..9b4c4577 --- /dev/null +++ b/.config/.cprc.json @@ -0,0 +1,4 @@ +{ + "version": "7.0.0", + "features": {} +} diff --git a/.config/.eslintrc b/.config/.eslintrc deleted file mode 100644 index 56950f21..00000000 --- a/.config/.eslintrc +++ /dev/null @@ -1,13 +0,0 @@ -/* - * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ - * - * In order to extend the configuration follow the steps in - * https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-eslint-config - */ -{ - "extends": ["@grafana/eslint-config"], - "root": true, - "rules": { - "react/prop-types": "off" - } -} diff --git a/.config/Dockerfile b/.config/Dockerfile index 35d89bd1..12fdef9d 100644 --- a/.config/Dockerfile +++ b/.config/Dockerfile @@ -1,16 +1,77 @@ -ARG grafana_version=latest +ARG grafana_version=latest@sha256:8b6530902b3609dac9f82cabbe5a9778e2ca6eda817c4572d5d5c202102fe76d ARG grafana_image=grafana-enterprise FROM grafana/${grafana_image}:${grafana_version} +ARG anonymous_auth_enabled=true +ARG development=false +ARG TARGETARCH + +ARG GO_VERSION=1.21.6 +ARG GO_ARCH=${TARGETARCH:-amd64} + +ENV DEV "${development}" + # Make it as simple as possible to access the grafana instance for development purposes # Do NOT enable these settings in a public facing / production grafana instance ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin" -ENV GF_AUTH_ANONYMOUS_ENABLED "true" +ENV GF_AUTH_ANONYMOUS_ENABLED "${anonymous_auth_enabled}" ENV GF_AUTH_BASIC_ENABLED "false" # Set development mode so plugins can be loaded without the need to sign ENV GF_DEFAULT_APP_MODE "development" -# Inject livereload script into grafana index.html + +LABEL maintainer="Grafana Labs " + +ENV GF_PATHS_HOME="/usr/share/grafana" +WORKDIR $GF_PATHS_HOME + USER root -RUN sed -i 's/<\/body><\/html>/|g' /usr/share/grafana/public/views/index.html + + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.config/README.md b/.config/README.md index 60bf4cdf..5ba31866 100644 --- a/.config/README.md +++ b/.config/README.md @@ -56,11 +56,11 @@ set up the Jest DOM for the testing library and to apply some polyfills. ([link #### ESM errors with Jest -A common issue found with the current jest config involves importing an npm package which only offers an ESM build. These packages cause jest to error with `SyntaxError: Cannot use import statement outside a module`. To work around this we provide a list of known packages to pass to the `[transformIgnorePatterns](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)` jest configuration property. If need be this can be extended in the following way: +A common issue with the current jest config involves importing an npm package that only offers an ESM build. These packages cause jest to error with `SyntaxError: Cannot use import statement outside a module`. To work around this, we provide a list of known packages to pass to the `[transformIgnorePatterns](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)` jest configuration property. If need be, this can be extended in the following way: ```javascript process.env.TZ = 'UTC'; -const { grafanaESModules, nodeModulesToTransform } = require('./jest/utils'); +const { grafanaESModules, nodeModulesToTransform } = require('./config/jest/utils'); module.exports = { // Jest configuration provided by Grafana @@ -106,9 +106,9 @@ We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge // webpack.config.ts import type { Configuration } from 'webpack'; import { merge } from 'webpack-merge'; -import grafanaConfig from './.config/webpack/webpack.config'; +import grafanaConfig, { type Env } from './.config/webpack/webpack.config'; -const config = async (env): Promise => { +const config = async (env: Env): Promise => { const baseConfig = await grafanaConfig(env); return merge(baseConfig, { @@ -142,7 +142,7 @@ We need to update the `scripts` in the `package.json` to use the extended Webpac ### Configure grafana image to use when running docker -By default `grafana-enterprise` will be used as the docker image for all docker related commands. If you want to override this behaviour simply alter the `docker-compose.yaml` by adding the following build arg `grafana_image`. +By default, `grafana-enterprise` will be used as the docker image for all docker related commands. If you want to override this behavior, simply alter the `docker-compose.yaml` by adding the following build arg `grafana_image`. **Example:** @@ -151,14 +151,15 @@ version: '3.7' services: grafana: - container_name: 'myorg-basic-app' + extends: + file: .config/docker-compose-base.yaml + service: grafana build: - context: ./.config args: grafana_version: ${GRAFANA_VERSION:-9.1.2} grafana_image: ${GRAFANA_IMAGE:-grafana} ``` -In this example we are assigning the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will give you the possibility to set the value while running the docker-compose commands which might be convinent in some scenarios. +In this example, we assign the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will allow you to set the value while running the docker compose commands, which might be convenient in some scenarios. --- diff --git a/.config/bundler/externals.ts b/.config/bundler/externals.ts new file mode 100644 index 00000000..3a287d58 --- /dev/null +++ b/.config/bundler/externals.ts @@ -0,0 +1,43 @@ +import type { Configuration, ExternalItemFunctionData } from 'webpack'; + +type ExternalsType = Configuration['externals']; + +export const externals: ExternalsType = [ + // Required for dynamic publicPath resolution + { 'amd-module': 'module' }, + 'lodash', + 'jquery', + 'moment', + 'slate', + 'emotion', + '@emotion/react', + '@emotion/css', + 'prismjs', + 'slate-plain-serializer', + '@grafana/slate-react', + 'react', + 'react-dom', + 'react-redux', + 'redux', + 'rxjs', + 'i18next', + 'react-router', + 'd3', + 'angular', + /^@grafana\/ui/i, + /^@grafana\/runtime/i, + /^@grafana\/data/i, + + // Mark legacy SDK imports as external if their name starts with the "grafana/" prefix + ({ request }: ExternalItemFunctionData, callback: (error?: Error, result?: string) => void) => { + const prefix = 'grafana/'; + const hasPrefix = (request: string) => request.indexOf(prefix) === 0; + const stripPrefix = (request: string) => request.slice(prefix.length); + + if (request && hasPrefix(request)) { + return callback(undefined, stripPrefix(request)); + } + + callback(); + }, +]; diff --git a/.config/docker-compose-base.yaml b/.config/docker-compose-base.yaml new file mode 100644 index 00000000..09740092 --- /dev/null +++ b/.config/docker-compose-base.yaml @@ -0,0 +1,31 @@ +services: + grafana: + user: root + container_name: 'grafana-github-datasource' + + build: + context: . + args: + grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise} + grafana_version: ${GRAFANA_VERSION:-12.2.0} + development: ${DEVELOPMENT:-false} + anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true} + ports: + - 3000:3000/tcp + - 2345:2345/tcp # delve + security_opt: + - 'apparmor:unconfined' + - 'seccomp:unconfined' + cap_add: + - SYS_PTRACE + volumes: + - ../dist:/var/lib/grafana/plugins/grafana-github-datasource + - ../provisioning:/etc/grafana/provisioning + - ..:/root/grafana-github-datasource + + environment: + NODE_ENV: development + GF_LOG_FILTERS: plugin.grafana-github-datasource:debug + GF_LOG_LEVEL: debug + GF_DATAPROXY_LOGGING: 1 + GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: grafana-github-datasource diff --git a/.config/entrypoint.sh b/.config/entrypoint.sh new file mode 100644 index 00000000..00c69f24 --- /dev/null +++ b/.config/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ "${DEV}" = "false" ]; then + echo "Starting test mode" + exec /run.sh +fi + +echo "Starting development mode" + +if grep -i -q alpine /etc/issue; then + exec /usr/bin/supervisord -c /etc/supervisord.conf +elif grep -i -q ubuntu /etc/issue; then + exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf +else + echo 'ERROR: Unsupported base image' + exit 1 +fi + diff --git a/.config/eslint.config.mjs b/.config/eslint.config.mjs new file mode 100644 index 00000000..968c0715 --- /dev/null +++ b/.config/eslint.config.mjs @@ -0,0 +1,31 @@ +import { defineConfig } from 'eslint/config'; +import grafanaConfig from '@grafana/eslint-config/flat.js'; + +export default defineConfig([ + ...grafanaConfig, + { + rules: { + 'react/prop-types': 'off', + }, + }, + { + files: ['src/**/*.{ts,tsx}'], + + languageOptions: { + parserOptions: { + project: './tsconfig.json', + }, + }, + + rules: { + '@typescript-eslint/no-deprecated': 'warn', + }, + }, + { + files: ['./tests/**/*'], + + rules: { + 'react-hooks/rules-of-hooks': 'off', + }, + }, +]); diff --git a/.config/jest-setup.js b/.config/jest-setup.js index 575b354f..7b1771ea 100644 --- a/.config/jest-setup.js +++ b/.config/jest-setup.js @@ -2,15 +2,18 @@ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ * * In order to extend the configuration follow the steps in - * https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-jest-config + * https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-jest-config */ import '@testing-library/jest-dom'; +import { TextEncoder, TextDecoder } from 'util'; + +Object.assign(global, { TextDecoder, TextEncoder }); // https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom Object.defineProperty(global, 'matchMedia', { writable: true, - value: jest.fn().mockImplementation((query) => ({ + value: (query) => ({ matches: false, media: query, onchange: null, @@ -19,7 +22,7 @@ Object.defineProperty(global, 'matchMedia', { addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(), - })), + }), }); HTMLCanvasElement.prototype.getContext = () => {}; diff --git a/.config/jest.config.js b/.config/jest.config.js index 027c0ffc..efe19384 100644 --- a/.config/jest.config.js +++ b/.config/jest.config.js @@ -2,7 +2,7 @@ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ * * In order to extend the configuration follow the steps in - * https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-jest-config + * https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-jest-config */ const path = require('path'); @@ -25,7 +25,7 @@ module.exports = { '^.+\\.(t|j)sx?$': [ '@swc/jest', { - sourceMaps: true, + sourceMaps: 'inline', jsc: { parser: { syntax: 'typescript', @@ -40,4 +40,5 @@ module.exports = { // Jest will throw `Cannot use import statement outside module` if it tries to load an // ES module without it being transformed first. ./config/README.md#esm-errors-with-jest transformIgnorePatterns: [nodeModulesToTransform(grafanaESModules)], + watchPathIgnorePatterns: ['/node_modules', '/dist'], }; diff --git a/.config/jest/utils.js b/.config/jest/utils.js index 9e9a4bf2..55d9cb6e 100644 --- a/.config/jest/utils.js +++ b/.config/jest/utils.js @@ -8,17 +8,26 @@ * This utility function is useful in combination with jest `transformIgnorePatterns` config * to transform specific packages (e.g.ES modules) in a projects node_modules folder. */ -const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!(${moduleNames.join('|')})\/)`; +const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!.*(${moduleNames.join('|')})\/.*)`; // Array of known nested grafana package dependencies that only bundle an ESM version const grafanaESModules = [ + '.pnpm', // Support using pnpm symlinked packages + '@grafana/schema', + '@wojtekmaj/date-utils', 'd3', 'd3-color', 'd3-force', 'd3-interpolate', 'd3-scale-chromatic', + 'get-user-locale', + 'marked', + 'memoize', + 'mimic-function', 'ol', + 'react-calendar', 'react-colorful', + 'rxjs', 'uuid', ]; diff --git a/.config/supervisord/supervisord.conf b/.config/supervisord/supervisord.conf new file mode 100644 index 00000000..2089136b --- /dev/null +++ b/.config/supervisord/supervisord.conf @@ -0,0 +1,47 @@ +[supervisord] +nodaemon=true +user=root + +[program:grafana] +user=root +directory=/var/lib/grafana +command=bash -c 'while [ ! -f /root/grafana-github-datasource/dist/gpx_github* ]; do sleep 1; done; /run.sh' +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +redirect_stderr=true +killasgroup=true +stopasgroup=true +autostart=true + +[program:delve] +user=root +command=/bin/bash -c 'pid=""; while [ -z "$pid" ]; do pid=$(pgrep -f gpx_github); done; /root/go/bin/dlv attach --api-version=2 --headless --continue --accept-multiclient --listen=:2345 $pid' +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +redirect_stderr=true +killasgroup=false +stopasgroup=false +autostart=true +autorestart=true + +[program:build-watcher] +user=root +command=/bin/bash -c 'while inotifywait -e modify,create,delete -r /var/lib/grafana/plugins/grafana-github-datasource; do echo "Change detected, restarting delve...";supervisorctl restart delve; done' +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +redirect_stderr=true +killasgroup=true +stopasgroup=true +autostart=true + +[program:mage-watcher] +user=root +environment=PATH="/usr/local/go/bin:/root/go/bin:%(ENV_PATH)s" +directory=/root/grafana-github-datasource +command=/bin/bash -c 'git config --global --add safe.directory /root/grafana-github-datasource && mage -v watch' +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +redirect_stderr=true +killasgroup=true +stopasgroup=true +autostart=true diff --git a/.config/tsconfig.json b/.config/tsconfig.json index 8acd86b6..c0fc6d47 100644 --- a/.config/tsconfig.json +++ b/.config/tsconfig.json @@ -2,7 +2,7 @@ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ * * In order to extend the configuration follow the steps in - * https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-typescript-config + * https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-typescript-config */ { "compilerOptions": { diff --git a/.config/types/bundler-rules.d.ts b/.config/types/bundler-rules.d.ts new file mode 100644 index 00000000..e67197c5 --- /dev/null +++ b/.config/types/bundler-rules.d.ts @@ -0,0 +1,37 @@ +// Image declarations +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + const src: string; + export default src; +} + +// Font declarations +declare module '*.woff'; +declare module '*.woff2'; +declare module '*.eot'; +declare module '*.ttf'; +declare module '*.otf'; diff --git a/.config/types/setupTests.d.ts b/.config/types/setupTests.d.ts new file mode 100644 index 00000000..7b0828bf --- /dev/null +++ b/.config/types/setupTests.d.ts @@ -0,0 +1 @@ +import '@testing-library/jest-dom'; diff --git a/.config/types/webpack-plugins.d.ts b/.config/types/webpack-plugins.d.ts new file mode 100644 index 00000000..6dbab109 --- /dev/null +++ b/.config/types/webpack-plugins.d.ts @@ -0,0 +1,83 @@ +declare module 'replace-in-file-webpack-plugin' { + import { Compiler, Plugin } from 'webpack'; + + interface ReplaceRule { + search: string | RegExp; + replace: string | ((match: string) => string); + } + + interface ReplaceOption { + dir?: string; + files?: string[]; + test?: RegExp | RegExp[]; + rules: ReplaceRule[]; + } + + class ReplaceInFilePlugin extends Plugin { + constructor(options?: ReplaceOption[]); + options: ReplaceOption[]; + apply(compiler: Compiler): void; + } + + export = ReplaceInFilePlugin; +} + +declare module 'webpack-livereload-plugin' { + import { ServerOptions } from 'https'; + import { Compiler, Plugin, Stats, Compilation } from 'webpack'; + + interface Options extends Pick { + /** + * protocol for livereload `